|
| 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) |
0 commit comments