Skip to content

Commit fdd1f6d

Browse files
caberoscaberos
authored andcommitted
block/file volume-options improvement 3
1 parent 963fe01 commit fdd1f6d

File tree

3 files changed

+134
-47
lines changed

3 files changed

+134
-47
lines changed

SoftLayer/CLI/block/options.py

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,83 @@
1212

1313

1414
@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')
1519
@environment.pass_env
16-
def cli(env):
20+
def cli(env, prices, location=None):
1721
"""List all options for ordering a block storage"""
1822

1923
order_manager = SoftLayer.OrderingManager(env.client)
2024
items = order_manager.get_items(PACKAGE_STORAGE)
21-
datacenters = order_manager.get_regions(PACKAGE_STORAGE)
25+
datacenters = order_manager.get_regions(PACKAGE_STORAGE, location)
2226

23-
iops_table = formatting.Table(['Id', 'Description', 'KeyName'], title='IOPS')
24-
snapshot_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Snapshot')
25-
storage_table = formatting.Table(['Id', 'Description', 'KeyName', 'Capacity Minimum'], title='Storage')
27+
tables = []
2628
datacenter_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Datacenter')
2729

28-
storage_table.align['Description'] = 'l'
29-
storage_table.align['KeyName'] = 'l'
30-
storage_table.sortby = 'Id'
3130
for datacenter in datacenters:
3231
datacenter_table.add_row([datacenter['location']['locationId'],
3332
datacenter.get('description'),
3433
datacenter['keyname']])
3534

36-
for item in items:
37-
if item['itemCategory']['categoryCode'] == 'performance_storage_space':
38-
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(_storage_table(items, prices))
38+
tables.append(_snapshot_get_table(items, prices))
39+
env.fout(tables)
4040

41-
if item['itemCategory']['categoryCode'] == 'storage_tier_level':
42-
iops_table.add_row([item.get('id'), item.get('description'),
43-
item.get('keyName')])
4441

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
4858

49-
env.fout(datacenter_table)
50-
env.fout(iops_table)
51-
env.fout(storage_table)
52-
env.fout(snapshot_table)
59+
60+
def _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

SoftLayer/CLI/file/options.py

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,83 @@
1212

1313

1414
@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')
1519
@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"""
1822

1923
order_manager = SoftLayer.OrderingManager(env.client)
2024
items = order_manager.get_items(PACKAGE_STORAGE)
21-
datacenters = order_manager.get_regions(PACKAGE_STORAGE)
25+
datacenters = order_manager.get_regions(PACKAGE_STORAGE, location)
2226

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 = []
2628
datacenter_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Datacenter')
2729

28-
file_storage_table.align['Description'] = 'l'
29-
file_storage_table.align['KeyName'] = 'l'
30-
file_storage_table.sortby = 'Id'
3130
for datacenter in datacenters:
3231
datacenter_table.add_row([datacenter['location']['locationId'],
3332
datacenter.get('description'),
3433
datacenter['keyname']])
3534

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)
4040

41-
if item['itemCategory']['categoryCode'] == 'storage_tier_level':
42-
iops_table.add_row([item.get('id'), item.get('description'),
43-
item.get('keyName')])
4441

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
4858

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

SoftLayer/managers/ordering.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,12 @@ def get_items(self, package_id, storage_filter=None):
728728
return self.client.call('SoftLayer_Product_Package', 'getItems', filter=storage_filter,
729729
id=package_id)
730730

731-
def get_regions(self, package_id):
731+
def get_regions(self, package_id, location=None):
732732
"""returns the all regions.
733733
734734
:param int package_id: The package for which to get the items.
735735
"""
736-
return self.client.call('SoftLayer_Product_Package', 'getRegions', id=package_id)
736+
_filter = ''
737+
if location:
738+
_filter = {"regions": {"location": {"location": {"name": {"operation": location}}}}}
739+
return self.client.call('SoftLayer_Product_Package', 'getRegions', id=package_id, filter=_filter)

0 commit comments

Comments
 (0)