Allow add_rule(s) method to accept 'operation' as an arg

NSX allows DFW rules to be added to a DFW section with query
param 'operation', which can be used to create the said rule
at top or bottom within the DFW section. This patch
adds 'operation' as an argument for the methods 'add_rule'
and 'add_rules'.

Change-Id: I82dd206967543b3382dd20d7bffb140fce9cb59d
This commit is contained in:
Abhishek Raut 2017-11-09 18:10:06 -08:00
parent 6f04d52536
commit 82ce3daf8c

View File

@ -469,23 +469,23 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
rule_dict['applied_tos'] = applied_tos
return rule_dict
def add_rule(self, rule, section_id):
def add_rule(self, rule, section_id, operation=consts.FW_INSERT_BOTTOM):
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self.nsxlib_config.max_attempts)
def _add_rule():
resource = 'firewall/sections/%s/rules' % section_id
params = '?operation=insert_bottom'
params = '?operation=%s' % operation
return self.client.create(resource + params, rule)
return _add_rule()
def add_rules(self, rules, section_id):
def add_rules(self, rules, section_id, operation=consts.FW_INSERT_BOTTOM):
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self.nsxlib_config.max_attempts)
def _add_rules():
resource = 'firewall/sections/%s/rules' % section_id
params = '?action=create_multiple&operation=insert_bottom'
params = '?action=create_multiple&operation=%s' % operation
return self.client.create(resource + params, {'rules': rules})
return _add_rules()