Skip to content

Commit 0a5af09

Browse files
Merge pull request #1963 from edsonarios/issue1961
Group bandwidth commands
2 parents 17aa0d2 + afd8c87 commit 0a5af09

File tree

11 files changed

+264
-221
lines changed

11 files changed

+264
-221
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Bandwidth."""
2+
# :license: MIT, see LICENSE for more details.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Displays information about the accounts bandwidth pools"""
1+
"""Displays information about the bandwidth pools"""
22
# :license: MIT, see LICENSE for more details.
33
import click
44

@@ -15,6 +15,9 @@ def cli(env):
1515
"""Displays bandwidth pool information
1616
1717
Similiar to https://cloud.ibm.com/classic-bandwidth/pools
18+
19+
More information
20+
https://cloud.ibm.com/docs/bandwidth-metering?topic=bandwidth-metering-get-started-with-bandwidth-metering
1821
"""
1922

2023
manager = AccountManager(env.client)

SoftLayer/CLI/account/bandwidth_pools_detail.py renamed to SoftLayer/CLI/bandwidth/pools_detail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Get bandwidth pools."""
1+
"""Get bandwidth pool details."""
22
# :license: MIT, see LICENSE for more details.
33
import click
44

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Bandwidth report for every pool/server."""
1+
"""Bandwidth summary for every pool/server."""
22
import click
33

44
from SoftLayer.CLI.command import SLCommand as SLCommand
@@ -7,14 +7,17 @@
77
from SoftLayer import utils
88

99

10-
@click.command(cls=SLCommand, short_help="Bandwidth report for every pool/server")
10+
@click.command(cls=SLCommand, short_help="Bandwidth summary for every pool/server")
1111
@environment.pass_env
1212
def cli(env):
13-
"""Bandwidth report for every pool/server.
13+
"""Bandwidth summary for every pool/server.
1414
15-
This reports on the total data transfered for each virtual sever, hardware
15+
This summary on the total data transfered for each virtual sever, hardware
1616
server and bandwidth pool.
1717
https://cloud.ibm.com/classic-bandwidth
18+
19+
More information
20+
https://cloud.ibm.com/docs/bandwidth-metering?topic=bandwidth-metering-get-started-with-bandwidth-metering
1821
"""
1922

2023
table = formatting.Table([

SoftLayer/CLI/routes.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
('account:invoice-detail', 'SoftLayer.CLI.account.invoice_detail:cli'),
1616
('account:invoices', 'SoftLayer.CLI.account.invoices:cli'),
1717
('account:events', 'SoftLayer.CLI.account.events:cli'),
18-
('account:bandwidth-pools-detail', 'SoftLayer.CLI.account.bandwidth_pools_detail:cli'),
18+
('account:bandwidth-pools-detail', 'SoftLayer.CLI.bandwidth.pools_detail:cli'),
1919
('account:event-detail', 'SoftLayer.CLI.account.event_detail:cli'),
2020
('account:licenses', 'SoftLayer.CLI.account.licenses:cli'),
2121
('account:summary', 'SoftLayer.CLI.account.summary:cli'),
2222
('account:billing-items', 'SoftLayer.CLI.account.billing_items:cli'),
2323
('account:item-detail', 'SoftLayer.CLI.account.item_detail:cli'),
2424
('account:cancel-item', 'SoftLayer.CLI.account.cancel_item:cli'),
2525
('account:orders', 'SoftLayer.CLI.account.orders:cli'),
26-
('account:bandwidth-pools', 'SoftLayer.CLI.account.bandwidth_pools:cli'),
26+
('account:bandwidth-pools', 'SoftLayer.CLI.bandwidth.pools:cli'),
2727
('account:hooks', 'SoftLayer.CLI.account.hooks:cli'),
2828
('account:hook-create', 'SoftLayer.CLI.account.hook_create:cli'),
2929
('account:hook-delete', 'SoftLayer.CLI.account.hook_delete:cli'),
@@ -417,8 +417,13 @@
417417
('search', 'SoftLayer.CLI.search:cli'),
418418

419419
('report', 'SoftLayer.CLI.report'),
420-
('report:bandwidth', 'SoftLayer.CLI.report.bandwidth:cli'),
420+
('report:bandwidth', 'SoftLayer.CLI.bandwidth.summary:cli'),
421421
('report:datacenter-closures', 'SoftLayer.CLI.report.dc_closures:cli'),
422+
423+
('bandwidth', 'SoftLayer.CLI.bandwidth'),
424+
('bandwidth:summary', 'SoftLayer.CLI.bandwidth.summary:cli'),
425+
('bandwidth:pools', 'SoftLayer.CLI.bandwidth.pools:cli'),
426+
('bandwidth:pools-detail', 'SoftLayer.CLI.bandwidth.pools_detail:cli'),
422427
]
423428

424429
ALL_ALIASES = {

docs/cli/account.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ Account Commands
4444
:prog: account licenses
4545
:show-nested:
4646

47-
.. click:: SoftLayer.CLI.account.bandwidth_pools:cli
47+
.. click:: SoftLayer.CLI.bandwidth.pools:cli
4848
:prog: account bandwidth-pools
4949
:show-nested:
5050

51-
.. click:: SoftLayer.CLI.account.bandwidth_pools_detail:cli
51+
.. click:: SoftLayer.CLI.bandwidth.pools_detail:cli
5252
:prog: account bandwidth-pools-detail
5353
:show-nested:
5454

docs/cli/bandwidth.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _cli_account:
2+
3+
bandwidth Commands
4+
=================
5+
6+
7+
.. click:: SoftLayer.CLI.bandwidth.pools:cli
8+
:prog: bandwidth pools
9+
:show-nested:
10+
11+
.. click:: SoftLayer.CLI.bandwidth.pools_detail:cli
12+
:prog: bandwidth pools-detail
13+
:show-nested:
14+
15+
.. click:: SoftLayer.CLI.bandwidth.summary:cli
16+
:prog: bandwidth summary
17+
:show-nested:

docs/cli/reports.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ There are a few report type commands in the SLCLI.
1515
A list of datacenters, and how many servers, VSI, vlans, subnets and public_ips are in each.
1616

1717

18-
.. click:: SoftLayer.CLI.report.bandwidth:cli
18+
.. click:: SoftLayer.CLI.bandwidth.summary:cli
1919
:prog: report bandwidth
2020
:show-nested:
2121

tests/CLI/modules/account_tests.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,6 @@ def test_acccount_licenses(self):
165165
self.assert_called_with('SoftLayer_Account', 'getActiveVirtualLicenses')
166166
self.assert_called_with('SoftLayer_Account', 'getActiveAccountLicenses')
167167

168-
def test_bandwidth_pools(self):
169-
result = self.run_command(['account', 'bandwidth-pools'])
170-
self.assert_no_fail(result)
171-
self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments')
172-
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')
173-
174-
def test_acccount_bandwidth_pool_detail(self):
175-
result = self.run_command(['account', 'bandwidth-pools-detail', '123456'])
176-
self.assert_no_fail(result)
177-
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')
178-
179168
def test_acccount_provisioning_hook(self):
180169
result = self.run_command(['account', 'hooks'])
181170
self.assert_no_fail(result)
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
"""
2+
SoftLayer.tests.CLI.modules.bandwidth_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
:license: MIT, see LICENSE for more details.
6+
"""
7+
from SoftLayer import testing
8+
9+
import json
10+
11+
from pprint import pprint as pp
12+
13+
14+
class BandwidthTests(testing.TestCase):
15+
def test_bandwidth_pools(self):
16+
result = self.run_command(['bandwidth', 'pools'])
17+
self.assert_no_fail(result)
18+
self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments')
19+
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')
20+
21+
def test_acccount_bandwidth_pool_detail(self):
22+
result = self.run_command(['bandwidth', 'pools-detail', '123456'])
23+
self.assert_no_fail(result)
24+
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')
25+
26+
def test_bandwidth_summary(self):
27+
search_mock = self.set_mock('SoftLayer_Search', 'advancedSearch')
28+
search_mock.side_effect = [_bandwidth_advanced_search(), [], [], []]
29+
result = self.run_command(['bandwidth', 'summary'])
30+
31+
self.assert_no_fail(result)
32+
self.assert_called_with('SoftLayer_Search', 'advancedSearch')
33+
json_output = json.loads(result.output)
34+
pp(json_output)
35+
self.assertEqual(5, len(json_output))
36+
self.assertEqual(100250634, json_output[0]['Id'])
37+
self.assertEqual('TestRegion', json_output[0]['Pool'])
38+
self.assertEqual('dal10', json_output[0]['Location'])
39+
self.assertEqual(['tag test', 'tag test2'], json_output[0]['Tags'])
40+
self.assertEqual('Virtual Private Rack', json_output[1]['Pool'])
41+
self.assertEqual('1.04 GB', json_output[2]['Total usage'])
42+
self.assertEqual('5.00 TB', json_output[2]['Allocation'])
43+
self.assertEqual('Unlimited', json_output[3]['Allocation'])
44+
self.assertEqual('Not Applicable', json_output[3]['Pool'])
45+
self.assertEqual('0.00 MB', json_output[3]['Data in'])
46+
self.assertEqual('0.00 MB', json_output[3]['Data out'])
47+
self.assertEqual('Pay-As-You-Go', json_output[4]['Allocation'])
48+
49+
50+
def _bandwidth_advanced_search():
51+
result = [
52+
{
53+
"matchedTerms": [],
54+
"relevanceScore": "1",
55+
"resource": {
56+
"fullyQualifiedDomainName": "test.com",
57+
"id": 100250634,
58+
"bandwidthAllocation": "250",
59+
"bandwidthAllotmentDetail": {
60+
"id": 53306635,
61+
"bandwidthAllotment": {
62+
"bandwidthAllotmentTypeId": 2,
63+
"id": 1289128,
64+
"name": "TestRegion"
65+
}
66+
},
67+
"billingItem": {
68+
"createDate": "2022-03-07T05:28:44-06:00",
69+
"id": 937460400,
70+
"lastBillDate": "2023-05-03T23:07:54-06:00"
71+
},
72+
"datacenter": {
73+
"id": 1441195,
74+
"name": "dal10"
75+
},
76+
"inboundPublicBandwidthUsage": ".16204",
77+
"outboundPublicBandwidthUsage": ".01351",
78+
"primaryIpAddress": "169.46.48.110",
79+
"tagReferences": [
80+
{
81+
"id": 172236920,
82+
"tag": {
83+
"id": 3414982,
84+
"name": "tag test"
85+
}
86+
},
87+
{
88+
"id": 172236918,
89+
"tag": {
90+
"id": 3307656,
91+
"name": "tag test2"
92+
}
93+
}
94+
]
95+
},
96+
"resourceType": "SoftLayer_Virtual_Guest"
97+
},
98+
{
99+
"matchedTerms": [],
100+
"relevanceScore": "1",
101+
"resource": {
102+
"fullyQualifiedDomainName": "test.cloud",
103+
"id": 1867001,
104+
"bandwidthAllocation": "20000",
105+
"bandwidthAllotmentDetail": {
106+
"id": 37331756,
107+
"bandwidthAllotment": {
108+
"bandwidthAllotmentTypeId": 1,
109+
"id": 138442,
110+
"name": "Virtual Private Rack"
111+
}
112+
},
113+
"billingItem": {
114+
"createDate": "2020-04-27T14:02:03-06:00",
115+
"id": 658642904,
116+
"lastBillDate": "2023-05-03T23:07:47-06:00"
117+
},
118+
"datacenter": {
119+
"id": 1441195,
120+
"name": "dal10"
121+
},
122+
"inboundPublicBandwidthUsage": ".48562",
123+
"outboundPublicBandwidthUsage": ".1987",
124+
"primaryIpAddress": "169.48.191.246",
125+
"tagReferences": [
126+
{
127+
"id": 1060153378,
128+
"tag": {
129+
"id": 4974546,
130+
"name": "tags"
131+
}
132+
}
133+
]
134+
},
135+
"resourceType": "SoftLayer_Hardware"
136+
},
137+
{
138+
"matchedTerms": [],
139+
"relevanceScore": "1",
140+
"resource": {
141+
"fullyQualifiedDomainName": "testcommunity.cloud",
142+
"id": 3190740,
143+
"bandwidthAllocation": "5000",
144+
"bandwidthAllotmentDetail": {
145+
"id": 50932574,
146+
"bandwidthAllotment": {
147+
"bandwidthAllotmentTypeId": 1,
148+
"id": 138442,
149+
"name": "Virtual Private Rack"
150+
}
151+
},
152+
"billingItem": {
153+
"createDate": "2022-08-11T11:39:55-06:00",
154+
"id": 983649084,
155+
"lastBillDate": "2023-05-03T23:07:48-06:00"
156+
},
157+
"datacenter": {
158+
"id": 1441195,
159+
"name": "dal10"
160+
},
161+
"inboundPublicBandwidthUsage": ".63179",
162+
"outboundPublicBandwidthUsage": ".40786",
163+
"primaryIpAddress": "52.118.38.243",
164+
"tagReferences": []
165+
},
166+
"resourceType": "SoftLayer_Hardware"
167+
},
168+
{
169+
"matchedTerms": [],
170+
"relevanceScore": "1",
171+
"resource": {
172+
"id": 47758,
173+
"name": "SLADC307608-jt48",
174+
"billingItem": {
175+
"createDate": "2022-02-11T09:49:16-06:00",
176+
"id": 931026566,
177+
"lastBillDate": "2023-05-03T23:08:02-06:00"
178+
},
179+
"datacenter": {
180+
"id": 2017603,
181+
"name": "wdc07"
182+
},
183+
"primaryIpAddress": "169.62.12.146",
184+
"tagReferences": []
185+
},
186+
"resourceType": "SoftLayer_Network_Application_Delivery_Controller"
187+
},
188+
{
189+
"matchedTerms": [],
190+
"relevanceScore": "1",
191+
"resource": {
192+
"fullyQualifiedDomainName": "lab-web.test.com",
193+
"id": 127890106,
194+
"bandwidthAllocation": "0",
195+
"bandwidthAllotmentDetail": {
196+
"id": 48915580,
197+
"bandwidthAllotment": {
198+
"bandwidthAllotmentTypeId": 1,
199+
"id": 138442,
200+
"name": "Virtual Private Rack"
201+
}
202+
},
203+
"billingItem": {
204+
"createDate": "2022-02-08T08:33:14-06:00",
205+
"id": 930164384,
206+
"lastBillDate": "2023-05-03T23:07:56-06:00"
207+
},
208+
"datacenter": {
209+
"id": 138124,
210+
"name": "dal05"
211+
},
212+
"inboundPrivateBandwidthUsage": ".00002",
213+
"inboundPublicBandwidthUsage": ".19583",
214+
"outboundPrivateBandwidthUsage": ".00002",
215+
"outboundPublicBandwidthUsage": ".18446",
216+
"primaryIpAddress": "108.168.148.26",
217+
"tagReferences": []
218+
},
219+
"resourceType": "SoftLayer_Virtual_Guest"
220+
}
221+
]
222+
return result

0 commit comments

Comments
 (0)