Skip to content

Commit fd579dd

Browse files
caberoscaberos
authored andcommitted
Bandwidth pool management
1 parent cdef7d6 commit fd579dd

File tree

6 files changed

+232
-0
lines changed

6 files changed

+232
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Get bandwidth pools."""
2+
# :license: MIT, see LICENSE for more details.
3+
import click
4+
5+
from SoftLayer import AccountManager
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
from SoftLayer import utils
9+
10+
11+
@click.command()
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Get bandwidth about a VLAN."""
16+
17+
manager = AccountManager(env.client)
18+
bandwidths = manager.getBandwidthDetail(identifier)
19+
20+
table = formatting.KeyValueTable(['name', 'value'])
21+
table.align['name'] = 'r'
22+
table.align['value'] = 'l'
23+
table.add_row(['Id', bandwidths['id']])
24+
table.add_row(['Name', bandwidths['name']])
25+
table.add_row(['Create Date', bandwidths['createDate']])
26+
table.add_row(['Current Usage', bandwidths['billingCyclePublicBandwidthUsage']['amountOut']])
27+
table.add_row(['Projected Usage', bandwidths['projectedPublicBandwidthUsage']])
28+
table.add_row(['Inbound Usage', bandwidths['inboundPublicBandwidthUsage']])
29+
if bandwidths['hardware'] != []:
30+
table.add_row(['hardware', _bw_table(bandwidths['hardware'])])
31+
else:
32+
table.add_row(['hardware', 'not found'])
33+
34+
if bandwidths['virtualGuests'] != []:
35+
table.add_row(['virtualGuests', _virtual_table(bandwidths['virtualGuests'])])
36+
else:
37+
table.add_row(['virtualGuests', 'Not Found'])
38+
39+
if bandwidths['bareMetalInstances'] != []:
40+
table.add_row(['Netscale', _bw_table(bandwidths['bareMetalInstances'])])
41+
else:
42+
table.add_row(['Netscale', 'Not Found'])
43+
44+
env.fout(table)
45+
46+
47+
def _bw_table(bw_data):
48+
"""Generates a bandwidth useage table"""
49+
table_data = formatting.Table(['Id', 'HostName', "IP Address", 'Amount', "Current Usage"])
50+
for bw_point in bw_data:
51+
amount = bw_point['bandwidthAllotmentDetail']['allocation']['amount']
52+
current = utils.lookup(bw_point, 'outboundBandwidthUsage')
53+
ip_address = bw_point['primaryIpAddress']
54+
table_data.add_row([bw_point['id'], bw_point['fullyQualifiedDomainName'], ip_address, amount, current])
55+
return [table_data]
56+
57+
58+
def _virtual_table(bw_data):
59+
"""Generates a virtual bandwidth usage table"""
60+
table_data = formatting.Table(['Id', 'HostName', "IP Address", 'Amount', "Current Usage"])
61+
for bw_point in bw_data:
62+
amount = bw_point['bandwidthAllotmentDetail']['allocation']['amount']
63+
current = utils.lookup(bw_point, 'outboundPublicBandwidthUsage')
64+
ip_address = bw_point['primaryIpAddress']
65+
table_data.add_row([bw_point['id'], bw_point['fullyQualifiedDomainName'], ip_address, amount, current])
66+
return [table_data]

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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'),
1819
('account:event-detail', 'SoftLayer.CLI.account.event_detail:cli'),
1920
('account:licenses', 'SoftLayer.CLI.account.licenses:cli'),
2021
('account:summary', 'SoftLayer.CLI.account.summary:cli'),
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
getObject = {
2+
'bandwidthAllotmentTypeId': 2,
3+
'createDate': '2016-07-25T08:31:17-07:00',
4+
'id': 123456,
5+
'locationGroupId': 262,
6+
'name': 'MexRegion',
7+
'serviceProviderId': 1,
8+
'activeDetails': [
9+
{
10+
'allocationId': 48293300,
11+
'bandwidthAllotmentId': 309961,
12+
'effectiveDate': '2022-02-04T00:00:00-06:00',
13+
'id': 48882086,
14+
'serviceProviderId': 1,
15+
'allocation': {
16+
'amount': '5000',
17+
'id': 48293300,
18+
}
19+
},
20+
{
21+
'allocationId': 48293302,
22+
'bandwidthAllotmentId': 309961,
23+
'effectiveDate': '2022-02-04T00:00:00-06:00',
24+
'id': 48882088,
25+
'serviceProviderId': 1,
26+
'allocation': {
27+
'amount': '5000',
28+
'id': 48293302,
29+
}
30+
}
31+
],
32+
'bareMetalInstances': [],
33+
'billingCyclePublicBandwidthUsage': {
34+
'amountIn': '.23642',
35+
'amountOut': '.05475',
36+
'bandwidthUsageDetailTypeId': '1',
37+
'trackingObject': {
38+
'id': 258963,
39+
'resourceTableId': 309961,
40+
'startDate': '2021-03-10T11:04:56-06:00',
41+
}
42+
},
43+
'hardware': [
44+
{
45+
'domain': 'test.com',
46+
'fullyQualifiedDomainName': 'testpooling.test.com',
47+
'hardwareStatusId': 5,
48+
'hostname': 'testpooling',
49+
'id': 36589,
50+
'manufacturerSerialNumber': 'J122Y7N',
51+
'provisionDate': '2022-01-24T15:17:03-06:00',
52+
'serialNumber': 'SL018EA8',
53+
'serviceProviderId': 1,
54+
'bandwidthAllotmentDetail': {
55+
'allocationId': 48293302,
56+
'bandwidthAllotmentId': 309961,
57+
'effectiveDate': '2022-02-04T00:00:00-06:00',
58+
'id': 48882088,
59+
'allocation': {
60+
'amount': '5000',
61+
'id': 48293302,
62+
}
63+
},
64+
'globalIdentifier': '36e63026-5fa1-456d-a04f-adf34e60e2f4',
65+
'hardwareStatus': {
66+
'id': 5,
67+
'status': 'ACTIVE'
68+
},
69+
'networkManagementIpAddress': '10.130.97.247',
70+
'outboundBandwidthUsage': '.02594',
71+
'primaryBackendIpAddress': '10.130.97.227',
72+
'primaryIpAddress': '169.57.4.70',
73+
'privateIpAddress': '10.130.97.227'
74+
},
75+
{
76+
'domain': 'testtest.com',
77+
'fullyQualifiedDomainName': 'testpooling2.test.com',
78+
'hardwareStatusId': 5,
79+
'hostname': 'testpooling2',
80+
'id': 25478,
81+
'manufacturerSerialNumber': 'J12935M',
82+
'notes': '',
83+
'provisionDate': '2022-01-24T15:44:20-06:00',
84+
'serialNumber': 'SL01HIIB',
85+
'serviceProviderId': 1,
86+
'bandwidthAllotmentDetail': {
87+
'allocationId': 48293300,
88+
'bandwidthAllotmentId': 309961,
89+
'effectiveDate': '2022-02-04T00:00:00-06:00',
90+
'id': 48882086,
91+
'serviceProviderId': 1,
92+
'allocation': {
93+
'amount': '5000',
94+
'id': 478965,
95+
}
96+
},
97+
'globalIdentifier': '6ea407bd-9c07-4129-9103-9fda8a9e7028',
98+
'hardwareStatus': {
99+
'id': 5,
100+
'status': 'ACTIVE'
101+
},
102+
'networkManagementIpAddress': '10.130.97.252',
103+
'outboundBandwidthUsage': '.02884',
104+
'primaryBackendIpAddress': '10.130.97.248',
105+
'primaryIpAddress': '169.57.4.73',
106+
'privateIpAddress': '10.130.97.248'
107+
}
108+
],
109+
'inboundPublicBandwidthUsage': '.23642',
110+
'projectedPublicBandwidthUsage': 0.43,
111+
'virtualGuests': [{
112+
'createDate': '2021-06-09T13:49:28-07:00',
113+
'deviceStatusId': 8,
114+
'domain': 'cgallo.com',
115+
'fullyQualifiedDomainName': 'KVM-Test.test.com',
116+
'hostname': 'KVM-Test',
117+
'id': 3578963,
118+
'maxCpu': 2,
119+
'maxCpuUnits': 'CORE',
120+
'maxMemory': 4096,
121+
'startCpus': 2,
122+
'statusId': 1001,
123+
'typeId': 1,
124+
'uuid': '15951561-6171-0dfc-f3d2-be039e51cc10',
125+
'bandwidthAllotmentDetail': {
126+
'allocationId': 45907006,
127+
'bandwidthAllotmentId': 138442,
128+
'effectiveDate': '2021-06-09T13:49:31-07:00',
129+
'id': 46467342,
130+
'serviceProviderId': 1,
131+
'allocation': {
132+
'amount': '0',
133+
'id': 45907006,
134+
}
135+
},
136+
'globalIdentifier': 'a245a7dd-acd1-4d1a-9356-cc1ac6b55b98',
137+
'outboundPublicBandwidthUsage': '.02845',
138+
'primaryBackendIpAddress': '10.208.73.53',
139+
'primaryIpAddress': '169.48.96.27',
140+
'status': {
141+
'keyName': 'ACTIVE',
142+
'name': 'Active'
143+
}
144+
}]
145+
}

SoftLayer/managers/account.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,14 @@ def get_active_account_licenses(self):
326326
_mask = """billingItem,softwareDescription"""
327327

328328
return self.client['SoftLayer_Account'].getActiveAccountLicenses(mask=_mask)
329+
330+
def getBandwidthDetail(self, identifier):
331+
"""Gets bandwidth pool detail.
332+
333+
:returns: bandwidth pool detail
334+
"""
335+
_mask = """activeDetails[allocation],projectedPublicBandwidthUsage, billingCyclePublicBandwidthUsage,
336+
hardware[outboundBandwidthUsage,bandwidthAllotmentDetail[allocation]],inboundPublicBandwidthUsage,
337+
virtualGuests[outboundPublicBandwidthUsage,bandwidthAllotmentDetail[allocation]],
338+
bareMetalInstances[outboundBandwidthUsage,bandwidthAllotmentDetail[allocation]]"""
339+
return self.client['SoftLayer_Network_Bandwidth_Version1_Allotment'].getObject(id=identifier, mask=_mask)

docs/cli/account.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ Account Commands
4343
.. click:: SoftLayer.CLI.account.licenses:cli
4444
:prog: account licenses
4545
:show-nested:
46+
47+
.. click:: SoftLayer.CLI.account.bandwidth_pools_detail:cli
48+
:prog: account bandwidth-pools-detail
49+
:show-nested:

tests/CLI/modules/account_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,8 @@ def test_acccount_licenses(self):
136136
self.assert_no_fail(result)
137137
self.assert_called_with('SoftLayer_Account', 'getActiveVirtualLicenses')
138138
self.assert_called_with('SoftLayer_Account', 'getActiveAccountLicenses')
139+
140+
def test_acccount_bandwidth_pool_detail(self):
141+
result = self.run_command(['account', 'bandwidth-pools-detail', '123456'])
142+
self.assert_no_fail(result)
143+
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')

0 commit comments

Comments
 (0)