4949 cidrs:
5050 description:
5151 - List of CIDRs (full notation) to be used for firewall rule.
52- - Since version 2.5, it is a list of CIDR.
5352 elements: str
5453 type: list
5554 default: 0.0.0.0/0
5655 aliases: [ cidr ]
56+ dest_cidrs:
57+ description:
58+ - List of destination CIDRs (full notation) to forward traffic to if I(type=egress).
59+ elements: str
60+ type: list
61+ aliases: [ dest_cidr ]
62+ version_added: 2.2.0
5763 start_port:
5864 description:
5965 - Start port for this rule.
178184 returned: success
179185 type: list
180186 sample: [ '0.0.0.0/0' ]
187+ dest_cidrs:
188+ description: CIDR list of the rule to forward traffic to.
189+ returned: success
190+ type: list
191+ sample: [ '0.0.0.0/0' ]
192+ version_added: 2.2.0
181193protocol:
182194 description: Protocol of the rule.
183195 returned: success
@@ -224,6 +236,7 @@ def __init__(self, module):
224236 super (AnsibleCloudStackFirewall , self ).__init__ (module )
225237 self .returns = {
226238 'cidrlist' : 'cidr' ,
239+ 'destcidrlist' : 'dest_cidrs' ,
227240 'startport' : 'start_port' ,
228241 'endport' : 'end_port' ,
229242 'protocol' : 'protocol' ,
@@ -237,6 +250,7 @@ def __init__(self, module):
237250 def get_firewall_rule (self ):
238251 if not self .firewall_rule :
239252 cidrs = self .module .params .get ('cidrs' )
253+ dest_cidrs = self .module .params .get ('destcidrs' )
240254 protocol = self .module .params .get ('protocol' )
241255 start_port = self .module .params .get ('start_port' )
242256 end_port = self .get_or_fallback ('end_port' , 'start_port' )
@@ -280,7 +294,7 @@ def get_firewall_rule(self):
280294
281295 if firewall_rules :
282296 for rule in firewall_rules :
283- type_match = self ._type_cidrs_match (rule , cidrs , egress_cidrs )
297+ type_match = self ._type_cidrs_match (rule , cidrs , egress_cidrs ) and self . _type_dest_cidrs_match ( rule , dest_cidrs )
284298
285299 protocol_match = (
286300 self ._tcp_udp_match (rule , protocol , start_port , end_port ) or
@@ -322,13 +336,18 @@ def _type_cidrs_match(self, rule, cidrs, egress_cidrs):
322336 else :
323337 return "," .join (cidrs ) == rule ['cidrlist' ]
324338
339+ def _type_dest_cidrs_match (self , rule , dest_cidrs ):
340+ if dest_cidrs is not None and 'destcidrlist' in rule :
341+ return "," .join (dest_cidrs ) == rule ['destcidrlist' ]
342+
325343 def create_firewall_rule (self ):
326344 firewall_rule = self .get_firewall_rule ()
327345 if not firewall_rule :
328346 self .result ['changed' ] = True
329347
330348 args = {
331349 'cidrlist' : self .module .params .get ('cidrs' ),
350+ 'destcidrlist' : self .module .params .get ('dest_cidrs' ),
332351 'protocol' : self .module .params .get ('protocol' ),
333352 'startport' : self .module .params .get ('start_port' ),
334353 'endport' : self .get_or_fallback ('end_port' , 'start_port' ),
@@ -393,6 +412,7 @@ def main():
393412 ip_address = dict (),
394413 network = dict (),
395414 cidrs = dict (type = 'list' , elements = 'str' , default = '0.0.0.0/0' , aliases = ['cidr' ]),
415+ dest_cidrs = dict (type = 'list' , elements = 'str' , aliases = ['dest_cidr' ]),
396416 protocol = dict (choices = ['tcp' , 'udp' , 'icmp' , 'all' ], default = 'tcp' ),
397417 type = dict (choices = ['ingress' , 'egress' ], default = 'ingress' ),
398418 icmp_type = dict (type = 'int' ),
0 commit comments