1"""List securitygroups.""" 2# :license: MIT, see LICENSE for more details. 3 4import click 5 6import SoftLayer 7from SoftLayer.CLI import environment 8from SoftLayer.CLI import formatting 9 10COLUMNS = ['id', 11 'name', 12 'description', ] 13 14 15@click.command() 16@click.option('--sortby', 17 help='Column to sort by', 18 type=click.Choice(COLUMNS)) 19@click.option('--limit', '-l', 20 help='How many results to get in one api call, default is 100', 21 default=100, 22 show_default=True) 23@environment.pass_env 24def cli(env, sortby, limit): 25 """List security groups.""" 26 27 mgr = SoftLayer.NetworkManager(env.client) 28 29 table = formatting.Table(COLUMNS) 30 table.sortby = sortby 31 32 sgs = mgr.list_securitygroups(limit=limit) 33 for secgroup in sgs: 34 table.add_row([ 35 secgroup['id'], 36 secgroup.get('name') or formatting.blank(), 37 secgroup.get('description') or formatting.blank(), 38 ]) 39 40 env.fout(table) 41