@@ -25,11 +25,7 @@ def create_ipv4(rule, message_type=ANNOUNCE):
25
25
26
26
flagstring = rule .flags .replace (";" , " " ) if rule .flags else ""
27
27
28
- flags = (
29
- "tcp-flags {};" .format (flagstring )
30
- if rule .flags and rule .protocol == "tcp"
31
- else ""
32
- )
28
+ flags = "tcp-flags {};" .format (flagstring ) if rule .flags and rule .protocol == "tcp" else ""
33
29
34
30
fragment_string = rule .fragment .replace (";" , " " ) if rule .fragment else ""
35
31
fragment = "fragment [ {} ];" .format (fragment_string ) if rule .fragment else ""
@@ -55,11 +51,7 @@ def create_ipv6(rule, message_type=ANNOUNCE):
55
51
if rule .next_header and rule .next_header != "all" :
56
52
protocol = "next-header ={};" .format (IPV6_NEXT_HEADER [rule .next_header ])
57
53
flagstring = rule .flags .replace (";" , " " )
58
- flags = (
59
- "tcp-flags {};" .format (flagstring )
60
- if rule .flags and rule .next_header == "tcp"
61
- else ""
62
- )
54
+ flags = "tcp-flags {};" .format (flagstring ) if rule .flags and rule .next_header == "tcp" else ""
63
55
64
56
spec = {"protocol" : protocol , "mask" : IPV6_DEFMASK , "flags" : flags }
65
57
@@ -103,25 +95,17 @@ def create_rtbh(rule, message_type=ANNOUNCE):
103
95
targets = current_app .config ["MULTI_NEIGHBOR" ].get (rule .community .comm )
104
96
else :
105
97
targets = current_app .config ["MULTI_NEIGHBOR" ].get ("primary" )
106
-
98
+
107
99
neighbor = prepare_multi_neighbor (targets )
108
100
else :
109
101
neighbor = ""
110
102
except KeyError :
111
103
neighbor = ""
112
104
113
- community_string = (
114
- "community [{}]" .format (rule .community .comm ) if rule .community .comm else ""
115
- )
116
- large_community_string = (
117
- "large-community [{}]" .format (rule .community .larcomm )
118
- if rule .community .larcomm
119
- else ""
120
- )
105
+ community_string = "community [{}]" .format (rule .community .comm ) if rule .community .comm else ""
106
+ large_community_string = "large-community [{}]" .format (rule .community .larcomm ) if rule .community .larcomm else ""
121
107
extended_community_string = (
122
- "extended-community [{}]" .format (rule .community .extcomm )
123
- if rule .community .extcomm
124
- else ""
108
+ "extended-community [{}]" .format (rule .community .extcomm ) if rule .community .extcomm else ""
125
109
)
126
110
127
111
as_path_string = ""
@@ -165,49 +149,29 @@ def create_message(rule, ipv_specific, message_type=ANNOUNCE):
165
149
source = "source {}" .format (rule .source ) if rule .source else ""
166
150
source += "/{};" .format (smask ) if rule .source else ""
167
151
168
- source_port = (
169
- "source-port {};" .format (trps (rule .source_port )) if rule .source_port else ""
170
- )
152
+ source_port = "source-port {};" .format (trps (rule .source_port )) if rule .source_port else ""
171
153
172
154
dmask = sanitize_mask (rule .dest_mask , ipv_specific ["mask" ])
173
155
dest = " destination {}" .format (rule .dest ) if rule .dest else ""
174
156
dest += "/{};" .format (dmask ) if rule .dest else ""
175
157
176
- dest_port = (
177
- "destination-port {};" .format (trps (rule .dest_port )) if rule .dest_port else ""
178
- )
158
+ dest_port = "destination-port {};" .format (trps (rule .dest_port )) if rule .dest_port else ""
179
159
180
- protocol = ipv_specific [ "protocol" ]
181
- flags = ipv_specific [ "flags" ]
182
- fragment = ipv_specific .get ("fragment" , None )
160
+ protocol = ipv_specific . get ( "protocol" , "" )
161
+ flags = ipv_specific . get ( "flags" , "" )
162
+ fragment = ipv_specific .get ("fragment" , "" )
183
163
184
- packet_len = (
185
- "packet-length {};" .format (trps (rule .packet_len , MAX_PACKET ))
186
- if rule .packet_len
187
- else ""
188
- )
164
+ packet_len = "packet-length {};" .format (trps (rule .packet_len , MAX_PACKET )) if rule .packet_len else ""
189
165
190
- match_body = "{source} {source_port} {dest} {dest_port} {protocol} {fragment} {flags} {packet_len}" .format (
191
- source = source ,
192
- source_port = source_port ,
193
- dest = dest ,
194
- dest_port = dest_port ,
195
- protocol = protocol ,
196
- fragment = fragment ,
197
- flags = flags ,
198
- packet_len = packet_len ,
199
- )
166
+ values = [source , source_port , dest , dest_port , protocol , fragment , flags , packet_len ]
167
+ match_body = " " .join (v for v in values if v )
200
168
201
169
command = "{};" .format (rule .action .command )
202
170
203
171
try :
204
172
if current_app .config ["USE_RD" ]:
205
- rd_string = "route-distinguisher {rd};" .format (
206
- rd = current_app .config ["RD_STRING" ]
207
- )
208
- rt_string = "extended-community target:{rt};" .format (
209
- rt = current_app .config ["RT_STRING" ]
210
- )
173
+ rd_string = "route-distinguisher {rd};" .format (rd = current_app .config ["RD_STRING" ])
174
+ rt_string = "extended-community target:{rt};" .format (rt = current_app .config ["RT_STRING" ])
211
175
else :
212
176
rd_string = ""
213
177
rt_string = ""
0 commit comments