From 82ce3daf8cd43cb6a892414badb7b97ba3f873d7 Mon Sep 17 00:00:00 2001 From: Abhishek Raut Date: Thu, 9 Nov 2017 18:10:06 -0800 Subject: [PATCH] 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 --- vmware_nsxlib/v3/security.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vmware_nsxlib/v3/security.py b/vmware_nsxlib/v3/security.py index f69c7157..127668cf 100644 --- a/vmware_nsxlib/v3/security.py +++ b/vmware_nsxlib/v3/security.py @@ -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()