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
7 changes: 4 additions & 3 deletions SoftLayer/CLI/virt/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ def cli(env, identifier, passwords=False, price=False):
def _bw_table(bw_data):
"""Generates a bandwidth useage table"""
table = formatting.Table(['Type', 'In GB', 'Out GB', 'Allotment'])
for bw_point in bw_data.get('useage'):
for bw_point in bw_data.get('usage'):
bw_type = 'Private'
allotment = 'N/A'
if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
bw_type = 'Public'
allotment = utils.lookup(bw_data, 'allotment', 'amount')
if allotment is None:
if not bw_data.get('allotment'):
allotment = '-'
else:
allotment = utils.lookup(bw_data, 'allotment', 'amount')

table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
return table
Expand Down
6 changes: 4 additions & 2 deletions SoftLayer/managers/vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,10 @@ def get_bandwidth_allocation(self, instance_id):
a_mask = "mask[allocation[amount]]"
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.get('allocation'), 'useage': useage}
usage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
if allotment:
return {'allotment': allotment.get('allocation'), 'usage': usage}
return {'allotment': allotment, 'usage': usage}

# pylint: disable=inconsistent-return-statements
def _get_price_id_for_upgrade(self, package_items, option, value, public=True):
Expand Down
11 changes: 11 additions & 0 deletions tests/CLI/modules/vs/vs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ def test_detail_vs_empty_tag(self):
['example-tag'],
)

def test_detail_vs_empty_allotment(self):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
mock.return_value = None
result = self.run_command(['vs', 'detail', '100'])

self.assert_no_fail(result)
self.assertEqual(
json.loads(result.output)['Bandwidth'][0]['Allotment'],
'-',
)

def test_detail_vs_dedicated_host_not_found(self):
ex = SoftLayerAPIError('SoftLayer_Exception', 'Not found')
mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
Expand Down
18 changes: 16 additions & 2 deletions tests/managers/vs/vs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,26 @@ def test_get_bandwidth_allocation(self):
self.assert_called_with('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail', identifier=1234)
self.assert_called_with('SoftLayer_Virtual_Guest', 'getBillingCycleBandwidthUsage', identifier=1234)
self.assertEqual(result['allotment']['amount'], '250')
self.assertEqual(result['useage'][0]['amountIn'], '.448')
self.assertEqual(result['usage'][0]['amountIn'], '.448')

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

result = self.vs.get_bandwidth_allocation(1234)

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

def test_get_bandwidth_allocation_with_allotment(self):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
mock.return_value = {
"allocationId": 11111,
"id": 22222,
"allocation": {
"amount": "2000"
}
}

result = self.vs.get_bandwidth_allocation(1234)

self.assertEqual(2000, int(result['allotment']['amount']))