Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bandwidth pool management #1582

Merged
merged 6 commits into from
Feb 23, 2022
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
79 changes: 79 additions & 0 deletions SoftLayer/CLI/account/bandwidth_pools_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""Get bandwidth pools."""
# :license: MIT, see LICENSE for more details.
import click

from SoftLayer import AccountManager
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer import utils


@click.command()
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
"""Get bandwidth pool details."""

manager = AccountManager(env.client)
bandwidths = manager.getBandwidthDetail(identifier)

table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['Id', bandwidths['id']])
table.add_row(['Name', bandwidths['name']])
table.add_row(['Create Date', utils.clean_time(bandwidths.get('createDate'), '%Y-%m-%d')])
current = "{} GB".format(utils.lookup(bandwidths, 'billingCyclePublicBandwidthUsage', 'amountOut'))
if current is None:
current = '-'
table.add_row(['Current Usage', current])
projected = "{} GB".format(bandwidths.get('projectedPublicBandwidthUsage', 0))
if projected is None:
projected = '-'
table.add_row(['Projected Usage', projected])
inbound = "{} GB".format(bandwidths.get('inboundPublicBandwidthUsage', 0))
if inbound is None:
inbound = '-'
table.add_row(['Inbound Usage', inbound])
if bandwidths['hardware'] != []:
table.add_row(['hardware', _bw_table(bandwidths['hardware'])])
else:
table.add_row(['hardware', 'Not Found'])

if bandwidths['virtualGuests'] != []:
table.add_row(['virtualGuests', _virtual_table(bandwidths['virtualGuests'])])
else:
table.add_row(['virtualGuests', 'Not Found'])

if bandwidths['bareMetalInstances'] != []:
table.add_row(['Netscaler', _bw_table(bandwidths['bareMetalInstances'])])
else:
table.add_row(['Netscaler', 'Not Found'])

env.fout(table)


def _bw_table(bw_data):
"""Generates a bandwidth useage table"""
table_data = formatting.Table(['Id', 'HostName', "IP Address", 'Amount', "Current Usage"])
for bw_point in bw_data:
amount = "{} GB".format(utils.lookup(bw_point, 'bandwidthAllotmentDetail', 'allocation', 'amount'))
current = "{} GB".format(bw_point.get('outboundBandwidthUsage', 0))
ip_address = bw_point.get('primaryIpAddress')
if ip_address is None:
ip_address = '-'
table_data.add_row([bw_point['id'], bw_point['fullyQualifiedDomainName'], ip_address, amount, current])
return [table_data]


def _virtual_table(bw_data):
"""Generates a virtual bandwidth usage table"""
table_data = formatting.Table(['Id', 'HostName', "IP Address", 'Amount', "Current Usage"])
for bw_point in bw_data:
amount = "{} GB".format(utils.lookup(bw_point, 'bandwidthAllotmentDetail', 'allocation', 'amount'))
current = "{} GB".format(bw_point.get('outboundBandwidthUsage', 0))
ip_address = bw_point.get('primaryIpAddress')
if ip_address is None:
ip_address = '-'
table_data.add_row([bw_point['id'], bw_point['fullyQualifiedDomainName'], ip_address, amount, current])
return [table_data]
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
('account:invoice-detail', 'SoftLayer.CLI.account.invoice_detail:cli'),
('account:invoices', 'SoftLayer.CLI.account.invoices:cli'),
('account:events', 'SoftLayer.CLI.account.events:cli'),
('account:bandwidth-pools-detail', 'SoftLayer.CLI.account.bandwidth_pools_detail:cli'),
('account:event-detail', 'SoftLayer.CLI.account.event_detail:cli'),
('account:licenses', 'SoftLayer.CLI.account.licenses:cli'),
('account:summary', 'SoftLayer.CLI.account.summary:cli'),
Expand Down
146 changes: 144 additions & 2 deletions SoftLayer/fixtures/SoftLayer_Network_Bandwidth_Version1_Allotment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,148 @@
getObject = {
'id': 309961,
'bandwidthAllotmentTypeId': 2,
'createDate': '2016-07-25T08:31:17-07:00',
'id': 123456,
'locationGroupId': 262,
'name': 'MexRegion',
'serviceProviderId': 1,
'bareMetalInstanceCount': 0,
'hardwareCount': 2,
'virtualGuestCount': 0
'virtualGuestCount': 0,
'activeDetails': [
{
'allocationId': 48293300,
'bandwidthAllotmentId': 309961,
'effectiveDate': '2022-02-04T00:00:00-06:00',
'id': 48882086,
'serviceProviderId': 1,
'allocation': {
'amount': '5000',
'id': 48293300,
}
},
{
'allocationId': 48293302,
'bandwidthAllotmentId': 309961,
'effectiveDate': '2022-02-04T00:00:00-06:00',
'id': 48882088,
'serviceProviderId': 1,
'allocation': {
'amount': '5000',
'id': 48293302,
}
}
],
'bareMetalInstances': [],
'billingCyclePublicBandwidthUsage': {
'amountIn': '.23642',
'amountOut': '.05475',
'bandwidthUsageDetailTypeId': '1',
'trackingObject': {
'id': 258963,
'resourceTableId': 309961,
'startDate': '2021-03-10T11:04:56-06:00',
}
},
'hardware': [
{
'domain': 'test.com',
'fullyQualifiedDomainName': 'testpooling.test.com',
'hardwareStatusId': 5,
'hostname': 'testpooling',
'id': 36589,
'manufacturerSerialNumber': 'J122Y7N',
'provisionDate': '2022-01-24T15:17:03-06:00',
'serialNumber': 'SL018EA8',
'serviceProviderId': 1,
'bandwidthAllotmentDetail': {
'allocationId': 48293302,
'bandwidthAllotmentId': 309961,
'effectiveDate': '2022-02-04T00:00:00-06:00',
'id': 48882088,
'allocation': {
'amount': '5000',
'id': 48293302,
}
},
'globalIdentifier': '36e63026-5fa1-456d-a04f-adf34e60e2f4',
'hardwareStatus': {
'id': 5,
'status': 'ACTIVE'
},
'networkManagementIpAddress': '10.130.97.247',
'outboundBandwidthUsage': '.02594',
'primaryBackendIpAddress': '10.130.97.227',
'primaryIpAddress': '169.57.4.70',
'privateIpAddress': '10.130.97.227'
},
{
'domain': 'testtest.com',
'fullyQualifiedDomainName': 'testpooling2.test.com',
'hardwareStatusId': 5,
'hostname': 'testpooling2',
'id': 25478,
'manufacturerSerialNumber': 'J12935M',
'notes': '',
'provisionDate': '2022-01-24T15:44:20-06:00',
'serialNumber': 'SL01HIIB',
'serviceProviderId': 1,
'bandwidthAllotmentDetail': {
'allocationId': 48293300,
'bandwidthAllotmentId': 309961,
'effectiveDate': '2022-02-04T00:00:00-06:00',
'id': 48882086,
'serviceProviderId': 1,
'allocation': {
'amount': '5000',
'id': 478965,
}
},
'globalIdentifier': '6ea407bd-9c07-4129-9103-9fda8a9e7028',
'hardwareStatus': {
'id': 5,
'status': 'ACTIVE'
},
'networkManagementIpAddress': '10.130.97.252',
'outboundBandwidthUsage': '.02884',
'primaryBackendIpAddress': '10.130.97.248',
'primaryIpAddress': '169.57.4.73',
'privateIpAddress': '10.130.97.248'
}
],
'inboundPublicBandwidthUsage': '.23642',
'projectedPublicBandwidthUsage': 0.43,
'virtualGuests': [{
'createDate': '2021-06-09T13:49:28-07:00',
'deviceStatusId': 8,
'domain': 'cgallo.com',
'fullyQualifiedDomainName': 'KVM-Test.test.com',
'hostname': 'KVM-Test',
'id': 3578963,
'maxCpu': 2,
'maxCpuUnits': 'CORE',
'maxMemory': 4096,
'startCpus': 2,
'statusId': 1001,
'typeId': 1,
'uuid': '15951561-6171-0dfc-f3d2-be039e51cc10',
'bandwidthAllotmentDetail': {
'allocationId': 45907006,
'bandwidthAllotmentId': 138442,
'effectiveDate': '2021-06-09T13:49:31-07:00',
'id': 46467342,
'serviceProviderId': 1,
'allocation': {
'amount': '0',
'id': 45907006,
}
},
'globalIdentifier': 'a245a7dd-acd1-4d1a-9356-cc1ac6b55b98',
'outboundPublicBandwidthUsage': '.02845',
'primaryBackendIpAddress': '10.208.73.53',
'primaryIpAddress': '169.48.96.27',
'status': {
'keyName': 'ACTIVE',
'name': 'Active'
}
}]
}
11 changes: 11 additions & 0 deletions SoftLayer/managers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,14 @@ def get_bandwidth_pool_counts(self, identifier):
counts.get('hardwareCount', 0) + \
counts.get('virtualGuestCount', 0)
return total

def getBandwidthDetail(self, identifier):
"""Gets bandwidth pool detail.

:returns: bandwidth pool detail
"""
_mask = """activeDetails[allocation],projectedPublicBandwidthUsage, billingCyclePublicBandwidthUsage,
hardware[outboundBandwidthUsage,bandwidthAllotmentDetail[allocation]],inboundPublicBandwidthUsage,
virtualGuests[outboundPublicBandwidthUsage,bandwidthAllotmentDetail[allocation]],
bareMetalInstances[outboundBandwidthUsage,bandwidthAllotmentDetail[allocation]]"""
return self.client['SoftLayer_Network_Bandwidth_Version1_Allotment'].getObject(id=identifier, mask=_mask)
4 changes: 4 additions & 0 deletions docs/cli/account.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Account Commands
.. click:: SoftLayer.CLI.account.bandwidth_pools:cli
:prog: account bandwidth-pools
:show-nested:

.. click:: SoftLayer.CLI.account.bandwidth_pools_detail:cli
:prog: account bandwidth-pools-detail
:show-nested:
5 changes: 5 additions & 0 deletions tests/CLI/modules/account_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,8 @@ def test_bandwidth_pools(self):
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments')
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')

def test_acccount_bandwidth_pool_detail(self):
result = self.run_command(['account', 'bandwidth-pools-detail', '123456'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')