Skip to content

Commit 98222e0

Browse files
caberoscaberos
authored andcommitted
fix the team code review comments
1 parent 989bd3d commit 98222e0

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

SoftLayer/CLI/file/options.py

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,43 @@
88
from SoftLayer.CLI import environment
99
from SoftLayer.CLI import formatting
1010

11-
volume_size = ['20', '40', '80', '100', '250', '500', '1000', '2000-3000', '4000-7000', '8000-9000', '10000-12000']
11+
12+
PACKAGE_STORAGE = 759
1213

1314

1415
@click.command(cls=SLCommand)
1516
@environment.pass_env
1617
def cli(env):
1718
"""List all options for ordering a file storage"""
1819

19-
network_manager = SoftLayer.NetworkManager(env.client)
20-
datacenters = network_manager.get_datacenter()
21-
22-
table = formatting.Table(['Name', 'Value'], title='Volume table')
23-
24-
table.add_row(['Storage Type', 'performance,endurance'])
25-
table.add_row(['Size (GB)', str(volume_size)])
26-
27-
iops_table = formatting.Table(['Size (GB)', '20', '40', '80', '100', '250', '500', '1000', '2000-3000',
28-
'4000-7000', '8000-9000', '10000-12000'], title='IOPS table')
29-
snapshot_table = formatting.Table(['Storage Size (GB)', 'Available Snapshot Size (GB)'], title="Snapshot table")
30-
31-
datacenter_str = ','.join([str(dc['longName']) for dc in datacenters])
32-
iops_table.add_row(['Size (GB)', *volume_size])
33-
iops_table.add_row(['Min IOPS', '100', '100', '100', '100', '100', '100', '100', '200', '300', '500', '1000'])
34-
iops_table.add_row(['Max IOPS', '1000', '2000', '4000', '6000', '6000', '6000 or 10000', '6000 or 20000',
35-
'6000 or 40000', '6000 or 48000', '6000 or 48000', '6000 or 48000'])
36-
# table.add_row(['iops', iops_table])
37-
table.add_row(['Tier', '0.25,2,4,10'])
38-
table.add_row(['location', datacenter_str])
39-
40-
snapshot_table.add_row(['20', '0,5,10,20'])
41-
snapshot_table.add_row(['40', '0,5,10,20,40'])
42-
snapshot_table.add_row(['80', '0,5,10,20,40,60,80'])
43-
snapshot_table.add_row(['100', '0,5,10,20,40,60,80,100'])
44-
snapshot_table.add_row(['250', '0,5,10,20,40,60,80,100,150,200,250'])
45-
snapshot_table.add_row(['500', '0,5,10,20,40,60,80,100,150,200,250,300,350,400,450,500'])
46-
snapshot_table.add_row(['1000', '0,5,10,20,40,60,80,100,150,200,250,300,350,400,450,500,600,700,1000'])
47-
snapshot_table.add_row(['2000-3000', '0,5,10,20,40,60,80,100,150,200,250,300,350,400,450,500,600,700,1000,2000'])
48-
snapshot_table.add_row(
49-
['4000-7000', '0,5,10,20,40,60,80,100,150,200,250,300,350,400,450,500,600,700,1000,2000,4000'])
50-
snapshot_table.add_row(
51-
['8000-9000', '0,5,10,20,40,60,80,100,150,200,250,300,350,400,450,500,600,700,1000,2000,4000'])
52-
snapshot_table.add_row(
53-
['10000-12000', '0,5,10,20,40,60,80,100,150,200,250,300,350,400,450,500,600,700,1000,2000,4000'])
54-
55-
# table.add_row(['Snapshot Size (GB)', snapshot_table])
56-
table.add_row(['Note:',
57-
'IOPs limit above 6000 available in select data centers, refer to:'
58-
'http://knowledgelayer.softlayer.com/articles/new-ibm-block-and-file-storage-location-and-features'])
59-
env.fout(table)
20+
order_manager = SoftLayer.OrderingManager(env.client)
21+
items = order_manager.get_items(PACKAGE_STORAGE)
22+
datacenters = order_manager.get_regions(PACKAGE_STORAGE)
23+
24+
iops_table = formatting.Table(['Id', 'Description', 'KeyName'], title='IOPS')
25+
snapshot_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Snapshot')
26+
storage_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Storage')
27+
datacenter_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Datacenter')
28+
29+
for datacenter in datacenters:
30+
datacenter_table.add_row([datacenter['location']['locationId'],
31+
datacenter.get('description'),
32+
datacenter['keyname']])
33+
34+
for item in items:
35+
if item['itemCategory']['categoryCode'] == 'performance_storage_space':
36+
storage_table.add_row([item.get('id'), item.get('description'),
37+
item.get('keyName')])
38+
39+
if item['itemCategory']['categoryCode'] == 'storage_tier_level':
40+
iops_table.add_row([item.get('id'), item.get('description'),
41+
item.get('keyName')])
42+
43+
if item['itemCategory']['categoryCode'] == 'storage_snapshot_space':
44+
snapshot_table.add_row([item.get('id'), item.get('description'),
45+
item.get('keyName')])
46+
47+
env.fout(datacenter_table)
6048
env.fout(iops_table)
49+
env.fout(storage_table)
6150
env.fout(snapshot_table)

SoftLayer/managers/ordering.py

Lines changed: 19 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,22 @@ 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+
735+
:param int package_id: The package for which to get the items.
736+
"""
737+
return self.client.call('SoftLayer_Product_Package', 'getRegions', id=package_id)

tests/managers/ordering_tests.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ def test_get_item_capacity_core(self):
744744
"capacity": "1",
745745
"id": 10201,
746746
"keyName": "GUEST_CORE_1_DEDICATED",
747-
}]
747+
}]
748748

749749
item_capacity = self.ordering.get_item_capacity(items, ['GUEST_CORE_1_DEDICATED', 'OS_RHEL_7_X_LAMP_64_BIT'])
750750

@@ -761,7 +761,7 @@ def test_get_item_capacity_storage(self):
761761
"capacity": "1",
762762
"id": 10201,
763763
"keyName": "READHEAVY_TIER",
764-
}]
764+
}]
765765

766766
item_capacity = self.ordering.get_item_capacity(items, ['READHEAVY_TIER', 'STORAGE_SPACE_FOR_2_IOPS_PER_GB'])
767767

@@ -779,7 +779,7 @@ def test_get_item_capacity_intel(self):
779779
"capacity": "1",
780780
"id": 10201,
781781
"keyName": "GUEST_CORE_1_DEDICATED",
782-
}]
782+
}]
783783

784784
item_capacity = self.ordering.get_item_capacity(items, ['INTEL_XEON_2690_2_60', 'BANDWIDTH_20000_GB'])
785785

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