Skip to content

Migrated away from using Vlan.primaryRouter to find a VLAN's datacenter #2209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions SoftLayer/CLI/subnet/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ def cli(env, identifier, no_vs, no_hardware):
subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier,
name='subnet')

mask = 'mask[ipAddresses[id, ipAddress, note, isBroadcast, isGateway, isNetwork, isReserved, ' \
'hardware, virtualGuest], datacenter, virtualGuests, hardware,' \
' networkVlan[networkSpace,primaryRouter]]'
mask = """mask[
networkIdentifier, cidr, subnetType, gateway, broadcastAddress, usableIpAddressCount, note, id,
ipAddresses[
id, ipAddress, note, isBroadcast, isGateway, isNetwork, isReserved,
hardware[id, fullyQualifiedDomainName],
virtualGuest[id, fullyQualifiedDomainName]
],
datacenter[name], networkVlan[networkSpace], tagReferences,
virtualGuests[id, fullyQualifiedDomainName, hostname, domain, primaryIpAddress, primaryBackendIpAddress],
hardware[id, fullyQualifiedDomainName, hostname, domain, primaryIpAddress, primaryBackendIpAddress]
]"""

subnet = mgr.get_subnet(subnet_id, mask=mask)

Expand All @@ -37,22 +45,15 @@ def cli(env, identifier, no_vs, no_hardware):
table.align['value'] = 'l'

table.add_row(['id', subnet['id']])
table.add_row(['identifier',
'%s/%s' % (subnet['networkIdentifier'],
str(subnet['cidr']))])
table.add_row(['identifier', f"{subnet['networkIdentifier']}/{subnet['cidr']}"])
table.add_row(['subnet type', subnet.get('subnetType', formatting.blank())])
table.add_row(['network space',
utils.lookup(subnet, 'networkVlan', 'networkSpace')])
table.add_row(['network space', utils.lookup(subnet, 'networkVlan', 'networkSpace')])
table.add_row(['gateway', subnet.get('gateway', formatting.blank())])
table.add_row(['broadcast',
subnet.get('broadcastAddress', formatting.blank())])
table.add_row(['broadcast', subnet.get('broadcastAddress', formatting.blank())])
table.add_row(['datacenter', subnet['datacenter']['name']])
table.add_row(['usable ips',
subnet.get('usableIpAddressCount', formatting.blank())])
table.add_row(['note',
subnet.get('note', formatting.blank())])
table.add_row(['tags',
formatting.tags(subnet.get('tagReferences'))])
table.add_row(['usable ips', subnet.get('usableIpAddressCount', formatting.blank())])
table.add_row(['note', subnet.get('note', formatting.blank())])
table.add_row(['tags', formatting.tags(subnet.get('tagReferences'))])

ip_address = subnet.get('ipAddresses')

Expand All @@ -72,8 +73,9 @@ def cli(env, identifier, no_vs, no_hardware):
elif address.get('virtualGuest') is not None:
description = address['virtualGuest']['fullyQualifiedDomainName']
status = 'In use'
ip_table.add_row([address.get('id'), status,
address.get('ipAddress') + '/' + description, address.get('note', '-')])
ip_table.add_row([
address.get('id'), status, f"{address.get('ipAddress')}/{description}", address.get('note', '-')
])

table.add_row(['ipAddresses', ip_table])

Expand Down
4 changes: 2 additions & 2 deletions SoftLayer/CLI/vlan/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def cli(env, identifier, no_vs, no_hardware, no_trunks):
vlan_id = helpers.resolve_id(mgr.resolve_vlan_ids, identifier, 'VLAN')

mask = """mask[
firewallInterfaces, primaryRouter[id, fullyQualifiedDomainName, datacenter[longName]],
firewallInterfaces, datacenter[name, longName], primaryRouter[fullyQualifiedDomainName],
totalPrimaryIpAddressCount,
networkSpace, id, vlanNumber, fullyQualifiedName, name,
hardware[id, hostname, domain, primaryIpAddress, primaryBackendIpAddress, tagReferences],
Expand All @@ -52,7 +52,7 @@ def cli(env, identifier, no_vs, no_hardware, no_trunks):

table.add_row(['id', vlan.get('id')])
table.add_row(['number', vlan.get('vlanNumber')])
table.add_row(['datacenter', utils.lookup(vlan, 'primaryRouter', 'datacenter', 'longName')])
table.add_row(['datacenter', utils.lookup(vlan, 'datacenter', 'longName')])
table.add_row(['primary_router', utils.lookup(vlan, 'primaryRouter', 'fullyQualifiedDomainName')])
table.add_row(['Gateway/Firewall', get_gateway_firewall(vlan)])

Expand Down
15 changes: 4 additions & 11 deletions SoftLayer/CLI/vlan/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,9 @@ def cli(env, sortby, datacenter, number, name, limit):
table = formatting.Table(COLUMNS)
table.sortby = sortby

vlans = mgr.list_vlans(datacenter=datacenter,
vlan_number=number,
name=name,
limit=limit)
vlans = mgr.list_vlans(datacenter=datacenter, vlan_number=number, name=name, limit=limit)

pod_mask = """mask[
name, datacenterLongName, capabilities, datacenterId,
backendRouterId, backendRouterName, frontendRouterName, frontendRouterId
]"""
pod_mask = """mask[name, capabilities]"""
pods = mgr.get_pods(mask=pod_mask)

for vlan in vlans:
Expand All @@ -66,7 +60,7 @@ def cli(env, sortby, datacenter, number, name, limit):
vlan.get('fullyQualifiedName'),
vlan.get('name') or formatting.blank(),
vlan.get('networkSpace', 'Direct Link').capitalize(),
utils.lookup(vlan, 'primaryRouter', 'datacenter', 'name'),
utils.lookup(vlan, 'datacenter', 'name'),
get_pod_with_closed_announcement(vlan, pods),
get_gateway_firewall(vlan),
vlan.get('hardwareCount'),
Expand All @@ -82,8 +76,7 @@ def cli(env, sortby, datacenter, number, name, limit):
def get_pod_with_closed_announcement(vlan, pods):
"""Gets pods with announcement to close"""
for pod in pods:
if utils.lookup(pod, 'backendRouterId') == utils.lookup(vlan, 'primaryRouter', 'id') \
or utils.lookup(pod, 'frontendRouterId') == utils.lookup(vlan, 'primaryRouter', 'id'):
if utils.lookup(pod, 'name') == utils.lookup(vlan, 'podName'):
if 'CLOSURE_ANNOUNCED' in utils.lookup(pod, 'capabilities'):
name_pod = utils.lookup(pod, 'name').split('.')[1] + '*'
return "[red]" + name_pod.capitalize() + "[/red]"
Expand Down
7 changes: 3 additions & 4 deletions SoftLayer/managers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,10 @@ def list_vlans(self, datacenter=None, vlan_number=None, name=None, limit=100, ma

"""
vlan_mask = """mask[
networkSpace, id, vlanNumber, fullyQualifiedName, name,
networkSpace, id, vlanNumber, fullyQualifiedName, name, datacenter[name], podName,
networkVlanFirewall[id,fullyQualifiedDomainName], attachedNetworkGateway[id,name],
firewallInterfaces, primaryRouter[id, fullyQualifiedDomainName, datacenter[name]],
hardwareCount, subnetCount, totalPrimaryIpAddressCount, virtualGuestCount,
billingItem[id], tagReferences[tag[name]]
firewallInterfaces, billingItem[id], tagReferences[tag[name]],
hardwareCount, subnetCount, totalPrimaryIpAddressCount, virtualGuestCount
]"""
_filter = utils.NestedDict(_filter or {})

Expand Down
Loading