From 4447dcaed9f476bfd06dfbfaab24d0195b3dd105 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 7 Mar 2018 01:38:04 -0800 Subject: [PATCH] Enabled adding tags to nat rules The following methods now have the ability to add tags: - add_fip_nat_rules - add_gw_snat_rule - add_nat_rule Change-Id: I6dc34ab3749ff4a5f1a575f407d8474538c69f96 --- vmware_nsxlib/v3/core_resources.py | 6 ++++-- vmware_nsxlib/v3/router.py | 14 +++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/vmware_nsxlib/v3/core_resources.py b/vmware_nsxlib/v3/core_resources.py index f00085a2..e58692c5 100644 --- a/vmware_nsxlib/v3/core_resources.py +++ b/vmware_nsxlib/v3/core_resources.py @@ -517,7 +517,8 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase): enabled=True, rule_priority=None, match_ports=None, match_protocol=None, match_resource_type=None, - bypass_firewall=True): + bypass_firewall=True, + tags=None): resource = 'logical-routers/%s/nat/rules' % logical_router_id body = {'action': action, 'enabled': enabled, @@ -543,7 +544,8 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase): elif not bypass_firewall: LOG.error("Ignoring bypass_firewall for router %s nat rule: " "this feature is not supported.", logical_router_id) - + if tags is not None: + body['tags'] = tags 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 74e6ac4d..c68b0fd9 100644 --- a/vmware_nsxlib/v3/router.py +++ b/vmware_nsxlib/v3/router.py @@ -153,13 +153,14 @@ 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): + bypass_firewall=True, tags=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) + bypass_firewall=bypass_firewall, + tags=tags) def update_router_edge_cluster(self, nsx_router_id, edge_cluster_uuid): return self._router_client.update(nsx_router_id, @@ -194,20 +195,23 @@ class RouterLib(object): relay_service_uuid=relay_service_uuid) def add_fip_nat_rules(self, logical_router_id, ext_ip, int_ip, - match_ports=None, bypass_firewall=True): + match_ports=None, bypass_firewall=True, + tags=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) + bypass_firewall=bypass_firewall, + tags=tags) self.nsxlib.logical_router.add_nat_rule( logical_router_id, action="DNAT", translated_network=int_ip, dest_net=ext_ip, rule_priority=FIP_NAT_PRI, match_ports=match_ports, - bypass_firewall=bypass_firewall) + bypass_firewall=bypass_firewall, + tags=tags) def delete_fip_nat_rules_by_internal_ip(self, logical_router_id, int_ip): self.nsxlib.logical_router.delete_nat_rule_by_values(