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
This commit is contained in:
Qian Sun 2018-05-17 01:38:25 -07:00
parent c1a775e492
commit 734270d9e9
3 changed files with 16 additions and 7 deletions

View File

@ -715,9 +715,11 @@ class LogicalRouterTestCase(BaseTestResource):
router = self.get_mocked_resource() router = self.get_mocked_resource()
translated_net = '1.1.1.1' translated_net = '1.1.1.1'
priority = 10 priority = 10
display_name = 'fake_name'
data = { data = {
'action': action, 'action': action,
'display_name': display_name,
'enabled': True, 'enabled': True,
'translated_network': translated_net, 'translated_network': translated_net,
'rule_priority': priority 'rule_priority': priority
@ -734,7 +736,8 @@ class LogicalRouterTestCase(BaseTestResource):
action=action, action=action,
translated_network=translated_net, translated_network=translated_net,
rule_priority=priority, rule_priority=priority,
bypass_firewall=False) bypass_firewall=False,
display_name=display_name)
except exceptions.InvalidInput as e: except exceptions.InvalidInput as e:
if expect_failure: if expect_failure:
return return

View File

@ -532,7 +532,8 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase):
match_ports=None, match_protocol=None, match_ports=None, match_protocol=None,
match_resource_type=None, match_resource_type=None,
bypass_firewall=True, bypass_firewall=True,
tags=None): tags=None,
display_name=None):
self._validate_nat_rule_action(action) self._validate_nat_rule_action(action)
resource = 'logical-routers/%s/nat/rules' % logical_router_id resource = 'logical-routers/%s/nat/rules' % logical_router_id
body = {'action': action, body = {'action': action,
@ -561,6 +562,8 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase):
"this feature is not supported.", logical_router_id) "this feature is not supported.", logical_router_id)
if tags is not None: if tags is not None:
body['tags'] = tags body['tags'] = tags
if display_name:
body['display_name'] = display_name
return self.client.create(resource, body) return self.client.create(resource, body)
def add_static_route(self, logical_router_id, dest_cidr, nexthop): def add_static_route(self, logical_router_id, dest_cidr, nexthop):

View File

@ -153,14 +153,15 @@ class RouterLib(object):
skip_not_found=True, strict_mode=False) skip_not_found=True, strict_mode=False)
def add_gw_snat_rule(self, logical_router_id, gw_ip, source_net=None, 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( return self.nsxlib.logical_router.add_nat_rule(
logical_router_id, action="SNAT", logical_router_id, action="SNAT",
translated_network=gw_ip, translated_network=gw_ip,
source_net=source_net, source_net=source_net,
rule_priority=GW_NAT_PRI, rule_priority=GW_NAT_PRI,
bypass_firewall=bypass_firewall, bypass_firewall=bypass_firewall,
tags=tags) tags=tags,
display_name=display_name)
def update_router_edge_cluster(self, nsx_router_id, edge_cluster_uuid): def update_router_edge_cluster(self, nsx_router_id, edge_cluster_uuid):
return self._router_client.update(nsx_router_id, 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, 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): tags=None, display_name=None):
self.nsxlib.logical_router.add_nat_rule( self.nsxlib.logical_router.add_nat_rule(
logical_router_id, action="SNAT", logical_router_id, action="SNAT",
translated_network=ext_ip, translated_network=ext_ip,
source_net=int_ip, source_net=int_ip,
rule_priority=FIP_NAT_PRI, rule_priority=FIP_NAT_PRI,
bypass_firewall=bypass_firewall, bypass_firewall=bypass_firewall,
tags=tags) tags=tags,
display_name=display_name)
self.nsxlib.logical_router.add_nat_rule( self.nsxlib.logical_router.add_nat_rule(
logical_router_id, action="DNAT", logical_router_id, action="DNAT",
translated_network=int_ip, translated_network=int_ip,
@ -215,7 +217,8 @@ class RouterLib(object):
rule_priority=FIP_NAT_PRI, rule_priority=FIP_NAT_PRI,
match_ports=match_ports, match_ports=match_ports,
bypass_firewall=bypass_firewall, 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): def delete_fip_nat_rules_by_internal_ip(self, logical_router_id, int_ip):
self.nsxlib.logical_router.delete_nat_rule_by_values( self.nsxlib.logical_router.delete_nat_rule_by_values(