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 {} with message {}'.format( res['error'], res['error_msg'])) if wait: self.__wait_node_fdu_state_change(res['result']['uuid'], 'DEFINE') return InfraFDU(res['result'])
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())
def clean(self, instanceid, wait=True): ''' Cleans the given instance paremeters ---------- instanceid : string UUID of instance wait : bool optional, call will block until FDU is cleaned 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('CLEAN') 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, 'DEFINE') 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 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, skip_unknown=True) 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 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 __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 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 = src_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