From 734270d9e9fc10f31a5eb65da2aab1cce90f27f4 Mon Sep 17 00:00:00 2001 From: Qian Sun Date: Thu, 17 May 2018 01:38:25 -0700 Subject: [PATCH] Enabled naming nat rules The following methods now have the ability to name nat rules: - add_fip_nat_rules - add_gw_snat_rule - add_nat_rule Change-Id: I62b36fcec1a53b6d2c0c0b64c9dcb4200c9b0ae9 --- vmware_nsxlib/tests/unit/v3/test_resources.py | 5 ++++- vmware_nsxlib/v3/core_resources.py | 5 ++++- vmware_nsxlib/v3/router.py | 13 ++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/test_resources.py b/vmware_nsxlib/tests/unit/v3/test_resources.py index 586a575e..7b6b8d5d 100644 --- a/vmware_nsxlib/tests/unit/v3/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/test_resources.py @@ -715,9 +715,11 @@ class LogicalRouterTestCase(BaseTestResource): router = self.get_mocked_resource() translated_net = '1.1.1.1' priority = 10 + display_name = 'fake_name' data = { 'action': action, + 'display_name': display_name, 'enabled': True, 'translated_network': translated_net, 'rule_priority': priority @@ -734,7 +736,8 @@ class LogicalRouterTestCase(BaseTestResource): action=action, translated_network=translated_net, rule_priority=priority, - bypass_firewall=False) + bypass_firewall=False, + display_name=display_name) except exceptions.InvalidInput as e: if expect_failure: return diff --git a/vmware_nsxlib/v3/core_resources.py b/vmware_nsxlib/v3/core_resources.py index f81d80e6..af96f1c4 100644 --- a/vmware_nsxlib/v3/core_resources.py +++ b/vmware_nsxlib/v3/core_resources.py @@ -532,7 +532,8 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase): match_ports=None, match_protocol=None, match_resource_type=None, bypass_firewall=True, - tags=None): + tags=None, + display_name=None): self._validate_nat_rule_action(action) resource = 'logical-routers/%s/nat/rules' % logical_router_id body = {'action': action, @@ -561,6 +562,8 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase): "this feature is not supported.", logical_router_id) if tags is not None: body['tags'] = tags + if display_name: + body['display_name'] = display_name return self.client.create(resource, body) def add_static_route(self, logical_router_id, dest_cidr, nexthop): diff --git a/vmware_nsxlib/v3/router.py b/vmware_nsxlib/v3/router.py index 1233c7b9..0d96f7e0 100644 --- a/vmware_nsxlib/v3/router.py +++ b/vmware_nsxlib/v3/router.py @@ -153,14 +153,15 @@ class RouterLib(object): skip_not_found=True, strict_mode=False) def add_gw_snat_rule(self, logical_router_id, gw_ip, source_net=None, - bypass_firewall=True, tags=None): + bypass_firewall=True, tags=None, display_name=None): return self.nsxlib.logical_router.add_nat_rule( logical_router_id, action="SNAT", translated_network=gw_ip, source_net=source_net, rule_priority=GW_NAT_PRI, bypass_firewall=bypass_firewall, - tags=tags) + tags=tags, + display_name=display_name) def update_router_edge_cluster(self, nsx_router_id, edge_cluster_uuid): return self._router_client.update(nsx_router_id, @@ -200,14 +201,15 @@ class RouterLib(object): def add_fip_nat_rules(self, logical_router_id, ext_ip, int_ip, match_ports=None, bypass_firewall=True, - tags=None): + tags=None, display_name=None): self.nsxlib.logical_router.add_nat_rule( logical_router_id, action="SNAT", translated_network=ext_ip, source_net=int_ip, rule_priority=FIP_NAT_PRI, bypass_firewall=bypass_firewall, - tags=tags) + tags=tags, + display_name=display_name) self.nsxlib.logical_router.add_nat_rule( logical_router_id, action="DNAT", translated_network=int_ip, @@ -215,7 +217,8 @@ class RouterLib(object): rule_priority=FIP_NAT_PRI, match_ports=match_ports, bypass_firewall=bypass_firewall, - tags=tags) + tags=tags, + display_name=display_name) def delete_fip_nat_rules_by_internal_ip(self, logical_router_id, int_ip): self.nsxlib.logical_router.delete_nat_rule_by_values(