|
| 1 | +"""List hosts with access to block volume.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | +import SoftLayer |
| 6 | +from SoftLayer.CLI import columns as column_helper |
| 7 | +from SoftLayer.CLI import environment |
| 8 | +from SoftLayer.CLI import formatting |
| 9 | +from SoftLayer.CLI import storage_utils |
| 10 | + |
| 11 | + |
| 12 | +@click.command() |
| 13 | +@click.argument('volume_id') |
| 14 | +@click.option('--sortby', help='Column to sort by', default='name') |
| 15 | +@click.option('--columns', |
| 16 | + callback=column_helper.get_formatter(storage_utils.COLUMNS), |
| 17 | + help='Columns to display. Options: {0}'.format( |
| 18 | + ', '.join(column.name for column in storage_utils.COLUMNS)), |
| 19 | + default=','.join(storage_utils.DEFAULT_COLUMNS)) |
| 20 | +@environment.pass_env |
| 21 | +def cli(env, columns, sortby, volume_id): |
| 22 | + """List ACLs.""" |
| 23 | + block_manager = SoftLayer.BlockStorageManager(env.client) |
| 24 | + access_list = block_manager.get_block_volume_access_list( |
| 25 | + volume_id=volume_id) |
| 26 | + table = formatting.Table(columns.columns) |
| 27 | + table.sortby = sortby |
| 28 | + |
| 29 | + for key, type_name in [('allowedVirtualGuests', 'VIRTUAL'), |
| 30 | + ('allowedHardware', 'HARDWARE'), |
| 31 | + ('allowedSubnets', 'SUBNET'), |
| 32 | + ('allowedIpAddresses', 'IP')]: |
| 33 | + for obj in access_list.get(key, []): |
| 34 | + obj['type'] = type_name |
| 35 | + table.add_row([value or formatting.blank() |
| 36 | + for value in columns.row(obj)]) |
| 37 | + |
| 38 | + env.fout(table) |
0 commit comments