|
12 | 12 |
|
13 | 13 |
|
14 | 14 | @click.command(cls=SLCommand) |
| 15 | +@click.argument('location', required=False) |
| 16 | +@click.option('--prices', '-p', is_flag=True, |
| 17 | + help='Use --prices to list the server item prices, and to list the Item Prices by location,' |
| 18 | + 'add it to the --prices option using location short name, e.g. --prices dal13') |
15 | 19 | @environment.pass_env |
16 | | -def cli(env): |
17 | | - """List all options for ordering a file storage""" |
| 20 | +def cli(env, prices, location=None): |
| 21 | + """List all options for ordering a block storage""" |
18 | 22 |
|
19 | 23 | order_manager = SoftLayer.OrderingManager(env.client) |
20 | 24 | items = order_manager.get_items(PACKAGE_STORAGE) |
21 | | - datacenters = order_manager.get_regions(PACKAGE_STORAGE) |
| 25 | + datacenters = order_manager.get_regions(PACKAGE_STORAGE, location) |
22 | 26 |
|
23 | | - iops_table = formatting.Table(['Id', 'Description', 'KeyName'], title='IOPS') |
24 | | - snapshot_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Snapshot') |
25 | | - file_storage_table = formatting.Table(['Id', 'Description', 'KeyName', 'Capacity Minimum'], title='Storage') |
| 27 | + tables = [] |
26 | 28 | datacenter_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Datacenter') |
27 | 29 |
|
28 | | - file_storage_table.align['Description'] = 'l' |
29 | | - file_storage_table.align['KeyName'] = 'l' |
30 | | - file_storage_table.sortby = 'Id' |
31 | 30 | for datacenter in datacenters: |
32 | 31 | datacenter_table.add_row([datacenter['location']['locationId'], |
33 | 32 | datacenter.get('description'), |
34 | 33 | datacenter['keyname']]) |
35 | 34 |
|
36 | | - for item in items: |
37 | | - if item['itemCategory']['categoryCode'] == 'performance_storage_space': |
38 | | - file_storage_table.add_row([item.get('id'), item.get('description'), |
39 | | - item.get('keyName'), item.get('capacityMinimum') or '-']) |
| 35 | + tables.append(datacenter_table) |
| 36 | + tables.append(_ios_get_table(items, prices)) |
| 37 | + tables.append(_file_storage_table(items, prices)) |
| 38 | + tables.append(_snapshot_get_table(items, prices)) |
| 39 | + env.fout(tables) |
40 | 40 |
|
41 | | - if item['itemCategory']['categoryCode'] == 'storage_tier_level': |
42 | | - iops_table.add_row([item.get('id'), item.get('description'), |
43 | | - item.get('keyName')]) |
44 | 41 |
|
45 | | - if item['itemCategory']['categoryCode'] == 'storage_snapshot_space': |
46 | | - snapshot_table.add_row([item.get('id'), item.get('description'), |
47 | | - item.get('keyName')]) |
| 42 | +def _ios_get_table(items, prices): |
| 43 | + if prices: |
| 44 | + table = formatting.Table(['Id', 'Description', 'KeyName', 'Prices'], title='IOPS') |
| 45 | + for item in items: |
| 46 | + if item['itemCategory']['categoryCode'] == 'storage_tier_level': |
| 47 | + table.add_row([item.get('id'), item.get('description'), |
| 48 | + item.get('keyName'), item['prices'][0]['recurringFee']]) |
| 49 | + else: |
| 50 | + table = formatting.Table(['Id', 'Description', 'KeyName'], title='IOPS') |
| 51 | + for item in items: |
| 52 | + if item['itemCategory']['categoryCode'] == 'storage_tier_level': |
| 53 | + table.add_row([item.get('id'), item.get('description'), |
| 54 | + item.get('keyName')]) |
| 55 | + table.sortby = 'Id' |
| 56 | + table.align = 'l' |
| 57 | + return table |
48 | 58 |
|
49 | | - env.fout(datacenter_table) |
50 | | - env.fout(iops_table) |
51 | | - env.fout(file_storage_table) |
52 | | - env.fout(snapshot_table) |
| 59 | + |
| 60 | +def _file_storage_table(items, prices): |
| 61 | + if prices: |
| 62 | + table = formatting.Table(['Id', 'Description', 'KeyName', 'Capacity Minimum', 'Prices'], title='Storage') |
| 63 | + for item in items: |
| 64 | + if item['itemCategory']['categoryCode'] == 'performance_storage_space': |
| 65 | + table.add_row([item.get('id'), item.get('description'), |
| 66 | + item.get('keyName'), item.get('capacityMinimum') or '-', |
| 67 | + item['prices'][0]['recurringFee']]) |
| 68 | + else: |
| 69 | + table = formatting.Table(['Id', 'Description', 'KeyName', 'Capacity Minimum'], title='Storage') |
| 70 | + for item in items: |
| 71 | + if item['itemCategory']['categoryCode'] == 'performance_storage_space': |
| 72 | + table.add_row([item.get('id'), item.get('description'), |
| 73 | + item.get('keyName'), item.get('capacityMinimum') or '-', ]) |
| 74 | + table.sortby = 'Id' |
| 75 | + table.align = 'l' |
| 76 | + return table |
| 77 | + |
| 78 | + |
| 79 | +def _snapshot_get_table(items, prices): |
| 80 | + if prices: |
| 81 | + table = formatting.Table(['Id', 'Description', 'KeyName', 'Prices'], title='Snapshot') |
| 82 | + for item in items: |
| 83 | + if item['itemCategory']['categoryCode'] == 'storage_snapshot_space': |
| 84 | + table.add_row([item.get('id'), item.get('description'), |
| 85 | + item.get('keyName'), item['prices'][0]['recurringFee']]) |
| 86 | + else: |
| 87 | + table = formatting.Table(['Id', 'Description', 'KeyName'], title='Snapshot') |
| 88 | + for item in items: |
| 89 | + if item['itemCategory']['categoryCode'] == 'storage_snapshot_space': |
| 90 | + table.add_row([item.get('id'), item.get('description'), |
| 91 | + item.get('keyName')]) |
| 92 | + table.sortby = 'Id' |
| 93 | + table.align = 'l' |
| 94 | + return table |
0 commit comments