Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion SoftLayer/CLI/hardware/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def _bw_table(bw_data):
allotment = 'N/A'
if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
bw_type = 'Public'
allotment = bw_data['allotment'].get('amount', '-')
allotment = utils.lookup(bw_data, 'allotment', 'amount')
if allotment is None:
allotment = '-'

table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
return table
4 changes: 3 additions & 1 deletion SoftLayer/CLI/virt/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def _bw_table(bw_data):
allotment = 'N/A'
if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
bw_type = 'Public'
allotment = bw_data['allotment'].get('amount', '-')
allotment = utils.lookup(bw_data, 'allotment', 'amount')
if allotment is None:
allotment = '-'

table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
return table
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def get_bandwidth_allocation(self, instance_id):
allotment = self.client.call('Hardware_Server', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
u_mask = "mask[amountIn,amountOut,type]"
useage = self.client.call('Hardware_Server', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
return {'allotment': allotment['allocation'], 'useage': useage}
return {'allotment': allotment.get('allocation'), 'useage': useage}


def _get_extra_price_id(items, key_name, hourly, location):
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/managers/vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ def get_bandwidth_allocation(self, instance_id):
allotment = self.client.call('Virtual_Guest', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
u_mask = "mask[amountIn,amountOut,type]"
useage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
return {'allotment': allotment['allocation'], 'useage': useage}
return {'allotment': allotment.get('allocation'), 'useage': useage}

# pylint: disable=inconsistent-return-statements
def _get_price_id_for_upgrade(self, package_items, option, value, public=True):
Expand Down
8 changes: 8 additions & 0 deletions tests/managers/hardware_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ def test_get_bandwidth_allocation(self):
self.assertEqual(result['allotment']['amount'], '250')
self.assertEqual(result['useage'][0]['amountIn'], '.448')

def test_get_bandwidth_allocation_no_allotment(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getBandwidthAllotmentDetail')
mock.return_value = {}

result = self.hardware.get_bandwidth_allocation(1234)

self.assertEqual(None, result['allotment'])


class HardwareHelperTests(testing.TestCase):
def test_get_extra_price_id_no_items(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/managers/vs/vs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,11 @@ def test_get_bandwidth_allocation(self):
self.assert_called_with('SoftLayer_Virtual_Guest', 'getBillingCycleBandwidthUsage', identifier=1234)
self.assertEqual(result['allotment']['amount'], '250')
self.assertEqual(result['useage'][0]['amountIn'], '.448')

def test_get_bandwidth_allocation_no_allotment(self):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
mock.return_value = {}

result = self.vs.get_bandwidth_allocation(1234)

self.assertEqual(None, result['allotment'])