Skip to content

Commit e02e684

Browse files
author
Brian Flores
committed
update report bandwidth command and its unit tests
1 parent 182c390 commit e02e684

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

SoftLayer/CLI/report/bandwidth.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,27 @@ def _get_pooled_bandwidth(env, start, end):
4848
label='Calculating for bandwidth pools',
4949
file=sys.stderr) as pools:
5050
for pool in pools:
51+
metric_tracking_id = pool.get('metricTrackingObjectId')
52+
53+
if metric_tracking_id is None:
54+
continue
55+
5156
pool_detail = {
5257
'id': pool.get('id'),
5358
'type': 'pool',
5459
'name': pool.get('name'),
5560
'data': []
5661
}
57-
if pool.get('metricTrackingObjectId'):
58-
bw_data = env.client.call(
59-
'Metric_Tracking_Object',
60-
'getSummaryData',
61-
start.strftime('%Y-%m-%d %H:%M:%S %Z'),
62-
end.strftime('%Y-%m-%d %H:%M:%S %Z'),
63-
types,
64-
300,
65-
id=pool.get('metricTrackingObjectId'),
66-
)
67-
pool_detail['data'] = bw_data
62+
bw_data = env.client.call(
63+
'Metric_Tracking_Object',
64+
'getSummaryData',
65+
start.strftime('%Y-%m-%d %H:%M:%S %Z'),
66+
end.strftime('%Y-%m-%d %H:%M:%S %Z'),
67+
types,
68+
300,
69+
id=metric_tracking_id,
70+
)
71+
pool_detail['data'] = bw_data
6872

6973
yield pool_detail
7074

@@ -74,7 +78,7 @@ def _get_hardware_bandwidth(env, start, end):
7478
'Account', 'getHardware',
7579
iter=True,
7680
mask='id,hostname,metricTrackingObject.id,'
77-
'virtualRack[id,bandwidthAllotmentTypeId]')
81+
'virtualRack[id,bandwidthAllotmentTypeId,name]')
7882
types = [
7983
{'keyName': 'PUBLICIN',
8084
'name': 'publicIn',
@@ -125,7 +129,7 @@ def _get_virtual_bandwidth(env, start, end):
125129
'Account', 'getVirtualGuests',
126130
iter=True,
127131
mask='id,hostname,metricTrackingObjectId,'
128-
'virtualRack[id,bandwidthAllotmentTypeId]')
132+
'virtualRack[id,bandwidthAllotmentTypeId,name]')
129133
types = [
130134
{'keyName': 'PUBLICIN_NET_OCTET',
131135
'name': 'publicIn_net_octet',
@@ -155,7 +159,7 @@ def _get_virtual_bandwidth(env, start, end):
155159
if utils.lookup(instance,
156160
'virtualRack',
157161
'bandwidthAllotmentTypeId') == 2:
158-
pool_name = utils.lookup(instance, 'virtualRack', 'id')
162+
pool_name = utils.lookup(instance, 'virtualRack', 'name')
159163

160164
yield {
161165
'id': instance['id'],

tests/CLI/modules/report_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_virtual_bandwidth_report(self):
183183
stripped_output = '[' + result.output.split('[', 1)[1]
184184
json_output = json.loads(stripped_output)
185185
self.assertEqual(json_output[0]['hostname'], 'pool1')
186-
self.assertEqual(json_output[1]['private_in'], 0)
186+
self.assertEqual(json_output[1]['private_out'], 40)
187187
self.assertEqual(json_output[2]['private_in'], 30)
188188
self.assertEqual(json_output[3]['type'], 'virtual')
189189

@@ -266,7 +266,7 @@ def test_server_bandwidth_report(self):
266266
stripped_output = '[' + result.output.split('[', 1)[1]
267267
json_output = json.loads(stripped_output)
268268
self.assertEqual(json_output[0]['hostname'], 'pool1')
269-
self.assertEqual(json_output[1]['private_in'], 0)
269+
self.assertEqual(json_output[1]['private_out'], 40)
270270
self.assertEqual(json_output[2]['private_in'], 30)
271271
self.assertEqual(json_output[3]['type'], 'hardware')
272272

0 commit comments

Comments
 (0)