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