1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
"""List active Netscaler devices."""
import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer import utils
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@environment.pass_env
def cli(env):
"""List active Netscaler devices."""
mgr = SoftLayer.LoadBalancerManager(env.client)
netscalers = mgr.get_adcs()
if netscalers:
adc_table = generate_netscaler_table(netscalers)
env.fout(adc_table)
else:
env.fout("No Netscalers")
def location_sort(location):
"""Quick function that just returns the datacenter longName for sorting"""
return utils.lookup(location, 'datacenter', 'longName')
def generate_netscaler_table(netscalers):
"""Tales a list of SoftLayer_Network_Application_Delivery_Controller and makes a table"""
table = formatting.Table([
'Id', 'Location', 'Name', 'Description', 'IP Address', 'Management Ip', 'Bandwidth', 'Create Date'
], title="Netscalers")
for adc in sorted(netscalers, key=location_sort):
table.add_row([
adc.get('id'),
utils.lookup(adc, 'datacenter', 'longName'),
adc.get('name'),
adc.get('description'),
adc.get('primaryIpAddress'),
adc.get('managementIpAddress'),
adc.get('outboundPublicBandwidthUsage', 0),
utils.clean_time(adc.get('createDate'))
])
return table
|