Skip to content

Commit 18ecf58

Browse files
Merge pull request #1865 from allmightyspiff/issues1864
fixed an issue showing block/file snapshot prices
2 parents 742bc6a + 08aed9f commit 18ecf58

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

SoftLayer/API.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(self, auth=None, transport=None, config_file=None):
177177
endpoint_url=url,
178178
proxy=self.settings['softlayer'].get('proxy'),
179179
# prevents an exception incase timeout is a float number.
180-
timeout=int(self.settings['softlayer'].getfloat('timeout')),
180+
timeout=int(self.settings['softlayer'].getfloat('timeout', 0)),
181181
user_agent=consts.USER_AGENT,
182182
verify=self.settings['softlayer'].getboolean('verify'),
183183
)
@@ -186,7 +186,7 @@ def __init__(self, auth=None, transport=None, config_file=None):
186186
transport = transports.XmlRpcTransport(
187187
endpoint_url=url,
188188
proxy=self.settings['softlayer'].get('proxy'),
189-
timeout=int(self.settings['softlayer'].getfloat('timeout')),
189+
timeout=int(self.settings['softlayer'].getfloat('timeout', 0)),
190190
user_agent=consts.USER_AGENT,
191191
verify=self.settings['softlayer'].getboolean('verify'),
192192
)

SoftLayer/CLI/block/options.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def cli(env, prices, location=None):
2222
"""List all options for ordering a block storage"""
2323

2424
order_manager = SoftLayer.OrderingManager(env.client)
25-
items = order_manager.get_items(PACKAGE_STORAGE)
25+
items = order_manager.get_items(PACKAGE_STORAGE, mask="mask[categories]")
2626
datacenters = order_manager.get_regions(PACKAGE_STORAGE, location)
2727

2828
tables = []
@@ -67,7 +67,7 @@ def _block_ios_get_table(items, prices):
6767
if block_item['itemCategory']['categoryCode'] == 'storage_tier_level':
6868
table.add_row([block_item.get('id'), block_item.get('description'),
6969
block_item.get('keyName')])
70-
table.sortby = 'Id'
70+
table.sortby = 'KeyName'
7171
table.align = 'l'
7272
return table
7373

@@ -86,7 +86,7 @@ def _block_storage_table(items, prices):
8686
if block_item['itemCategory']['categoryCode'] == 'performance_storage_space':
8787
table.add_row([block_item.get('id'), block_item.get('description'),
8888
block_item.get('keyName'), block_item.get('capacityMinimum') or '-', ])
89-
table.sortby = 'Id'
89+
table.sortby = 'KeyName'
9090
table.align = 'l'
9191
return table
9292

@@ -101,9 +101,16 @@ def _block_snapshot_get_table(items, prices):
101101
else:
102102
table = formatting.Table(['Id', 'Description', 'KeyName'], title='Snapshot')
103103
for block_item in items:
104-
if block_item['itemCategory']['categoryCode'] == 'storage_snapshot_space':
105-
table.add_row([block_item.get('id'), block_item.get('description'),
106-
block_item.get('keyName')])
107-
table.sortby = 'Id'
104+
if is_snapshot_category(block_item.get('categories', [])):
105+
table.add_row([block_item.get('id'), block_item.get('description'), block_item.get('keyName')])
106+
table.sortby = 'KeyName'
108107
table.align = 'l'
109108
return table
109+
110+
111+
def is_snapshot_category(categories):
112+
"""Checks if storage_snapshot_space is one of the categories"""
113+
for item in categories:
114+
if item.get('categoryCode') == "storage_snapshot_space":
115+
return True
116+
return False

SoftLayer/managers/ordering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def resolve_location_name(self, location_key):
717717
return location_name
718718
raise exceptions.SoftLayerError("Location {} does not exist".format(location_key))
719719

720-
def get_items(self, package_id, storage_filter=None):
720+
def get_items(self, package_id, storage_filter=None, mask=None):
721721
""""Returns the items .
722722
723723
@@ -726,7 +726,7 @@ def get_items(self, package_id, storage_filter=None):
726726
"""
727727

728728
return self.client.call('SoftLayer_Product_Package', 'getItems', filter=storage_filter,
729-
id=package_id)
729+
id=package_id, mask=mask)
730730

731731
def get_regions(self, package_id, location=None):
732732
"""returns the all regions.

tests/CLI/modules/config_tests.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,21 @@ def set_up(self):
3131
def test_show(self):
3232
result = self.run_command(['config', 'show'])
3333
self.assert_no_fail(result)
34-
self.assertEqual(json.loads(result.output),
35-
{'Username': 'username',
36-
'API Key': 'api-key',
37-
'Endpoint URL': 'http://endpoint-url',
38-
'Timeout': 'not set',
39-
'Theme': 'dark'})
34+
default_config = {
35+
'Username': 'username',
36+
'API Key': 'api-key',
37+
'Endpoint URL': 'http://endpoint-url',
38+
'Timeout': 'not set',
39+
'Theme': 'dark'
40+
}
41+
result_config = json.loads(result.output)
42+
43+
self.assertEqual(result_config.get('Username'), default_config.get('Username'))
44+
self.assertEqual(result_config.get('API Key'), default_config.get('API Key'))
45+
self.assertEqual(result_config.get('Endpoint URL'), default_config.get('Endpoint URL'))
46+
self.assertEqual(result_config.get('Timeout'), default_config.get('Timeout'))
47+
# Could be either theme since were not setting it in this test
48+
self.assertIn(result_config.get('Theme'), ['dark', 'light'])
4049

4150

4251
class TestHelpSetup(testing.TestCase):

0 commit comments

Comments
 (0)