Add apis to get tier0 uplink cidrs and not just ips
Change-Id: I6583338b196de84c6d8db122609c6031a7750329
This commit is contained in:
parent
4d510cc632
commit
bb3fb29fad
@ -1039,9 +1039,9 @@ class NsxPolicyTier0Api(NsxPolicyResourceBase):
|
||||
return self.nsx_api.router.get_tier0_router_tz(
|
||||
nsx_router_uuid)
|
||||
|
||||
def get_uplink_ips(self, tier0_id, tenant=constants.POLICY_INFRA_TENANT):
|
||||
"""Return a link of all uplink ips of this tier0 router"""
|
||||
uplink_ips = []
|
||||
def _get_uplink_subnets(self, tier0_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
subnets = []
|
||||
services = self.get_locale_services(tier0_id, tenant=tenant)
|
||||
for srv in services:
|
||||
# get the interfaces of this service
|
||||
@ -1053,10 +1053,27 @@ class NsxPolicyTier0Api(NsxPolicyResourceBase):
|
||||
t0interface_def).get('results', [])
|
||||
for interface in interfaces:
|
||||
if interface.get('type') == 'EXTERNAL':
|
||||
for subnet in interface.get('subnets', []):
|
||||
uplink_ips.extend(subnet.get('ip_addresses', []))
|
||||
subnets.extend(interface.get('subnets', []))
|
||||
return subnets
|
||||
|
||||
def get_uplink_ips(self, tier0_id, tenant=constants.POLICY_INFRA_TENANT):
|
||||
"""Return a link of all uplink ips of this tier0 router"""
|
||||
subnets = self._get_uplink_subnets(tier0_id, tenant=tenant)
|
||||
uplink_ips = []
|
||||
for subnet in subnets:
|
||||
uplink_ips.extend(subnet.get('ip_addresses', []))
|
||||
return uplink_ips
|
||||
|
||||
def get_uplink_cidrs(self, tier0_id, tenant=constants.POLICY_INFRA_TENANT):
|
||||
"""Return a link of all uplink cidrs of this tier0 router"""
|
||||
subnets = self._get_uplink_subnets(tier0_id, tenant=tenant)
|
||||
cidrs = []
|
||||
for subnet in subnets:
|
||||
for ip_address in subnet.get('ip_addresses'):
|
||||
cidrs.append('%s/%s' % (ip_address,
|
||||
subnet.get('prefix_len')))
|
||||
return cidrs
|
||||
|
||||
|
||||
class NsxPolicyTier1NatRuleApi(NsxPolicyResourceBase):
|
||||
DEFAULT_NAT_ID = 'USER'
|
||||
|
@ -357,13 +357,29 @@ class LogicalRouterPort(utils.NsxLibApiBase):
|
||||
if port['resource_type'] == nsx_constants.LROUTERPORT_UPLINK:
|
||||
return port
|
||||
|
||||
def get_tier0_uplink_ips(self, logical_router_id):
|
||||
def get_tier0_uplink_subnets(self, logical_router_id):
|
||||
port = self.get_tier0_uplink_port(logical_router_id)
|
||||
ips = []
|
||||
if port:
|
||||
for subnet in port.get('subnets', []):
|
||||
for ip_address in subnet.get('ip_addresses'):
|
||||
ips.append(ip_address)
|
||||
return port.get('subnets', [])
|
||||
return []
|
||||
|
||||
def get_tier0_uplink_cidrs(self, logical_router_id):
|
||||
# return a list of tier0 uplink ip/prefix addresses
|
||||
subnets = self.get_tier0_uplink_subnets(logical_router_id)
|
||||
cidrs = []
|
||||
for subnet in subnets:
|
||||
for ip_address in subnet.get('ip_addresses'):
|
||||
cidrs.append('%s/%s' % (ip_address,
|
||||
subnet.get('prefix_length')))
|
||||
return cidrs
|
||||
|
||||
def get_tier0_uplink_ips(self, logical_router_id):
|
||||
# return a list of tier0 uplink ip addresses
|
||||
subnets = self.get_tier0_uplink_subnets(logical_router_id)
|
||||
ips = []
|
||||
for subnet in subnets:
|
||||
for ip_address in subnet.get('ip_addresses'):
|
||||
ips.append(ip_address)
|
||||
return ips
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user