Skip to content

Commit 9321d72

Browse files
Merge pull request #1501 from caberos/issue1500
Add slcli account licenses
2 parents a844e1c + 14f19da commit 9321d72

File tree

7 files changed

+192
-1
lines changed

7 files changed

+192
-1
lines changed

SoftLayer/CLI/account/licenses.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Show all licenses."""
2+
# :license: MIT, see LICENSE for more details.
3+
import click
4+
5+
from SoftLayer import utils
6+
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
from SoftLayer.managers import account
10+
11+
12+
@click.command()
13+
@environment.pass_env
14+
def cli(env):
15+
"""Show all licenses."""
16+
17+
manager = account.AccountManager(env.client)
18+
19+
control_panel = manager.get_active_virtual_licenses()
20+
vmwares = manager.get_active_account_licenses()
21+
22+
table_panel = formatting.KeyValueTable(['id', 'ip_address', 'manufacturer', 'software',
23+
'key', 'subnet', 'subnet notes'], title="Control Panel Licenses")
24+
25+
table_vmware = formatting.KeyValueTable(['name', 'license_key', 'cpus', 'description',
26+
'manufacturer', 'requiredUser'], title="VMware Licenses")
27+
for panel in control_panel:
28+
table_panel.add_row([panel.get('id'), panel.get('ipAddress'),
29+
utils.lookup(panel, 'softwareDescription', 'manufacturer'),
30+
utils.trim_to(utils.lookup(panel, 'softwareDescription', 'longDescription'), 40),
31+
panel.get('key'), utils.lookup(panel, 'subnet', 'broadcastAddress'),
32+
utils.lookup(panel, 'subnet', 'note')])
33+
34+
env.fout(table_panel)
35+
for vmware in vmwares:
36+
table_vmware.add_row([utils.lookup(vmware, 'softwareDescription', 'name'),
37+
vmware.get('key'), vmware.get('capacity'),
38+
utils.lookup(vmware, 'billingItem', 'description'),
39+
utils.lookup(vmware, 'softwareDescription', 'manufacturer'),
40+
utils.lookup(vmware, 'softwareDescription', 'requiredUser')])
41+
42+
env.fout(table_vmware)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
('account:invoices', 'SoftLayer.CLI.account.invoices:cli'),
1717
('account:events', 'SoftLayer.CLI.account.events:cli'),
1818
('account:event-detail', 'SoftLayer.CLI.account.event_detail:cli'),
19+
('account:licenses', 'SoftLayer.CLI.account.licenses:cli'),
1920
('account:summary', 'SoftLayer.CLI.account.summary:cli'),
2021
('account:billing-items', 'SoftLayer.CLI.account.billing_items:cli'),
2122
('account:item-detail', 'SoftLayer.CLI.account.item_detail:cli'),

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,3 +1100,110 @@
11001100
"smtpAccess": "1"
11011101
}
11021102
]
1103+
1104+
getActiveAccountLicenses = [{
1105+
"accountId": 123456,
1106+
"capacity": "4",
1107+
"key": "Y8GNS-7QRNG-OUIJO-MATEI-5GJRM",
1108+
"units": "CPU",
1109+
"billingItem": {
1110+
"allowCancellationFlag": 1,
1111+
"categoryCode": "software_license",
1112+
"cycleStartDate": "2021-06-03T23:11:22-06:00",
1113+
"description": "vCenter Server Appliance 6.0",
1114+
"id": 741258963,
1115+
"laborFee": "0",
1116+
"laborFeeTaxRate": "0",
1117+
"oneTimeFee": "0",
1118+
"oneTimeFeeTaxRate": "0",
1119+
"orderItemId": 963258741,
1120+
"recurringFee": "0",
1121+
"recurringFeeTaxRate": "0",
1122+
"recurringMonths": 1,
1123+
"serviceProviderId": 1,
1124+
"setupFee": "0",
1125+
"setupFeeTaxRate": "0"
1126+
},
1127+
"softwareDescription": {
1128+
"controlPanel": 0,
1129+
"id": 15963,
1130+
"licenseTermValue": 0,
1131+
"longDescription": "VMware vCenter 6.0",
1132+
"manufacturer": "VMware",
1133+
"name": "vCenter",
1134+
"operatingSystem": 0,
1135+
"version": "6.0",
1136+
"virtualLicense": 0,
1137+
"virtualizationPlatform": 0,
1138+
"requiredUser": "administrator@vsphere.local"
1139+
}
1140+
},
1141+
{
1142+
"accountId": 123456,
1143+
"capacity": "4",
1144+
"key": "TSZES-SJF85-04GLD-AXA64-8O1EO",
1145+
"units": "CPU",
1146+
"billingItem": {
1147+
"allowCancellationFlag": 1,
1148+
"categoryCode": "software_license",
1149+
"description": "vCenter Server Appliance 6.x",
1150+
"id": 36987456,
1151+
"laborFee": "0",
1152+
"laborFeeTaxRate": "0",
1153+
"oneTimeFee": "0",
1154+
"oneTimeFeeTaxRate": "0",
1155+
"orderItemId": 25839,
1156+
"recurringFee": "0",
1157+
"recurringFeeTaxRate": "0",
1158+
"recurringMonths": 1,
1159+
"serviceProviderId": 1,
1160+
"setupFee": "0",
1161+
"setupFeeTaxRate": "0"
1162+
},
1163+
"softwareDescription": {
1164+
"controlPanel": 0,
1165+
"id": 1472,
1166+
"licenseTermValue": 0,
1167+
"longDescription": "VMware vCenter 6.0",
1168+
"manufacturer": "VMware",
1169+
"name": "vCenter",
1170+
"operatingSystem": 0,
1171+
"version": "6.0",
1172+
"virtualLicense": 0,
1173+
"virtualizationPlatform": 0,
1174+
"requiredUser": "administrator@vsphere.local"
1175+
}
1176+
}
1177+
]
1178+
1179+
getActiveVirtualLicenses = [{
1180+
"id": 12345,
1181+
"ipAddress": "192.168.23.78",
1182+
"key": "TEST.60220734.0000",
1183+
"billingItem": {
1184+
"categoryCode": "control_panel",
1185+
"description": "Plesk Onyx (Linux) - (Unlimited) - VPS "
1186+
},
1187+
"softwareDescription": {
1188+
"longDescription": "Plesk - Unlimited Domain w/ Power Pack for VPS 17.8.11 Linux",
1189+
"manufacturer": "Plesk",
1190+
"name": "Plesk - Unlimited Domain w/ Power Pack for VPS"
1191+
},
1192+
"subnet": {
1193+
"broadcastAddress": "192.168.23.79",
1194+
"cidr": 28,
1195+
"gateway": "192.168.23.65",
1196+
"id": 1973163,
1197+
"isCustomerOwned": False,
1198+
"isCustomerRoutable": False,
1199+
"netmask": "255.255.255.240",
1200+
"networkIdentifier": "128.116.23.64",
1201+
"networkVlanId": 123456,
1202+
"note": "test note",
1203+
"sortOrder": "1",
1204+
"subnetType": "ADDITIONAL_PRIMARY",
1205+
"totalIpAddresses": "16",
1206+
"usableIpAddressCount": "13",
1207+
"version": 4
1208+
}
1209+
}]

SoftLayer/managers/account.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,26 @@ def get_network_message_delivery_accounts(self):
303303
_mask = """vendor,type"""
304304

305305
return self.client['SoftLayer_Account'].getNetworkMessageDeliveryAccounts(mask=_mask)
306+
307+
def get_active_virtual_licenses(self):
308+
"""Gets all active virtual licenses account.
309+
310+
:returns: active virtual licenses account
311+
"""
312+
313+
_mask = """billingItem[categoryCode,createDate,description],
314+
key,id,ipAddress,
315+
softwareDescription[longDescription,name,manufacturer],
316+
subnet"""
317+
318+
return self.client['SoftLayer_Account'].getActiveVirtualLicenses(mask=_mask)
319+
320+
def get_active_account_licenses(self):
321+
"""Gets all active account licenses.
322+
323+
:returns: Active account Licenses
324+
"""
325+
326+
_mask = """billingItem,softwareDescription"""
327+
328+
return self.client['SoftLayer_Account'].getActiveAccountLicenses(mask=_mask)

docs/cli/account.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ Account Commands
3838

3939
.. click:: SoftLayer.CLI.account.orders:cli
4040
:prog: account orders
41-
:show-nested:
41+
:show-nested:
42+
43+
.. click:: SoftLayer.CLI.account.licenses:cli
44+
:prog: account licenses
45+
:show-nested:

tests/CLI/modules/account_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,9 @@ def test_acccount_order(self):
116116
result = self.run_command(['account', 'orders'])
117117
self.assert_no_fail(result)
118118
self.assert_called_with('SoftLayer_Billing_Order', 'getAllObjects')
119+
120+
def test_acccount_licenses(self):
121+
result = self.run_command(['account', 'licenses'])
122+
self.assert_no_fail(result)
123+
self.assert_called_with('SoftLayer_Account', 'getActiveVirtualLicenses')
124+
self.assert_called_with('SoftLayer_Account', 'getActiveAccountLicenses')

tests/managers/account_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,11 @@ def test_get_item_details_with_invoice_item_id(self):
153153
def test_get_routers(self):
154154
self.manager.get_routers()
155155
self.assert_called_with("SoftLayer_Account", "getRouters")
156+
157+
def test_get_active_account_licenses(self):
158+
self.manager.get_active_account_licenses()
159+
self.assert_called_with("SoftLayer_Account", "getActiveAccountLicenses")
160+
161+
def test_get_active_virtual_licenses(self):
162+
self.manager.get_active_virtual_licenses()
163+
self.assert_called_with("SoftLayer_Account", "getActiveVirtualLicenses")

0 commit comments

Comments
 (0)