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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
"""List all options for ordering a file storage."""
# :license: MIT, see LICENSE for more details.
import click
import SoftLayer
from SoftLayer.CLI.command import SLCommand
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting
PACKAGE_STORAGE = 759
@click.command(cls=SLCommand)
@click.argument('location', required=False)
@click.option('--prices', '-p', is_flag=True,
help='Use --prices to list the server item prices, and to list the Item Prices by location,'
'add it to the --prices option using location short name, e.g. --prices dal13')
@environment.pass_env
def cli(env, prices, location=None):
"""List all options for ordering a block storage
Example::
slcli file volume-options
slcli file volume-options --prices dal13
"""
order_manager = SoftLayer.OrderingManager(env.client)
items = order_manager.get_items(PACKAGE_STORAGE)
datacenters = order_manager.get_regions(PACKAGE_STORAGE, location)
tables = []
network = SoftLayer.NetworkManager(env.client)
pods = network.get_closed_pods()
if datacenters != []:
datacenter_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Datacenter')
for datacenter in datacenters:
closure = []
for pod in pods:
if datacenter['location']['location']['name'] in str(pod['name']):
closure.append(pod['name'])
notes = '-'
if len(closure) > 0:
notes = 'closed soon: %s' % (', '.join(closure))
datacenter_table.add_row([datacenter['location']['locationId'],
datacenter.get('description'),
datacenter['keyname'], notes])
tables.append(datacenter_table)
else:
raise exceptions.CLIAbort('Location does not exit.')
tables.append(_file_ios_get_table(items, prices))
tables.append(_file_storage_table(items, prices))
tables.append(_file_snapshot_get_table(items, prices))
env.fout(tables)
def _file_ios_get_table(items, prices):
if prices:
table = formatting.Table(['Id', 'Description', 'KeyName', 'Prices'], title='IOPS')
for item in items:
if item['itemCategory']['categoryCode'] == 'storage_tier_level':
table.add_row([item.get('id'), item.get('description'),
item.get('keyName'), item['prices'][0]['recurringFee']])
else:
table = formatting.Table(['Id', 'Description', 'KeyName'], title='IOPS')
for item in items:
if item['itemCategory']['categoryCode'] == 'storage_tier_level':
table.add_row([item.get('id'), item.get('description'),
item.get('keyName')])
table.sortby = 'Id'
table.align = 'l'
return table
def _file_storage_table(items, prices):
if prices:
table = formatting.Table(['Id', 'Description', 'KeyName', 'Capacity Minimum', 'Prices'], title='Storage')
for item in items:
if item['itemCategory']['categoryCode'] == 'performance_storage_space':
table.add_row([item.get('id'), item.get('description'),
item.get('keyName'), item.get('capacityMinimum') or '-',
item['prices'][0]['recurringFee']])
else:
table = formatting.Table(['Id', 'Description', 'KeyName', 'Capacity Minimum'], title='Storage')
for item in items:
if item['itemCategory']['categoryCode'] == 'performance_storage_space':
table.add_row([item.get('id'), item.get('description'),
item.get('keyName'), item.get('capacityMinimum') or '-', ])
table.sortby = 'Id'
table.align = 'l'
return table
def _file_snapshot_get_table(items, prices):
if prices:
table = formatting.Table(['Id', 'Description', 'KeyName', 'Prices'], title='Snapshot')
for item in items:
if item['itemCategory']['categoryCode'] == 'storage_snapshot_space':
table.add_row([item.get('id'), item.get('description'),
item.get('keyName'), item['prices'][0]['recurringFee']])
else:
table = formatting.Table(['Id', 'Description', 'KeyName'], title='Snapshot')
for item in items:
if item['itemCategory']['categoryCode'] == 'storage_snapshot_space':
table.add_row([item.get('id'), item.get('description'),
item.get('keyName')])
table.sortby = 'Id'
table.align = 'l'
return table
|