Skip to content

Commit cdf590a

Browse files
Merge pull request #1681 from caberos/issue1673
add the block volume-options command
2 parents 119d2b3 + 78c02cc commit cdf590a

File tree

7 files changed

+86
-2
lines changed

7 files changed

+86
-2
lines changed

SoftLayer/CLI/block/options.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""List all options for ordering a block storage."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI.command import SLCommand
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import formatting
10+
11+
PACKAGE_STORAGE = 759
12+
13+
14+
@click.command(cls=SLCommand)
15+
@environment.pass_env
16+
def cli(env):
17+
"""List all options for ordering a block storage"""
18+
19+
order_manager = SoftLayer.OrderingManager(env.client)
20+
items = order_manager.get_items(PACKAGE_STORAGE)
21+
datacenters = order_manager.get_regions(PACKAGE_STORAGE)
22+
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'], title='Storage')
26+
datacenter_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Datacenter')
27+
28+
for datacenter in datacenters:
29+
datacenter_table.add_row([datacenter['location']['locationId'],
30+
datacenter.get('description'),
31+
datacenter['keyname']])
32+
33+
for item in items:
34+
if item['itemCategory']['categoryCode'] == 'performance_storage_space':
35+
storage_table.add_row([item.get('id'), item.get('description'),
36+
item.get('keyName')])
37+
38+
if item['itemCategory']['categoryCode'] == 'storage_tier_level':
39+
iops_table.add_row([item.get('id'), item.get('description'),
40+
item.get('keyName')])
41+
42+
if item['itemCategory']['categoryCode'] == 'storage_snapshot_space':
43+
snapshot_table.add_row([item.get('id'), item.get('description'),
44+
item.get('keyName')])
45+
46+
env.fout(datacenter_table)
47+
env.fout(iops_table)
48+
env.fout(storage_table)
49+
env.fout(snapshot_table)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
('block:volume-limits', 'SoftLayer.CLI.block.limit:cli'),
126126
('block:volume-refresh', 'SoftLayer.CLI.block.refresh:cli'),
127127
('block:volume-convert', 'SoftLayer.CLI.block.convert:cli'),
128+
('block:volume-options', 'SoftLayer.CLI.block.options:cli'),
128129
('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),
129130
('block:object-list', 'SoftLayer.CLI.block.object_list:cli'),
130131
('block:object-storage-detail', 'SoftLayer.CLI.block.object_storage_detail:cli'),

SoftLayer/fixtures/SoftLayer_Location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
"longName": "San Jose 1",
1010
"name": "sjc01"
1111
}]
12-
getDatacenters = [{'id': 1854895, 'name': 'dal13', 'regions': [{'keyname': 'DALLAS13'}]}]
12+
getDatacenters = [{'id': 1854895, 'longName': 'dallas 13', 'name': 'dal13', 'regions': [{'keyname': 'DALLAS13'}]}]

SoftLayer/managers/ordering.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
:license: MIT, see LICENSE for more details.
77
"""
88

9-
109
from re import match
1110

1211
from SoftLayer import exceptions
@@ -717,3 +716,21 @@ def resolve_location_name(self, location_key):
717716
if location.get('regions', default_regions)[index_first].get('keyname') == location_key:
718717
return location_name
719718
raise exceptions.SoftLayerError("Location {} does not exist".format(location_key))
719+
720+
def get_items(self, package_id, storage_filter=None):
721+
""""Returns the items .
722+
723+
724+
:param int package_id: The package for which to get the items.
725+
:param dict storage_filter: object filter.
726+
"""
727+
728+
return self.client.call('SoftLayer_Product_Package', 'getItems', filter=storage_filter,
729+
id=package_id)
730+
731+
def get_regions(self, package_id):
732+
"""returns the all regions.
733+
734+
:param int package_id: The package for which to get the items.
735+
"""
736+
return self.client.call('SoftLayer_Product_Package', 'getRegions', id=package_id)

docs/cli/block.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ Block Commands
8383
:prog: block volume-count
8484
:show-nested:
8585

86+
.. click:: SoftLayer.CLI.block.options:cli
87+
:prog: block volume-options
88+
:show-nested:
89+
8690
.. click:: SoftLayer.CLI.block.detail:cli
8791
:prog: block volume-detail
8892
:show-nested:

tests/CLI/modules/block_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,11 @@ def test_dep_dupe_convert(self):
792792

793793
self.assert_no_fail(result)
794794

795+
def test_volume_options(self):
796+
result = self.run_command(['block', 'volume-options'])
797+
798+
self.assert_no_fail(result)
799+
795800
@mock.patch('SoftLayer.BlockStorageManager.volume_set_note')
796801
def test_volume_set_note(self, set_note):
797802
set_note.return_value = True

tests/managers/ordering_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,11 @@ def test_issues1425_nonzeroterm(self):
893893
# Test None-existing price for term
894894
price_id = self.ordering.get_item_price_id("8", [price2, price1], 37)
895895
self.assertEqual(None, price_id)
896+
897+
def test_get_items(self):
898+
self.ordering.get_items(123)
899+
self.assert_called_with('SoftLayer_Product_Package', 'getItems')
900+
901+
def test_get_regions(self):
902+
self.ordering.get_regions(123)
903+
self.assert_called_with('SoftLayer_Product_Package', 'getRegions')

0 commit comments

Comments
 (0)