Allow passing args of type list for NSGroup and firewall rule methods
The current NSGroup create method does not allow for passing a list of membership criterias. Similarly the source, destination and service arguments of Firewall rule method does not allow for passing a list. This patch provides a fix for it and updates all occurences of get_rule_dict with appropriate values. This patch also adds a new arg to get_rule_dict to allow creation of firewall rules with the disabled=True or False. The default value of this arg is False, which means rules are enabled. Change-Id: I6b16d37bf3ca61f3c9f02688f9548ea4b3b6adb6
This commit is contained in:
parent
05fdc812d5
commit
0294780a4d
|
@ -118,7 +118,13 @@ class NsxLibNsGroup(utils.NsxLibApiBase):
|
|||
'tags': tags,
|
||||
'members': []}
|
||||
if membership_criteria:
|
||||
body.update({'membership_criteria': [membership_criteria]})
|
||||
# Allow caller to pass a list of membership criterias.
|
||||
# The 'else' block is maintained for backwards compatibility
|
||||
# where in a caller might only send a single membership criteria.
|
||||
if isinstance(membership_criteria, list):
|
||||
body.update({'membership_criteria': membership_criteria})
|
||||
else:
|
||||
body.update({'membership_criteria': [membership_criteria]})
|
||||
return self.client.create('ns-groups', body)
|
||||
|
||||
def list(self):
|
||||
|
@ -361,18 +367,20 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
|
|||
return {'target_id': ip_cidr_block,
|
||||
'target_type': target_type}
|
||||
|
||||
def get_rule_dict(self, display_name, source=None, destination=None,
|
||||
def get_rule_dict(self, display_name, sources=None, destinations=None,
|
||||
direction=consts.IN_OUT, ip_protocol=consts.IPV4_IPV6,
|
||||
service=None, action=consts.FW_ACTION_ALLOW,
|
||||
logged=False):
|
||||
return {'display_name': display_name,
|
||||
'sources': [source] if source else [],
|
||||
'destinations': [destination] if destination else [],
|
||||
'direction': direction,
|
||||
'ip_protocol': ip_protocol,
|
||||
'services': [service] if service else [],
|
||||
'action': action,
|
||||
'logged': logged}
|
||||
services=None, action=consts.FW_ACTION_ALLOW,
|
||||
logged=False, disabled=False):
|
||||
rule_dict = {'display_name': display_name,
|
||||
'direction': direction,
|
||||
'ip_protocol': ip_protocol,
|
||||
'action': action,
|
||||
'logged': logged,
|
||||
'disabled': disabled,
|
||||
'sources': sources or [],
|
||||
'destinations': destinations or [],
|
||||
'services': services or []}
|
||||
return rule_dict
|
||||
|
||||
def add_rule(self, rule, section_id):
|
||||
resource = 'firewall/sections/%s/rules' % section_id
|
||||
|
@ -421,9 +429,9 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
|
|||
service = self._decide_service(sg_rule)
|
||||
name = sg_rule['id']
|
||||
|
||||
return self.get_rule_dict(name, source,
|
||||
destination, direction,
|
||||
ip_protocol, service,
|
||||
return self.get_rule_dict(name, [source],
|
||||
[destination], direction,
|
||||
ip_protocol, [service],
|
||||
action, logged)
|
||||
|
||||
def create_rules(self, context, section_id, nsgroup_id,
|
||||
|
@ -479,7 +487,7 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
|
|||
destination_ports=[68])
|
||||
dhcp_client_rule_in = self.get_rule_dict(
|
||||
'DHCP Reply', direction=consts.IN,
|
||||
service=dhcp_client)
|
||||
services=[dhcp_client])
|
||||
|
||||
dhcp_server = (
|
||||
self.get_nsservice(
|
||||
|
@ -489,7 +497,7 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
|
|||
destination_ports=[67]))
|
||||
dhcp_client_rule_out = self.get_rule_dict(
|
||||
'DHCP Request', direction=consts.OUT,
|
||||
service=dhcp_server)
|
||||
services=[dhcp_server])
|
||||
|
||||
self.update(section['id'],
|
||||
name, section['description'],
|
||||
|
|
Loading…
Reference in New Issue