Skip to content

Commit 3a206a8

Browse files
Merge pull request #1582 from caberos/issue1579
Bandwidth pool management
2 parents bfcbc02 + 6f85906 commit 3a206a8

File tree

6 files changed

+244
-2
lines changed

6 files changed

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

SoftLayer/managers/account.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,14 @@ def get_bandwidth_pool_counts(self, identifier):
350350
counts.get('hardwareCount', 0) + \
351351
counts.get('virtualGuestCount', 0)
352352
return total
353+
354+
def getBandwidthDetail(self, identifier):
355+
"""Gets bandwidth pool detail.
356+
357+
:returns: bandwidth pool detail
358+
"""
359+
_mask = """activeDetails[allocation],projectedPublicBandwidthUsage, billingCyclePublicBandwidthUsage,
360+
hardware[outboundBandwidthUsage,bandwidthAllotmentDetail[allocation]],inboundPublicBandwidthUsage,
361+
virtualGuests[outboundPublicBandwidthUsage,bandwidthAllotmentDetail[allocation]],
362+
bareMetalInstances[outboundBandwidthUsage,bandwidthAllotmentDetail[allocation]]"""
363+
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
@@ -47,3 +47,7 @@ Account Commands
4747
.. click:: SoftLayer.CLI.account.bandwidth_pools:cli
4848
:prog: account bandwidth-pools
4949
:show-nested:
50+
51+
.. click:: SoftLayer.CLI.account.bandwidth_pools_detail:cli
52+
:prog: account bandwidth-pools-detail
53+
:show-nested:

tests/CLI/modules/account_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,8 @@ def test_bandwidth_pools(self):
142142
self.assert_no_fail(result)
143143
self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments')
144144
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')
145+
146+
def test_acccount_bandwidth_pool_detail(self):
147+
result = self.run_command(['account', 'bandwidth-pools-detail', '123456'])
148+
self.assert_no_fail(result)
149+
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')

0 commit comments

Comments
 (0)