|
| 1 | +"""List existing replicant volumes for a file 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 | + |
| 10 | +COLUMNS = [ |
| 11 | + column_helper.Column('ID', ('id',)), |
| 12 | + column_helper.Column('Username', ('username',), mask="username"), |
| 13 | + column_helper.Column('Account ID', ('accountId',), mask="accountId"), |
| 14 | + column_helper.Column('Capacity (GB)', ('capacityGb',), mask="capacityGb"), |
| 15 | + column_helper.Column('Hardware ID', ('hardwareId',), mask="hardwareId"), |
| 16 | + column_helper.Column('Guest ID', ('guestId',), mask="guestId"), |
| 17 | + column_helper.Column('Host ID', ('hostId',), mask="hostId"), |
| 18 | +] |
| 19 | + |
| 20 | +# In-line comment to avoid similarity flag with block version |
| 21 | + |
| 22 | +DEFAULT_COLUMNS = [ |
| 23 | + 'ID', |
| 24 | + 'Username', |
| 25 | + 'Account ID', |
| 26 | + 'Capacity (GB)', |
| 27 | + 'Hardware ID', |
| 28 | + 'Guest ID', |
| 29 | + 'Host ID' |
| 30 | +] |
| 31 | + |
| 32 | + |
| 33 | +@click.command() |
| 34 | +@click.argument('volume-id') |
| 35 | +@click.option('--sortby', help='Column to sort by', default='Username') |
| 36 | +@click.option('--columns', |
| 37 | + callback=column_helper.get_formatter(COLUMNS), |
| 38 | + help='Columns to display. Options: {0}'.format( |
| 39 | + ', '.join(column.name for column in COLUMNS)), |
| 40 | + default=','.join(DEFAULT_COLUMNS)) |
| 41 | +@environment.pass_env |
| 42 | +def cli(env, columns, sortby, volume_id): |
| 43 | + """List existing replicant volumes for a file volume.""" |
| 44 | + file_storage_manager = SoftLayer.FileStorageManager(env.client) |
| 45 | + |
| 46 | + legal_volumes = file_storage_manager.get_replication_partners( |
| 47 | + volume_id |
| 48 | + ) |
| 49 | + |
| 50 | + if not legal_volumes: |
| 51 | + click.echo("There are no replication partners for the given volume.") |
| 52 | + else: |
| 53 | + table = formatting.Table(columns.columns) |
| 54 | + table.sortby = sortby |
| 55 | + |
| 56 | + for legal_volume in legal_volumes: |
| 57 | + table.add_row([value or formatting.blank() |
| 58 | + for value in columns.row(legal_volume)]) |
| 59 | + |
| 60 | + env.fout(table) |
0 commit comments