Skip to content

Commit b425a2e

Browse files
committedAug 11, 2021
cs_firewall: add dest cidrs
1 parent e6e11e4 commit b425a2e

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed
 

‎plugins/modules/cs_firewall.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@
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.
@@ -178,6 +184,11 @@
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' ]
181192
protocol:
182193
description: Protocol of the rule.
183194
returned: success
@@ -224,6 +235,7 @@ def __init__(self, module):
224235
super(AnsibleCloudStackFirewall, self).__init__(module)
225236
self.returns = {
226237
'cidrlist': 'cidr',
238+
'destcidrlist': 'dest_cidrs',
227239
'startport': 'start_port',
228240
'endport': 'end_port',
229241
'protocol': 'protocol',
@@ -237,6 +249,7 @@ def __init__(self, module):
237249
def get_firewall_rule(self):
238250
if not self.firewall_rule:
239251
cidrs = self.module.params.get('cidrs')
252+
dest_cidrs = self.module.params.get('destcidrs')
240253
protocol = self.module.params.get('protocol')
241254
start_port = self.module.params.get('start_port')
242255
end_port = self.get_or_fallback('end_port', 'start_port')
@@ -280,7 +293,7 @@ def get_firewall_rule(self):
280293

281294
if firewall_rules:
282295
for rule in firewall_rules:
283-
type_match = self._type_cidrs_match(rule, cidrs, egress_cidrs)
296+
type_match = self._type_cidrs_match(rule, cidrs, egress_cidrs) and self._type_dest_cidrs_match(rule, dest_cidrs)
284297

285298
protocol_match = (
286299
self._tcp_udp_match(rule, protocol, start_port, end_port) or
@@ -322,13 +335,18 @@ def _type_cidrs_match(self, rule, cidrs, egress_cidrs):
322335
else:
323336
return ",".join(cidrs) == rule['cidrlist']
324337

338+
def _type_dest_cidrs_match(self, rule, dest_cidrs):
339+
if dest_cidrs is not None and 'destcidrlist' in rule:
340+
return ",".join(dest_cidrs) == rule['destcidrlist']
341+
325342
def create_firewall_rule(self):
326343
firewall_rule = self.get_firewall_rule()
327344
if not firewall_rule:
328345
self.result['changed'] = True
329346

330347
args = {
331348
'cidrlist': self.module.params.get('cidrs'),
349+
'destcidrlist': self.module.params.get('dest_cidrs'),
332350
'protocol': self.module.params.get('protocol'),
333351
'startport': self.module.params.get('start_port'),
334352
'endport': self.get_or_fallback('end_port', 'start_port'),
@@ -393,6 +411,7 @@ def main():
393411
ip_address=dict(),
394412
network=dict(),
395413
cidrs=dict(type='list', elements='str', default='0.0.0.0/0', aliases=['cidr']),
414+
dest_cidrs=dict(type='list', elements='str', aliases=['dest_cidr']),
396415
protocol=dict(choices=['tcp', 'udp', 'icmp', 'all'], default='tcp'),
397416
type=dict(choices=['ingress', 'egress'], default='ingress'),
398417
icmp_type=dict(type='int'),

0 commit comments

Comments
 (0)
Failed to load comments.