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 53 54 55 56 57 58
|
"""List file storage snapshots."""
# :license: MIT, see LICENSE for more details.
import click
import SoftLayer
from SoftLayer.CLI import columns as column_helper
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.CLI import helpers
COLUMNS = [
column_helper.Column('id', ('id',), mask='id'),
column_helper.Column('name', ('notes',), mask='notes'),
column_helper.Column('created', ('snapshotCreationTimestamp',),
mask='snapshotCreationTimestamp'),
column_helper.Column('size_bytes', ('snapshotSizeBytes',),
mask='snapshotSizeBytes'),
]
DEFAULT_COLUMNS = [
'id',
'name',
'created',
'size_bytes'
]
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('volume_id')
@click.option('--sortby', help='Column to sort by',
default='created')
@click.option('--columns',
callback=column_helper.get_formatter(COLUMNS),
help=f"Columns to display. Options: {', '.join(column.name for column in COLUMNS)}",
default=','.join(DEFAULT_COLUMNS))
@environment.pass_env
def cli(env, volume_id, sortby, columns):
"""List file storage snapshots.
Example::
slcli file snapshot-list 12345678 --sortby id
This command lists all snapshots of volume with ID 12345678 and sorts them by ID.
"""
file_manager = SoftLayer.FileStorageManager(env.client)
resolved_id = helpers.resolve_id(file_manager.resolve_ids, volume_id, 'Volume Id')
snapshots = file_manager.get_file_volume_snapshot_list(
resolved_id,
mask=columns.mask()
)
table = formatting.Table(columns.columns)
table.sortby = sortby
for snapshot in snapshots:
table.add_row([value or formatting.blank()
for value in columns.row(snapshot)])
env.fout(table)
|