def list(self, component=None): """ Lists all available Licenses """ if component is None: return LicenseList.get_licenses() return LicenseList.get_by_component(component, return_as_list=True)
def apply(license_string): """ Applies a license. It will apply as much licenses as possible, however, it won't fail on invalid licenses as it will simply skip them. """ try: clients = {} storagerouters = StorageRouterList.get_storagerouters() try: for storagerouter in storagerouters: clients[storagerouter] = SSHClient(storagerouter.ip) except UnableToConnectException: raise RuntimeError('Not all StorageRouters are reachable') data = LicenseController._decode(license_string) for component in data: cdata = data[component] name = cdata['name'] data = cdata['data'] token = cdata['token'] valid_until = float( cdata['valid_until']) if 'valid_until' in cdata else None if valid_until is not None and valid_until <= time.time(): continue signature = cdata['signature'] if 'signature' in cdata else None validate_functions = Toolbox.fetch_hooks( 'license', '{0}.validate'.format(component)) apply_functions = Toolbox.fetch_hooks( 'license', '{0}.apply'.format(component)) if len(validate_functions) == 1 and len(apply_functions) == 1: valid, metadata = validate_functions[0]( component=component, data=data, signature=signature) if valid is True: success = apply_functions[0](component=component, data=data, signature=signature) if success is True: license_object = LicenseList.get_by_component( component) if license_object is None: license_object = License() license_object.component = component license_object.name = name license_object.token = token license_object.data = data license_object.valid_until = valid_until license_object.signature = signature license_object.save() license_contents = [] for lic in LicenseList.get_licenses(): license_contents.append(lic.hash) for storagerouter in storagerouters: client = clients[storagerouter] client.file_write('/opt/OpenvStorage/config/licenses', '{0}\n'.format('\n'.join(license_contents))) except Exception, ex: logger.exception('Error applying license: {0}'.format(ex)) return None
def apply(license_string): """ Applies a license. It will apply as much licenses as possible, however, it won't fail on invalid licenses as it will simply skip them. """ try: clients = {} storagerouters = StorageRouterList.get_storagerouters() try: for storagerouter in storagerouters: clients[storagerouter] = SSHClient(storagerouter.ip) except UnableToConnectException: raise RuntimeError('Not all StorageRouters are reachable') data = LicenseController._decode(license_string) for component in data: cdata = data[component] name = cdata['name'] data = cdata['data'] token = cdata['token'] valid_until = float(cdata['valid_until']) if 'valid_until' in cdata else None if valid_until is not None and valid_until <= time.time(): continue signature = cdata['signature'] if 'signature' in cdata else None validate_functions = Toolbox.fetch_hooks('license', '{0}.validate'.format(component)) apply_functions = Toolbox.fetch_hooks('license', '{0}.apply'.format(component)) if len(validate_functions) == 1 and len(apply_functions) == 1: valid, metadata = validate_functions[0](component=component, data=data, signature=signature) if valid is True: success = apply_functions[0](component=component, data=data, signature=signature) if success is True: license_object = LicenseList.get_by_component(component) if license_object is None: license_object = License() license_object.component = component license_object.name = name license_object.token = token license_object.data = data license_object.valid_until = valid_until license_object.signature = signature license_object.save() license_contents = [] for lic in LicenseList.get_licenses(): license_contents.append(lic.hash) for storagerouter in storagerouters: client = clients[storagerouter] client.file_write('/opt/OpenvStorage/config/licenses', '{0}\n'.format('\n'.join(license_contents))) except Exception, ex: LicenseController._logger.exception('Error applying license: {0}'.format(ex)) return None
def remove(license_guid): """ Removes a license """ clients = {} storagerouters = StorageRouterList.get_storagerouters() try: for storagerouter in storagerouters: clients[storagerouter] = SSHClient(storagerouter.ip) except UnableToConnectException: raise RuntimeError('Not all StorageRouters are reachable') lic = License(license_guid) if lic.can_remove is True: remove_functions = Toolbox.fetch_hooks('license', '{0}.remove'.format(lic.component)) result = remove_functions[0](component=lic.component, data=lic.data, valid_until=lic.valid_until, signature=lic.signature) if result is True: lic.delete() license_contents = [] for lic in LicenseList.get_licenses(): license_contents.append(lic.hash) for storagerouter in storagerouters: client = clients[storagerouter] client.file_write('/opt/OpenvStorage/config/licenses', '{0}\n'.format('\n'.join(license_contents))) return result return None
def add_extra_node(**kwargs): ip = kwargs['cluster_ip'] license_contents = [] for lic in LicenseList.get_licenses(): license_contents.append(lic.hash) client = SSHClient(ip) client.file_write('/opt/OpenvStorage/config/licenses', '{0}\n'.format('\n'.join(license_contents)))
def remove(license_guid): """ Removes a license """ clients = {} storagerouters = StorageRouterList.get_storagerouters() try: for storagerouter in storagerouters: clients[storagerouter] = SSHClient(storagerouter.ip) except UnableToConnectException: raise RuntimeError('Not all StorageRouters are reachable') lic = License(license_guid) if lic.can_remove is True: remove_functions = Toolbox.fetch_hooks( 'license', '{0}.remove'.format(lic.component)) result = remove_functions[0](component=lic.component, data=lic.data, valid_until=lic.valid_until, signature=lic.signature) if result is True: lic.delete() license_contents = [] for lic in LicenseList.get_licenses(): license_contents.append(lic.hash) for storagerouter in storagerouters: client = clients[storagerouter] client.file_write( '/opt/OpenvStorage/config/licenses', '{0}\n'.format('\n'.join(license_contents))) return result return None
def add_extra_node(**kwargs): """ Add extra node hook :param kwargs: Extra parameters :return: None """ ip = kwargs['cluster_ip'] license_contents = [] for lic in LicenseList.get_licenses(): license_contents.append(lic.hash) client = SSHClient(ip) client.file_write('/opt/OpenvStorage/config/licenses', '{0}\n'.format('\n'.join(license_contents)))