From 3f2ac2925f2ceb94aa275c0b8d4e69cfb6e144fc Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Thu, 3 Dec 2015 11:39:27 -0600 Subject: [PATCH] Fixes keyerror with `vlan list` and `vlan detail` Adds backend ip address to virtual and hardware listed under `vlan detail` --- SoftLayer/CLI/summary.py | 24 ++++++++++-------------- SoftLayer/CLI/vlan/detail.py | 20 +++++++++----------- SoftLayer/CLI/vlan/list.py | 30 ++++++++++++++---------------- SoftLayer/managers/network.py | 2 +- 4 files changed, 34 insertions(+), 42 deletions(-) diff --git a/SoftLayer/CLI/summary.py b/SoftLayer/CLI/summary.py index 9e0d59f2c..6a17a71cf 100644 --- a/SoftLayer/CLI/summary.py +++ b/SoftLayer/CLI/summary.py @@ -8,16 +8,19 @@ from SoftLayer.CLI import formatting +COLUMNS = ['datacenter', + 'hardware', + 'virtual_servers', + 'vlans', + 'subnets', + 'public_ips'] + + @click.command() @click.option('--sortby', help='Column to sort by', default='datacenter', - type=click.Choice(['datacenter', - 'hardware', - 'virtual_servers', - 'vlans', - 'subnets', - 'public_ips'])) + type=click.Choice(COLUMNS)) @environment.pass_env def cli(env, sortby): """Account summary.""" @@ -25,14 +28,7 @@ def cli(env, sortby): mgr = SoftLayer.NetworkManager(env.client) datacenters = mgr.summary_by_datacenter() - table = formatting.Table([ - 'datacenter', - 'hardware', - 'virtual_servers', - 'vlans', - 'subnets', - 'public_ips', - ]) + table = formatting.Table(COLUMNS) table.sortby = sortby for name, datacenter in datacenters.items(): diff --git a/SoftLayer/CLI/vlan/detail.py b/SoftLayer/CLI/vlan/detail.py index 14782b09a..178c9981e 100644 --- a/SoftLayer/CLI/vlan/detail.py +++ b/SoftLayer/CLI/vlan/detail.py @@ -34,7 +34,7 @@ def cli(env, identifier, no_vs, no_hardware): table.add_row(['number', vlan['vlanNumber']]) table.add_row(['datacenter', vlan['primaryRouter']['datacenter']['longName']]) - table.add_row(['primary router', + table.add_row(['primary_router', vlan['primaryRouter']['fullyQualifiedDomainName']]) table.add_row(['firewall', 'Yes' if vlan['firewallInterfaces'] else 'No']) @@ -54,30 +54,28 @@ def cli(env, identifier, no_vs, no_hardware): table.add_row(['subnets', subnets]) + server_columns = ['hostname', 'domain', 'public_ip', 'private_ip'] + if not no_vs: if vlan['virtualGuests']: - vs_table = formatting.KeyValueTable(['Hostname', - 'Domain', - 'IP']) - vs_table.align['Hostname'] = 'r' - vs_table.align['IP'] = 'l' + vs_table = formatting.KeyValueTable(server_columns) for vsi in vlan['virtualGuests']: vs_table.add_row([vsi['hostname'], vsi['domain'], - vsi.get('primaryIpAddress')]) + vsi.get('primaryIpAddress'), + vsi.get('primaryBackendIpAddress')]) table.add_row(['vs', vs_table]) else: table.add_row(['vs', 'none']) if not no_hardware: if vlan['hardware']: - hw_table = formatting.Table(['Hostname', 'Domain', 'IP']) - hw_table.align['Hostname'] = 'r' - hw_table.align['IP'] = 'l' + hw_table = formatting.Table(server_columns) for hardware in vlan['hardware']: hw_table.add_row([hardware['hostname'], hardware['domain'], - hardware.get('primaryIpAddress')]) + hardware.get('primaryIpAddress'), + hardware.get('primaryBackendIpAddress')]) table.add_row(['hardware', hw_table]) else: table.add_row(['hardware', 'none']) diff --git a/SoftLayer/CLI/vlan/list.py b/SoftLayer/CLI/vlan/list.py index 3493ebfdf..1ad001ea7 100644 --- a/SoftLayer/CLI/vlan/list.py +++ b/SoftLayer/CLI/vlan/list.py @@ -8,18 +8,20 @@ from SoftLayer.CLI import formatting from SoftLayer import utils +COLUMNS = ['id', + 'number', + 'name', + 'firewall', + 'datacenter', + 'hardware', + 'virtual_servers', + 'public_ips'] + @click.command() @click.option('--sortby', help='Column to sort by', - type=click.Choice(['id', - 'number', - 'datacenter', - 'IPs', - 'hardware', - 'vs', - 'networking', - 'firewall'])) + type=click.Choice(COLUMNS)) @click.option('--datacenter', '-d', help='Filter by datacenter shortname (sng01, dal05, ...)') @click.option('--number', '-n', help='Filter by VLAN number') @@ -30,10 +32,7 @@ def cli(env, sortby, datacenter, number, name): mgr = SoftLayer.NetworkManager(env.client) - table = formatting.Table([ - 'id', 'number', 'datacenter', 'name', 'IPs', 'hardware', 'vs', - 'networking', 'firewall' - ]) + table = formatting.Table(COLUMNS) table.sortby = sortby vlans = mgr.list_vlans(datacenter=datacenter, @@ -43,13 +42,12 @@ def cli(env, sortby, datacenter, number, name): table.add_row([ vlan['id'], vlan['vlanNumber'], - utils.lookup(vlan, 'primaryRouter', 'datacenter', 'name'), vlan.get('name') or formatting.blank(), - vlan['totalPrimaryIpAddressCount'], + 'Yes' if vlan['firewallInterfaces'] else 'No', + utils.lookup(vlan, 'primaryRouter', 'datacenter', 'name'), len(vlan['hardware']), len(vlan['virtualGuests']), - len(vlan['networkComponents']), - 'Yes' if vlan['firewallInterfaces'] else 'No', + vlan['totalPrimaryIpAddressCount'], ]) env.fout(table) diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index 04cd8bf5c..029d529d1 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -350,7 +350,7 @@ def summary_by_datacenter(self): datacenters[name]['vlan_count'] += 1 datacenters[name]['public_ip_count'] += ( vlan['totalPrimaryIpAddressCount']) - datacenters[name]['vlan_count'] += len(vlan['subnets']) + datacenters[name]['subnet_count'] += len(vlan['subnets']) for hardware in vlan['hardware']: if hardware['id'] not in unique_servers: