Skip to content

Commit ce5dabf

Browse files
Merge pull request #1504 from caberos/issue1503
create a new commands on slcli that create/cancel a VMware licenses s…
2 parents 9e676af + 22f58ce commit ce5dabf

File tree

11 files changed

+279
-0
lines changed

11 files changed

+279
-0
lines changed

SoftLayer/CLI/licenses/__init__.py

Whitespace-only changes.

SoftLayer/CLI/licenses/cancel.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Cancel a license."""
2+
# :licenses: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
7+
from SoftLayer.CLI import environment
8+
9+
10+
@click.command()
11+
@click.argument('key')
12+
@click.option('--immediate', is_flag=True, help='Immediate cancellation')
13+
@environment.pass_env
14+
def cli(env, key, immediate):
15+
"""Cancel a license."""
16+
17+
licenses = SoftLayer.LicensesManager(env.client)
18+
19+
env.fout(licenses.cancel_item(key, immediate))

SoftLayer/CLI/licenses/create.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Order/create a vwmare licenses."""
2+
# :licenses: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import formatting
10+
11+
12+
@click.command()
13+
@click.option('--key', '-k', required=True, prompt=True,
14+
help="The VMware License Key. "
15+
"To get could use the product_package::getItems id=301 with name Software License Package"
16+
"E.g VMWARE_VSAN_ENTERPRISE_TIER_III_65_124_TB_6_X_2")
17+
@click.option('--datacenter', '-d', required=True, prompt=True, help="Datacenter shortname")
18+
@environment.pass_env
19+
def cli(env, key, datacenter):
20+
"""Order/Create License."""
21+
22+
item_package = [key]
23+
24+
licenses = SoftLayer.LicensesManager(env.client)
25+
26+
result = licenses.create(datacenter, item_package)
27+
28+
table = formatting.KeyValueTable(['name', 'value'])
29+
table.align['name'] = 'r'
30+
table.align['value'] = 'l'
31+
table.add_row(['id', result['orderId']])
32+
table.add_row(['created', result['orderDate']])
33+
34+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@
218218
('nas:list', 'SoftLayer.CLI.nas.list:cli'),
219219
('nas:credentials', 'SoftLayer.CLI.nas.credentials:cli'),
220220

221+
('licenses', 'SoftLayer.CLI.licenses'),
222+
('licenses:create', 'SoftLayer.CLI.licenses.create:cli'),
223+
('licenses:cancel', 'SoftLayer.CLI.licenses.cancel:cli'),
224+
221225
('object-storage', 'SoftLayer.CLI.object_storage'),
222226

223227
('object-storage:accounts', 'SoftLayer.CLI.object_storage.list_accounts:cli'),

SoftLayer/fixtures/SoftLayer_Product_Order.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,35 @@
252252
]
253253
}
254254
}
255+
256+
wmware_placeOrder = {
257+
"orderDate": "2021-06-02 15:23:47",
258+
"orderId": 123456,
259+
"prices": [
260+
{
261+
"id": 176535,
262+
"itemId": 8109,
263+
"categories": [
264+
{
265+
"categoryCode": "software_license",
266+
"id": 438,
267+
"name": "Software License"
268+
}
269+
],
270+
"item": {
271+
"capacity": "1",
272+
"description": "VMware vSAN Advanced Tier III 64 - 124 TB 6.x",
273+
"id": 8109,
274+
"keyName": "VMWARE_VSAN_ADVANCE_TIER_III_64_124_6_X",
275+
"softwareDescription": {
276+
"id": 1795,
277+
},
278+
"thirdPartyPolicyAssignments": [
279+
{
280+
"id": 29263,
281+
"policyName": "3rd Party Software Terms VMWare v4"
282+
}
283+
]
284+
}
285+
}
286+
]}

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,3 +2055,29 @@
20552055
"categoryCode": "dedicated_virtual_hosts"
20562056
}
20572057
}]}
2058+
2059+
getItems_vmware = [{
2060+
"capacity": "2",
2061+
"description": "VMware vSAN Enterprise Tier III 65 - 124 TB 6.x",
2062+
"id": 9567,
2063+
"itemTaxCategoryId": 166,
2064+
"keyName": "VMWARE_VSAN_ENTERPRISE_TIER_III_65_124_TB_6_X_2",
2065+
"softwareDescriptionId": 1979,
2066+
"units": "CPU",
2067+
"itemCategory": {
2068+
"categoryCode": "software_license",
2069+
"id": 438,
2070+
"name": "Software License",
2071+
"quantityLimit": 1,
2072+
},
2073+
"prices": [
2074+
{
2075+
"id": 245164,
2076+
"itemId": 9567,
2077+
"laborFee": "0",
2078+
"locationGroupId": None,
2079+
"oneTimeFee": "0",
2080+
"setupFee": "0",
2081+
"sort": 0,
2082+
}
2083+
]}]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
getAllObjects = [{
2+
"capacity": "4",
3+
"key": "ABCDE-6CJ8L-J8R9H-000R0-CDR70",
4+
"units": "CPU",
5+
"billingItem": {
6+
"allowCancellationFlag": 1,
7+
"categoryCode": "software_license",
8+
"createDate": "2018-10-22T11:16:48-06:00",
9+
"cycleStartDate": "2021-06-03T23:11:22-06:00",
10+
"description": "vCenter Server Appliance 6.0",
11+
"id": 123654789,
12+
"lastBillDate": "2021-06-03T23:11:22-06:00",
13+
"modifyDate": "2021-06-03T23:11:22-06:00",
14+
"nextBillDate": "2021-07-03T23:00:00-06:00",
15+
"orderItemId": 385054741,
16+
"recurringMonths": 1,
17+
"serviceProviderId": 1,
18+
},
19+
"softwareDescription": {
20+
"id": 1529,
21+
"longDescription": "VMware vCenter 6.0",
22+
"manufacturer": "VMware",
23+
"name": "vCenter",
24+
"version": "6.0",
25+
"requiredUser": "administrator@vsphere.local"
26+
}
27+
},
28+
{
29+
"capacity": "1",
30+
"key": "CBERT-4RL92-K8999-031K4-AJF5J",
31+
"units": "CPU",
32+
"billingItem": {
33+
"allowCancellationFlag": 1,
34+
"categoryCode": "software_license",
35+
"createDate": "2021-06-09T14:51:38-06:00",
36+
"cycleStartDate": "2021-06-09T14:51:38-06:00",
37+
"description": "VMware vSAN Advanced Tier III 64 - 124 TB 6.x",
38+
"id": 369852174,
39+
"nextBillDate": "2021-07-03T23:00:00-06:00",
40+
"orderItemId": 836502628,
41+
"recurringMonths": 1,
42+
"serviceProviderId": 1,
43+
},
44+
"softwareDescription": {
45+
"id": 1795,
46+
"longDescription": "VMware Virtual SAN Advanced Tier III 6.2",
47+
"manufacturer": "VMware",
48+
"name": "Virtual SAN Advanced Tier III",
49+
"version": "6.2",
50+
}
51+
}]

SoftLayer/managers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from SoftLayer.managers.hardware import HardwareManager
1818
from SoftLayer.managers.image import ImageManager
1919
from SoftLayer.managers.ipsec import IPSECManager
20+
from SoftLayer.managers.license import LicensesManager
2021
from SoftLayer.managers.load_balancer import LoadBalancerManager
2122
from SoftLayer.managers.metadata import MetadataManager
2223
from SoftLayer.managers.network import NetworkManager
@@ -43,6 +44,7 @@
4344
'HardwareManager',
4445
'ImageManager',
4546
'IPSECManager',
47+
'LicensesManager',
4648
'LoadBalancerManager',
4749
'MetadataManager',
4850
'NetworkManager',

SoftLayer/managers/license.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
SoftLayer.license
3+
~~~~~~~~~~~~~~~
4+
License Manager
5+
6+
:license: MIT, see LICENSE for more details.
7+
"""
8+
9+
# pylint: disable=too-many-public-methods
10+
from SoftLayer.CLI import exceptions
11+
from SoftLayer.managers import ordering
12+
from SoftLayer import utils
13+
14+
15+
class LicensesManager(object):
16+
"""Manages account license."""
17+
18+
def __init__(self, client):
19+
self.client = client
20+
21+
def get_all_objects(self):
22+
"""Show the all VMware licenses of an account.
23+
24+
"""
25+
_mask = '''softwareDescription,billingItem'''
26+
27+
return self.client.call('SoftLayer_Software_AccountLicense',
28+
'getAllObjects', mask=_mask)
29+
30+
def cancel_item(self, key, cancel_immediately=False):
31+
"""Cancel a billing item immediately, deleting all its data.
32+
33+
:param integer identifier: the instance ID to cancel
34+
:param string reason_cancel: reason cancel
35+
"""
36+
vm_ware_licenses = self.get_all_objects()
37+
vm_ware_find = False
38+
for vm_ware in vm_ware_licenses:
39+
if vm_ware.get('key') == key:
40+
vm_ware_find = True
41+
self.client.call('SoftLayer_Billing_Item', 'cancelItem',
42+
cancel_immediately,
43+
True,
44+
'Cancel by cli command',
45+
'Cancel by cli command',
46+
id=utils.lookup(vm_ware, 'billingItem', 'id'))
47+
48+
if not vm_ware_find:
49+
raise exceptions.CLIAbort(
50+
"Unable to find license key: {}".format(key))
51+
return vm_ware_find
52+
53+
def create(self, datacenter, item_package):
54+
"""Create a license
55+
56+
:param string datacenter: the datacenter shortname
57+
:param string[] item_package: items array
58+
"""
59+
complex_type = 'SoftLayer_Container_Product_Order_Software_License'
60+
ordering_manager = ordering.OrderingManager(self.client)
61+
return ordering_manager.place_order(package_keyname='SOFTWARE_LICENSE_PACKAGE',
62+
location=datacenter,
63+
item_keynames=item_package,
64+
complex_type=complex_type,
65+
hourly=False)

docs/cli/licenses.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. _cli_licenses:
2+
3+
licenses Commands
4+
=================
5+
6+
.. click:: SoftLayer.CLI.licenses.create:cli
7+
:prog: licenses create
8+
:show-nested:
9+
10+
.. click:: SoftLayer.CLI.licenses.cancel:cli
11+
:prog: licenses cancel
12+
:show-nested:

0 commit comments

Comments
 (0)