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 46 47 48 49 50 51 52
|
"""List active Load Balancer as a Service 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 Load Balancer as a Service devices."""
mgr = SoftLayer.LoadBalancerManager(env.client)
lbaas = mgr.get_lbaas()
if lbaas:
lbaas_table = generate_lbaas_table(lbaas)
env.fout(lbaas_table)
else:
env.fout("No LBaaS devices found")
def location_sort(location):
"""Quick function that just returns the datacenter longName for sorting"""
return utils.lookup(location, 'datacenter', 'longName')
def generate_lbaas_table(lbaas):
"""Takes a list of SoftLayer_Network_LBaaS_LoadBalancer and makes a table"""
table = formatting.Table([
'Id', 'Location', 'Name', 'Description', 'Public', 'Create Date', 'Members', 'Listeners'
], title="IBM Cloud LoadBalancer")
table.align['Name'] = 'l'
table.align['Description'] = 'l'
table.align['Location'] = 'l'
for this_lb in sorted(lbaas, key=location_sort):
table.add_row([
this_lb.get('id'),
utils.lookup(this_lb, 'datacenter', 'longName'),
this_lb.get('name'),
this_lb.get('description'),
'Yes' if this_lb.get('isPublic', 1) == 1 else 'No',
utils.clean_time(this_lb.get('createDate')),
this_lb.get('memberCount', 0),
this_lb.get('listenerCount', 0)
])
return table
|