def __wait_node_fdu_state_change(self, instanceid, state): ''' Waits an FDU instance state to change parameters ---------- instanceid : string UUID of instance state : string new state returns -------- dictionary ''' fdu_info = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, '*', instanceid) while fdu_info is None: fdu_info = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, '*', instanceid) fdu = InfraFDU(fdu_info) es = fdu.get_status() while es.upper() not in [state, 'ERROR']: fdu_info = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, '*', instanceid) fdu = InfraFDU(fdu_info) es = fdu.get_status() if es.upper() == 'ERROR': raise ValueError('Unable to change state to {} for FDU Instance: {} Errno: {} Msg: {}'.format( state, instanceid,fdu_info.get('error_code'), fdu_info.get('error_msg'))) return fdu_info
def __wait_node_fdu_state_change(self, instanceid, state): ''' Function used to wait if an instance changest state (eg. configured -> run) or goes to error state :param node_uuid :param fdu_uuid :param state the new expected state :return dict {'status':<new status>, 'fdu_uuid':fdu_uuid} ''' fdu_info = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, '*', instanceid) while fdu_info is None: fdu_info = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, '*', instanceid) fdu = InfraFDU(fdu_info) es = fdu.get_status() while es.upper() not in [state, 'ERROR']: fdu_info = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, '*', instanceid) fdu = InfraFDU(fdu_info) es = fdu.get_status() if es.upper() == 'ERROR': raise ValueError( 'Unable to change state to {} for FDU Instance: {} Errno: {} Msg: {}' .format(state, instanceid, fdu_info.get('error_code'), fdu_info.get('error_msg'))) return fdu_info
def write_fdu_error(self, fdu_uuid, instance_uuid, errno, errmsg): ''' Writes the given error for the given FDU instance in YAKS parameters ---------- fdu_uuid : string UUID of the FDU instance_uuid : string UUID of the instance errno : int Error number errmsg : string Error message ''' record = self.connector.loc.actual.get_node_fdu( self.node, self.uuid, fdu_uuid, instance_uuid) if record is None: record = self.connector.loc.desired.get_node_fdu( self.node, self.uuid, fdu_uuid, instance_uuid) record = InfraFDU(record) record.set_status('ERROR') record.set_error_code(errno) record.set_error_msg('{}'.format(errmsg)) self.connector.loc.actual.add_node_fdu(self.node, self.uuid, fdu_uuid, instance_uuid, record.to_json())
def define(self, fduid, node_uuid, wait=True): ''' Defines an FDU instance in a node, this method will check the descriptor before sending the definition to the node :param fduid: id of the fdu you want to instantiate :param node_uuid: destination node uuid :param wait: if wait that the definition is complete before returning :return: instance id ''' desc = self.connector.glob.actual.get_catalog_fdu_info( self.sysid, self.tenantid, fduid) if desc is None: raise ValueError('FDU with this UUID not found in the catalog') res = self.connector.glob.actual.define_fdu_in_node( self.sysid, self.tenantid, node_uuid, fduid) if res.get('error') is not None: raise ValueError('Got Error {}'.format(res['error'])) if wait: self.__wait_node_fdu_state_change(res['result']['uuid'], 'DEFINE') return InfraFDU(res['result'])
def stop(self, instanceid, wait=True): ''' Stops the given instance paremeters ---------- instanceid : string UUID of instance wait : bool optional, call will block until FDU is stopeed returns ------- string ''' node = self.connector.glob.actual.get_fdu_instance_node( self.sysid, self.tenantid, instanceid) if node is None: raise ValueError('Unable to find node for this instanceid') record = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, node, instanceid) record = InfraFDU(record) record.set_status('STOP') fduid = record.get_fdu_id() res = self.connector.glob.desired.add_node_fdu(self.sysid, self.tenantid, node, fduid, instanceid, record.to_json()) if wait: self.__wait_node_fdu_state_change(instanceid, 'CONFIGURE') return instanceid
def undefine(self, instanceid): ''' Undefines the given instance paremeters ---------- instanceid : string UUID of instance returns ------- string ''' node = self.connector.glob.actual.get_fdu_instance_node(self.sysid, self.tenantid, instanceid) if node is None: raise ValueError('Unable to find node for this instanceid') record = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, node, instanceid) record = InfraFDU(record) record.set_status('UNDEFINE') fduid = record.get_fdu_id() self.connector.glob.desired.add_node_fdu(self.sysid, self.tenantid, node, fduid, instanceid, record.to_json()) return instanceid
def define(self, fduid, node_uuid, wait=True): ''' Defines the given fdu in the given node Instance UUID is system-wide unique parameters ---------- fduid : string UUID of the FDU node_uuid : string UUID of the node wait : bool optional, call will block until FDU is defined returns ------- InfraFDU ''' desc = self.connector.glob.actual.get_catalog_fdu_info( self.sysid, self.tenantid, fduid) if desc is None: raise ValueError('FDU with this UUID not found in the catalog') res = self.connector.glob.actual.define_fdu_in_node(self.sysid, self.tenantid, node_uuid, fduid) if res.get('error') is not None: raise ValueError('Got Error {}'.format(res['error'])) if wait: self.__wait_node_fdu_state_change(res['result']['uuid'],'DEFINE') return InfraFDU(res['result'])
def resume(self, instanceid, wait=True): ''' Resume an FDU instance :param instanceid: FDU instance you want to resume :param wait: make the function blocking :return: instanceid ''' node = self.connector.glob.actual.get_fdu_instance_node( self.sysid, self.tenantid, instanceid) if node is None: raise ValueError('Unable to find node for this instanceid') record = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, node, instanceid) record = InfraFDU(record) record.set_status('RESUME') fduid = record.get_fdu_id() res = self.connector.glob.desired.add_node_fdu( self.sysid, self.tenantid, node, fduid, instanceid, record.to_json()) if wait: self.__wait_node_fdu_state_change(instanceid, 'RUN') return res
def undefine(self, instanceid, wait=True): ''' This method undefine an FDU instance from a None :param instanceid: FDU instance you want to undefine :param wait: if wait before returning that the entity is undefined :return: instanceid ''' node = self.connector.glob.actual.get_fdu_instance_node( self.sysid, self.tenantid, instanceid) if node is None: raise ValueError('Unable to find node for this instanceid') record = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, node, instanceid) record = InfraFDU(record) record.set_status('UNDEFINE') fduid = record.get_fdu_id() self.connector.glob.desired.add_node_fdu(self.sysid, self.tenantid, node, fduid, instanceid, record.to_json()) return instanceid
def migrate(self, instanceid, destination_node_uuid, wait=True): ''' Migrates the given instance paremeters ---------- instanceid : string UUID of instance destination_node_uuid : string UUID of destination node wait : bool optional, call will block until FDU is migrated returns ------- string ''' node = self.connector.glob.actual.get_fdu_instance_node( self.sysid, self.tenantid, instanceid) if node is None: raise ValueError('Unable to find node for this instanceid') record = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, node, instanceid) src_record = InfraFDU(record) dst_record = InfraFDU(record) fduid = record.get_fdu_id() src_record.set_status('TAKE_OFF') dst_record.set_status('LAND') src_record.set_migration_properties(node, destination_node_uuid) dst_record.set_migration_properties(node, destination_node_uuid) self.connector.glob.desired.add_node_fdu(self.sysid, self.tenantid, destination_node_uuid, fduid, instanceid, dst_record.to_json()) self.connector.glob.desired.add_node_fdu(self.sysid, self.tenantid, node, fduid, instanceid, src_record.to_json()) if wait: self.__wait_node_fdu_state_change(instanceid, 'RUN') return instanceid
def migrate(self, instanceid, destination_node_uuid, wait=True): ''' Live migrate an instance between two nodes The migration is issued when this command is sended, there is a little overhead for the copy of the base image and the disk image :param instanceid: fdu you want to migrate :param destination_node_uuid: destination node :param wait: optional wait before returning :return: instanceid ''' node = self.connector.glob.actual.get_fdu_instance_node( self.sysid, self.tenantid, instanceid) if node is None: raise ValueError('Unable to find node for this instanceid') record = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, node, instanceid) src_record = InfraFDU(record) dst_record = InfraFDU(record) fduid = record.get_fdu_id() src_record.set_status('TAKE_OFF') dst_record.set_status('LAND') src_record.set_migration_properties(node, destination_node_uuid) dst_record.set_migration_properties(node, destination_node_uuid) self.connector.glob.desired.add_node_fdu(self.sysid, self.tenantid, destination_node_uuid, fduid, instanceid, dst_record.to_json()) self.connector.glob.desired.add_node_fdu(self.sysid, self.tenantid, node, fduid, instanceid, src_record.to_json()) if wait: self.__wait_node_fdu_state_change(instanceid, 'RUN') return instanceid
def update_fdu_status(self, fdu_uuid, instance_uuid, status): record = self.connector.loc.actual.get_node_fdu( self.node, self.uuid, fdu_uuid, instance_uuid) if record is None: record = self.connector.loc.desired.get_node_fdu( self.node, self.uuid, fdu_uuid, instance_uuid) record = InfraFDU(record) record.set_status(status) self.connector.loc.actual.add_node_fdu(self.node, self.uuid, fdu_uuid, instance_uuid, record.to_json())
def write_fdu_error(self, fdu_uuid, instance_uuid, errno, errmsg): record = self.connector.loc.actual.get_node_fdu( self.node, self.uuid, fdu_uuid, instance_uuid) if record is None: record = self.connector.loc.desired.get_node_fdu( self.node, self.uuid, fdu_uuid, instance_uuid) record = InfraFDU(record) record.set_status('ERROR') record.set_error_code(errno) record.set_error_msg('{}'.format(errmsg)) self.connector.loc.actual.add_node_fdu(self.node, self.uuid, fdu_uuid, instance_uuid, record.to_json())
def instance_info(self, instanceid): ''' Information about an instance :param instanceid: instance id :return dict containing the fdu record and hypervisor informations ''' data = self.connector.glob.actual.get_node_fdu_instance( self.sysid, self.tenantid, "*", instanceid) fdu = InfraFDU(data) return fdu
def instance_info(self, instanceid): ''' Gets information about the given instance parameters ---------- instanceid : string UUID of the instance returns ------- InfraFDU ''' data = self.connector.glob.actual.get_node_fdu_instance(self.sysid, self.tenantid, '*', instanceid) fdu = InfraFDU(data) return fdu
def __init__(self, data=None): ''' Constructor for the FDU Descriptor :param data dictionary containing the FDU descriptor :return the FDU object ''' self.ae = infra_atomic_entity.infra_atomic_entity() self.encoder = pybindJSONEncoder() self.atomic_entity_id = None self.uuid = None self.fdus = [] self.internal_virtual_links = [] self.connection_points = [] self.depends_on = [] if data is not None: def conv(x): x['properties'] = json.dumps(x['properties']) return x cdata = copy.deepcopy(data) xs = list(map(conv, cdata['connection_points'])) cdata['connection_points'] = xs pybindJSONDecoder.load_ietf_json({'ae_record': cdata}, None, None, obj=self.ae) self.enforce() self.atomic_entity_id = self.ae.ae_record.atomic_entity_id self.uuid = self.ae.ae_record.uuid self.fdus = [InfraFDU(x) for x in data.get('fdus')] self.internal_virtual_links = data.get('internal_virtual_links') self.connection_points = data.get('connection_points') self.depends_on = data.get('depends_on')
def update_fdu_status(self, fdu_uuid, instance_uuid, status): ''' Updates the status of the given FDU instance in YAKS parameters ---------- fdu_uuid : string UUID of the FDU instance_uuid : string UUID of the instance status : string New status of the instance ''' record = self.connector.loc.actual.get_node_fdu( self.node, self.uuid, fdu_uuid, instance_uuid) if record is None: record = self.connector.loc.desired.get_node_fdu( self.node, self.uuid, fdu_uuid, instance_uuid) record = InfraFDU(record) record.set_status(status) self.connector.loc.actual.add_node_fdu(self.node, self.uuid, fdu_uuid, instance_uuid, record.to_json())