/** Replace an existing Instance from inst, using object-path op as reference. */ CMPIStatus TestInstanceProviderModifyInstance ( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const CMPIInstance * ci, const char **properties) { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIInstance * inst; CMPIValue val1, val2; CMPIData key1, key2, retData1, retInst; CMPIObjectPath *obp; unsigned int j = 0, flag = 0; if(ci) { inst = CMClone(ci, &rc); /* get key from the object-path */ key1 = CMGetKey(cop, "Identifier", &rc); val1.uint8 = key1.value.uint8; /* get the value of Message property */ retData1 = CMGetProperty(inst, "Message", &rc); val2.string = retData1.value.string; for (j=0; j < numOfInst; j++) { /* check for validity of Instance, that its not deleted */ if (valid[j] == 1) { /* get element(instance) from array */ retInst = CMGetArrayElementAt(clone_arr_ptr, j, &rc); /* get object-path of instance */ obp = CMGetObjectPath(retInst.value.inst, &rc); /* get key from this object-path */ key2 = CMGetKey(obp, "Identifier", &rc); /*compare key values. If they match then set the properties received from client */ if(key1.value.uint8 == key2.value.uint8) { CMSetProperty( retInst.value.inst, "Message", &val2, CMPI_string); flag = 1; } } } CMRelease(inst); /*If match fails, throw exception, as instance to be mmodified is not found */ if(!flag) { CMReturn (CMPI_RC_ERR_NOT_FOUND); } } CMReturnDone (rslt); CMReturn (CMPI_RC_OK); }
CMPIStatus TestInstanceProviderDeleteInstance ( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * result, const CMPIObjectPath * cop) { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIData key1, key2, retInst; CMPIObjectPath *obp; unsigned int j = 0, flag = 0; /* get key from the object-path */ key1 = CMGetKey(cop, "Identifier", &rc); for (j=0; j < numOfInst ; j++) { /*check for validity of Instance, that its not deleted */ if(valid[j] == 1) { /*get element(instance) from array */ retInst = CMGetArrayElementAt(clone_arr_ptr, j, &rc); /*get object-path of instance */ obp = CMGetObjectPath(retInst.value.inst, &rc); /*get key from this object-path */ key2 = CMGetKey(obp, "Identifier" , &rc); /*compare key values. If they match, release the object(instance) Also set its validity to zero, marking it as deleted */ if (key1.value.uint8 == key2.value.uint8) { if(retInst.value.inst) { flag =1; CMRelease(retInst.value.inst); CMSetArrayElementAt( clone_arr_ptr, j, &retInst.value.inst, CMPI_null); valid[j] = 0; } } } } if(!flag) { CMReturn (CMPI_RC_ERR_NOT_FOUND); } CMReturn (CMPI_RC_OK); }
CMPIStatus CWS_DirectoryGetInstance( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const char ** properties) { CMPIInstance *in = NULL; CMPIStatus st = {CMPI_RC_OK,NULL}; CMPIData nd = CMGetKey(cop,"Name",&st); CWS_FILE filebuf; if (!silentMode()) fprintf(stderr,"--- CWS_DirectoryGetInstance() \n"); if (st.rc == CMPI_RC_OK && nd.type == CMPI_string && CWS_Get_File(CMGetCharsPtr(nd.value.string, NULL),&filebuf)) in = makeInstance(_broker, LOCALCLASSNAME, CMGetCharsPtr(CMGetNameSpace(cop,NULL), NULL), &filebuf); if (CMIsNullObject(in)) { CMSetStatusWithChars(_broker, &st, CMPI_RC_ERR_FAILED, "Could not find or construct instance"); } else { CMReturnInstance(rslt,in); CMReturnDone(rslt); } return st; }
/** Create Instance from inst, using object-path op as reference. */ CMPIStatus TestInstanceProviderCreateInstance ( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const CMPIInstance * ci) { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIInstance * inst; CMPIValue value_inst; CMPIData key1,key2, retInst; CMPIObjectPath *obp; unsigned int j = 0; if(ci) { /* clone the instance to be added to the array */ inst = CMClone(ci, &rc); key1 = CMGetProperty(inst, "Identifier", &rc); for (j=0; j < numOfInst ; j++) { /* check for validity of Instance, that its not deleted */ if (valid[j] == 1) { /* get element(instance) from array */ retInst = CMGetArrayElementAt(clone_arr_ptr, j, &rc); /* get object-path of instance */ obp = CMGetObjectPath(retInst.value.inst, &rc); /* get key from this object-path */ key2 = CMGetKey(obp, "Identifier", &rc); /*compare key values. If they match throw exception as two instance with same key properties cannot exists. */ if(key1.value.uint8 == key2.value.uint8) { CMRelease(inst); CMReturn (CMPI_RC_ERR_ALREADY_EXISTS); } } } value_inst.inst = inst; /* If instance doesnot exists in array add it */ rc = CMSetArrayElementAt( clone_arr_ptr, numOfInst, &value_inst, CMPI_instance); valid[numOfInst]=1; numOfInst++; /* return object-path of instance */ CMReturnObjectPath(rslt, cop); CMReturnDone(rslt); } else { CMReturn (CMPI_RC_ERR_NOT_SUPPORTED); } CMRelease(inst); CMReturn (CMPI_RC_OK); }
/** Get the Instances defined by object-path op. */ CMPIStatus TestInstanceProviderGetInstance ( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * op, const char **properties) { CMPIData data,key1,key2; CMPIObjectPath *local; unsigned int j = 0; CMPIBoolean flag = 0; CMPIStatus rc = {CMPI_RC_OK, NULL}; /* get the kay from object-path */ key1 = CMGetKey(op, "Identifier", &rc); /* get the element from array containing created instances */ for(j = 0; j < numOfInst; j++) { /* check for validity of Instance, that its not deleted */ if (valid[j] == 1) { /* get element(instance) from array */ data = CMGetArrayElementAt(clone_arr_ptr, j, &rc); /* get object-path of instance */ local = CMGetObjectPath(data.value.inst, &rc); /* get key from this object-path */ key2 = CMGetKey(local, "Identifier", &rc); /* compare key values. If they match return instance */ if (key1.value.uint8 == key2.value.uint8) { CMReturnInstance(rslt, data.value.inst); flag =1; } } } /* key values did not match so throw exception */ if(!flag) { CMReturn (CMPI_RC_ERR_NOT_FOUND); } CMReturnDone (rslt); CMReturn (CMPI_RC_OK); }
/* Get the Instances defined by <op>. Parameters: mi - Provider this pointer. ctx - Invocation Context. rslt - Result data container. cop - ObjectPath containing namespace, classname and key components. properties - If not NULL, the members of the array define one or more Property names. Each returned Object MUST NOT include elements for any Properties missing from this list. Returns: Function return status. The following CMPIrc codes shall be recognized: CMPI_RC_OK Operation successful. CMPI_RC_ERR_FAILED Unspecific error occurred. CMPI_RC_ERR_NOT_SUPPORTED Operation not supported by this MI. CMPI_RC_ERR_ACCESS_DENIED Not authorized. CMPI_RC_ERR_NOT_FOUND Instance not found. */ CMPIStatus GK_TestGetInstance( CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * cop, char ** properties) { const CMPIInstance * ci = NULL; CMPIStatus rc = {CMPI_RC_OK, NULL}; CMPIString * instanceId = NULL; printf("--- %s CMPI GetInstance() called",_ClassName); instanceId = CMGetKey( cop, "InstanceID", &rc).value.string; if( instanceId == NULL ) { CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_FOUND, "Could not get InstanceID." ); goto exit; } if ( strcmp(CMGetCharPtr(instanceId),_InstanceID) != 0){ CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_FOUND, "This class name does not exist (wrong InstanceID)." ); goto exit; } ci = _makeInst_GK_Test(cop, &rc ); if( ci == NULL ){ CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_FAILED, "Couldn't build instance"); goto exit; } CMReturnInstance( rslt, ci ); CMReturnDone(rslt); exit: return rc; }
CMPIBoolean KMatch(const CMPIObjectPath* cop1, const CMPIObjectPath* cop2) { CMPIStatus st = KSTATUS_INIT; CMPICount count1; CMPICount count2; CMPICount i; if (!cop1 || !cop2) return 0; count1 = CMGetKeyCount(cop1, &st); if (!KOkay(st)) return 0; count2 = CMGetKeyCount(cop2, &st); if (!KOkay(st)) return 0; if (count1 != count2) return 0; for (i = 0; i < count1; i++) { CMPIData cd1; CMPIData cd2; CMPIString* pn; cd1 = CMGetKeyAt(cop1, i, &pn, &st); if (!KOkay(st) || !pn) return 0; cd2 = CMGetKey(cop2, KChars(pn), &st); if (!KOkay(st)) return 0; if (!_match_key(&cd1, &cd2)) return 0; } /* Identicial */ return 1; }
/****************************************************************************** * Provider export function * Execute an extrinsic method on the specified CIM instance. *****************************************************************************/ static CMPIStatus xen_resource_invoke_method( CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self') */ const CMPIBroker *broker, /* [in] CMPI Factory services */ const CMPIContext * context, /* [in] Additional context info, if any */ const CMPIResult * results, /* [out] Results of this operation */ const CMPIObjectPath * reference, /* [in] Contains the CIM namespace, classname and desired object path */ const char * methodname, /* [in] Name of the method to apply against the reference object */ const CMPIArgs * argsin, /* [in] Method input arguments */ CMPIArgs * argsout) /* [in] Method output arguments */ { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ char * nameSpace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ unsigned long rc = 0; CMPIData argdata; xen_utils_session * session = NULL; _SBLIM_ENTER("InvokeMethod"); _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("--- self=\"%s\"", self->ft->miName)); _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("--- methodname=\"%s\"", methodname)); _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("--- namespace=\"%s\"", nameSpace)); struct xen_call_context *ctx = NULL; if(!xen_utils_get_call_context(context, &ctx, &status)){ goto Exit; } if (!xen_utils_validate_session(&session, ctx)) { CMSetStatusWithChars(broker, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to Xen"); goto Exit; } int argcount = CMGetArgCount(argsin, NULL); _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("--- argsin=%d", argcount)); argdata = CMGetKey(reference, "Name", &status); if((status.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) { _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("Couldnt find the Virtual System Migration Service to invoke method on")); goto Exit; } /* Check that the method has the correct number of arguments. */ if(strcmp(methodname, "MigrateVirtualSystemToHost") == 0) { rc = MigrateVirtualSystem(broker, context, argsin, argsout, session, true, false, &status); //CMPIObjectPath* job_instance_op = NULL; //CMAddArg(argsout, "Job", (CMPIValue *)&job_instance_op, CMPI_ref); } else if(strcmp(methodname, "MigrateVirtualSystemToSystem") == 0) { rc = MigrateVirtualSystem(broker, context, argsin, argsout, session, false, false, &status); //CMPIObjectPath* job_instance_op = NULL; //CMAddArg(argsout, "Job", (CMPIValue *)&job_instance_op, CMPI_ref); //CMPIObjectPath* newcomputersystem_instance_op = NULL; //CMAddArg(argsout, "NewComputerSystem", (CMPIValue *)&newcomputersystem_instance_op, CMPI_ref); } else if(strcmp(methodname, "CheckVirtualSystemIsMigratableToHost") == 0) { rc = MigrateVirtualSystem(broker, context, argsin, argsout, session, true, true, &status); } else if(strcmp(methodname, "CheckVirtualSystemIsMigratableToSystem") == 0) { rc = MigrateVirtualSystem(broker, context, argsin, argsout, session, false, true, &status); } else status.rc = CMPI_RC_ERR_METHOD_NOT_FOUND; Exit: if(session) xen_utils_cleanup_session(session); if(ctx) xen_utils_free_call_context(ctx); CMReturnData(results, (CMPIValue *)&rc, CMPI_uint32); CMReturnDone(results); _SBLIM_RETURNSTATUS(status); }
/****************************************************************************** * checks for migratability or actually does the migration ******************************************************************************/ int MigrateVirtualSystem( const CMPIBroker *broker, /* in - CMPI Broker that does most of the work */ const CMPIContext *context, /* in - CMPI context for the caller */ const CMPIArgs *argsin, /* in - All the arguments for the method */ const CMPIArgs *argsout, /* out - All the output arguments for the method */ xen_utils_session *session, /* in - Session for making xen calls */ bool host_ip, /* in - The host parameter is an IP address */ bool migrate_check_only, /* in -Check if migration is possible only, dont actually migrate */ CMPIStatus *status) /* out - Report CMPI status of method */ { char *hostid = NULL, *vm_uuid = NULL; CMPIData argdata; xen_vm vm = NULL; xen_host_set *host_set = NULL; CMPIInstance *msd = NULL; xen_host host = NULL; int rc = Xen_VirtualSystemMigrationService_MigrateVirtualSystemToSystem_Invalid_Parameter; CMPIrc statusrc = CMPI_RC_ERR_INVALID_PARAMETER; char *error_msg = "ERROR: Unknown error"; xen_string_string_map *other_config=NULL; /* For now only Live migrations are supported */ if(_GetArgument(broker, argsin, "MigrationSettingData", CMPI_chars, &argdata, status)) { /* Argument passed in as a MOF string, parse it */ msd = xen_utils_parse_embedded_instance(broker, CMGetCharPtr(argdata.value.string)); if (msd == NULL) { // parser returns zero for success, non-zero for error error_msg = "ERROR: Couldnt parse the 'MigrationSettingData' parameter"; goto Exit; } } else /* Argument could have been passed in as an intance */ if(_GetArgument(broker, argsin, "MigrationSettingData", CMPI_instance, &argdata, status)) msd = argdata.value.inst; if(msd != NULL) { CMPIData data = CMGetProperty(msd, "MigrationType", status); if(data.value.uint16 != Xen_VirtualSystemMigrationSettingData_MigrationType_Live) { error_msg = "ERROR: 'MigrationSettingData' contains an invalid MigrationType (Live expected)"; goto Exit; } } /* Host to migrate to */ if(!host_ip) { /* required parameters */ if(!_GetArgument(broker, argsin, "DestinationSystem", CMPI_ref, &argdata, status)){ error_msg = "ERROR: 'DestionationSystem' parameter is missing"; goto Exit; } else { /* This is the CIM reference to an existing Host object */ CMPIData key; key = CMGetKey(argdata.value.ref, "Name", status); if(status->rc != CMPI_RC_OK || CMIsNullValue(key)) { error_msg = "ERROR: 'DestinationSystem' is missing the required 'Name' key"; goto Exit; } hostid = CMGetCharPtr(key.value.string); if(!xen_host_get_by_uuid(session->xen, &host, hostid)) goto Exit; } } else { if(!_GetArgument(broker, argsin, "DestinationHost", CMPI_string, &argdata, status)) { error_msg = "ERROR: 'DestinationHost' parameter is missing"; goto Exit; } else { /* Determing Xen host based on IP address,. Cannot use inet_pton() and so on since DNS may not have been configured properly */ hostid = CMGetCharPtr(argdata.value.string); _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("Trying to migrate to DestinationHost : %s", hostid)); if(!xen_host_get_all(session->xen, &host_set)) goto Exit; int i=0; for (i=0; i<host_set->size; i++) { xen_host_record *host_rec = NULL; if(!xen_host_get_record(session->xen, &host_rec, host_set->contents[i])) goto Exit; /* DestinationHost could be an IP address or the hostname */ if((host_rec->address && (strcmp(hostid, host_rec->address) == 0)) || (host_rec->hostname && (strcmp(hostid, host_rec->hostname) == 0)) || (host_rec->name_label && (strcmp(hostid, host_rec->name_label) == 0))) { xen_host_record_free(host_rec); host = host_set->contents[i]; host_set->contents[i] = NULL; /* dont free this one */ break; } xen_host_record_free(host_rec); } } } /* VM to migrate - required parameter */ if(!_GetArgument(broker, argsin, "ComputerSystem", CMPI_ref, &argdata, status)) { if(!_GetArgument(broker, argsin, "ComputerSystem", CMPI_string, &argdata, status)) { error_msg = "ERROR: Missing the required 'ComputerSystem' parameter"; goto Exit; } else vm_uuid = CMGetCharPtr(argdata.value.string); } else { argdata = CMGetKey(argdata.value.ref, "Name", status); if(status->rc != CMPI_RC_OK || CMIsNullValue(argdata)) { error_msg = "ERROR: ComputerSystem is missing the required 'Name' key"; goto Exit; } vm_uuid = CMGetCharPtr(argdata.value.string); } status->rc = CMPI_RC_ERR_FAILED; rc = Xen_VirtualSystemMigrationService_MigrateVirtualSystemToSystem_Failed; if(xen_vm_get_by_uuid(session->xen, &vm, vm_uuid)) { _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("Migrating %s to %s", vm_uuid, hostid)); if(migrate_check_only) { /* Check to see if migration is possible */ statusrc = CMPI_RC_OK; rc = Xen_VirtualSystemMigrationService_MigrateVirtualSystemToSystem_Completed_with_No_Error; bool migratable = xen_vm_assert_can_boot_here(session->xen, vm, host); if(migratable == false || !session->xen->ok) { migratable = false; // Workaround for kvp migration if(session->xen->error_description_count==1) { if(xen_vm_get_other_config(session->xen, &other_config, vm)) { if(xen_utils_get_from_string_string_map(other_config, "kvp_enabled")) { _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("Overwriting migratable to mark kvp vm as migratable, although its network")); migratable=true; RESET_XEN_ERROR(session->xen); } free(other_config); } else { _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("Could not get other config.")); } } if(migratable == false && session->xen->error_description) { /* This is not part of the MOF (and is not documented), but nice to have */ char *xen_error = xen_utils_get_xen_error(session->xen); CMAddArg(argsout, "Reason", (CMPIValue *)xen_error, CMPI_chars); free(xen_error); } } CMAddArg(argsout, "IsMigratable", (CMPIValue *)&migratable, CMPI_boolean); } else { /* Do the actual migration, this could take a few minutes */ CMPIObjectPath* job_instance_op = NULL; migrate_job_context *job_context = calloc(1, sizeof(migrate_job_context)); if(!job_context) { error_msg = "ERROR: Couldn't allocate memory for the migrate job."; goto Exit; } job_context->vm = vm; job_context->host = host; if(!job_create(broker, context, session, MIGRATE_VM_TASK_NAME, vm_uuid, migrate_task, job_context, &job_instance_op, status)) { error_msg = "ERROR: Couldn't prepare the Migrate job. Job wasnt started."; goto Exit; } statusrc = CMPI_RC_OK; rc = Xen_VirtualSystemMigrationService_MigrateVirtualSystemToHost_Method_Parameters_Checked___Job_Started; CMAddArg(argsout, "Job", (CMPIValue *)&job_instance_op, CMPI_ref); vm = NULL; /* freed by async thread */ host = NULL; /* freed by async thread */ } } Exit: if(host) xen_host_free(host); if(vm) xen_vm_free(vm); if(host_set) xen_host_set_free(host_set); xen_utils_set_status(broker, status, statusrc, error_msg, session->xen); return rc; }
int assoc_ServiceProcess( const CMPIBroker * _broker, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * ref, int assocType, CMPIStatus * rc ) { CMPIString * sourceClass = NULL; CMPIData serviceName; CMPIObjectPath * op = NULL; CMPIObjectPath * rop = NULL; CMPIInstance * rci = NULL; CMPIInstance * sci = NULL; LXS_Handle lhdl; LXS_Service * lxssvc = NULL; int i = 0; _OSBASE_TRACE(2,("--- assoc_ServiceProcess() called")); /* check if source instance does exist */ sci = CBGetInstance(_broker, ctx, ref, NULL, rc); if( sci == NULL ) { if( rc->rc == CMPI_RC_ERR_FAILED ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "GetInstance of source object failed."); } if( rc->rc == CMPI_RC_ERR_NOT_FOUND ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_NOT_FOUND, "Source object not found."); } _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg))); return -1; } sourceClass = CMGetClassName(ref, rc); if (CMGetCharPtr(sourceClass) == NULL) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Could not get source class name."); _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg))); return -1; } /* source class is Linux_UnixProcess; target class is Linux_Service */ if( strcasecmp(CMGetCharPtr(sourceClass),_RefRightClass) == 0 ) { /* NOT_SUPPORTED - association is uni-directional */ } /* source class is Linux_Service; target class is Linux_UnixProcess */ else if( strcasecmp(CMGetCharPtr(sourceClass),_RefLeftClass) == 0 ) { serviceName = CMGetKey(ref, "Name", rc); if( serviceName.value.string == NULL ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Could not get Name of Service" ); _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg))); return -1; } lhdl=LXS_InitFiltered(CMGetCharPtr(serviceName.value.string)); if (lhdl==NULL) { _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited : Could not find associated Service.")); return 0; } lxssvc=LXS_Next(lhdl); if (lxssvc==NULL) { _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited : Could not find associated Service.")); return 0; } /* get the list of associated processe */ for (i=0;lxssvc->svProcesses[i]!=NULL;i++) { op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)), _RefRightClass, rc ); if( CMIsNullObject(op) ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." ); _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg))); return -1; } CMAddKey(op, "CSCreationClassName", CSCreationClassName, CMPI_chars); CMAddKey(op, "CSName", get_system_name(), CMPI_chars); CMAddKey(op, "OSCreationClassName", OSCreationClassName, CMPI_chars); CMAddKey(op, "OSName", get_os_name(), CMPI_chars); CMAddKey(op, "CreationClassName", _RefRightClass, CMPI_chars); CMAddKey(op, "Handle", lxssvc->svProcesses[i], CMPI_chars); if (assocType&ATYPE_ASSOC) { /* the process (name) */ if (assocType&ATYPE_NAME) { CMReturnObjectPath(rslt, op); } else { rci = CBGetInstance(_broker, ctx, op, NULL, rc); if(rci==NULL) { return -1; } CMReturnInstance( rslt, rci ); } } else { /* the reference object (name) */ if (assocType&ATYPE_NAME) { rop = _makePath_ServiceProcess(_broker, ref, op, rc); CMReturnObjectPath(rslt, rop); } else { rci = _makeInst_ServiceProcess(_broker, ref, op, rc); CMReturnInstance( rslt, rci ); } } } LXS_Term(lhdl); } _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited")); return 0; }
/****************************************************************************** * disk_rasd_to_vbd * * This function attempts to parse a Xen_Disk CIM instance and populate a new * VBD record. It also gets the record to the VDI that the VBD attaches to (could * be a newly created VDI, if requested) and a handle to an existing SR as * pointed to by the PoolID field in the CIM instance * * Returns 1 on Success and 0 on failure. *******************************************************************************/ int disk_rasd_to_vbd( const CMPIBroker *broker, xen_utils_session* session, CMPIInstance *disk_rasd, xen_vbd_record **vbd_rec, xen_vdi_record **vdi_rec, xen_sr *sr, CMPIStatus *status) { CMPIData propertyvalue; char *error_msg = "ERROR: Unknown error"; char *sr_label = NULL, *vdi_name_label = NULL, *vdi_name_desc = NULL; char *vbd_device = NULL, *vbd_uuid = NULL, *vdi_uuid = NULL; enum xen_vbd_type vbd_type = XEN_VBD_TYPE_DISK; /* default with Disk (as opposed to CDRom) */ enum xen_vdi_type vdi_type = XEN_VDI_TYPE_USER; bool vbd_readonly = false, vbd_bootable = false;/* defaults for Disk type */ int vbd_mode= XEN_VBD_MODE_RW; /* defaults for Disk type */ int64_t disk_size = -1; /* for CDRoms - this is the size expected */ char buf[MAX_INSTANCEID_LEN]; *vbd_rec = NULL; *vdi_rec = NULL; /* only resource types of 15,16 and 19 are currently supported */ int rc = CMPI_RC_ERR_INVALID_PARAMETER; propertyvalue = CMGetProperty(disk_rasd, "ResourceType", status); if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) { error_msg = "ERROR: Xen_DiskSettingData has no ResourceType"; goto Error; } int res_type = propertyvalue.value.uint16; if ((res_type == DMTF_ResourceType_CD_Drive) || (res_type == DMTF_ResourceType_DVD_drive)) { vbd_mode = XEN_VBD_MODE_RO; vbd_type = XEN_VBD_TYPE_CD; } else if ((res_type == DMTF_ResourceType_Storage_Extent) || (res_type == DMTF_ResourceType_Disk_Drive)) vbd_type = XEN_VBD_TYPE_DISK; else { error_msg = "ERROR: Xen_DiskSettingData has unsupported ResourceType"; goto Error; } /* Get the instance ID which has the device's UUID in it, if its available This will be usd during deletes and not used during create*/ propertyvalue = CMGetProperty(disk_rasd, "InstanceID", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) { _CMPIStrncpyDeviceNameFromID(buf, CMGetCharPtr(propertyvalue.value.string), sizeof(buf)/sizeof(buf[0])); vbd_uuid = strdup(buf); } /* The HostResource property is used to identify the VDI, if available */ propertyvalue = CMGetProperty(disk_rasd, "HostResource", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) { /* HostResource is always in WBEM URI format and it points to a Xen_DiskImage object reference. Convert it to CMPIObjectPath */ CMPIData data = CMGetArrayElementAt(propertyvalue.value.array, 0, NULL); CMPIObjectPath *obj_path = xen_utils_WBEM_URI_to_CMPIObjectPath( broker, CMGetCharPtr(data.value.string)); if (obj_path) { /* this should be a Xen_DiskImage object reference */ /* Get the DeviceID key */ propertyvalue = CMGetKey(obj_path, "DeviceID", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue) && propertyvalue.type == CMPI_string) { memset(buf, 0, sizeof(buf)); _CMPIStrncpyDeviceNameFromID(buf, CMGetCharPtr(propertyvalue.value.string), sizeof(buf)/sizeof(buf[0])); vdi_uuid = strdup(buf); } } } if (!vdi_uuid) { /* second chance, Try the HostExtentName */ propertyvalue = CMGetProperty(disk_rasd, "HostExtentName", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) vdi_uuid = strdup(CMGetCharPtr(propertyvalue.value.string)); } /* Device is specified as the address on the host bus */ propertyvalue = CMGetProperty(disk_rasd, "AddressOnParent", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) vbd_device = strdup(CMGetCharPtr(propertyvalue.value.string)); propertyvalue = CMGetProperty(disk_rasd, "Bootable", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) vbd_bootable = propertyvalue.value.boolean; propertyvalue = CMGetProperty(disk_rasd, "Access", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) { if (propertyvalue.value.uint16 == Access_Readable) vbd_mode = XEN_VBD_MODE_RO; } /* * The Pool ID property is used to identify the Xen SR * This could be NULL if VDIs are reused or if * the VBD has to be created on the default SR. */ propertyvalue = CMGetProperty(disk_rasd, "PoolID", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) { char *poolid = CMGetCharPtr(propertyvalue.value.string); if (poolid && (*poolid != '\0')) sr_label = strdup(poolid); } propertyvalue = CMGetProperty(disk_rasd, "ElementName", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) vdi_name_label = strdup(CMGetCharPtr(propertyvalue.value.string)); propertyvalue = CMGetProperty(disk_rasd, "Description", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) vdi_name_desc = strdup(CMGetCharPtr(propertyvalue.value.string)); /* Get the disk size from the CIM instance - * If this is a new disk, this property is required * If we are instantiating a CDRom VDI, this is not required */ int64_t multiplier = 1; /* default to bytes */ propertyvalue = CMGetProperty(disk_rasd, "AllocationUnits", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) { char *units = CMGetCharPtr(propertyvalue.value.string); if ((multiplier = xen_utils_get_alloc_units(units)) == 0) { error_msg = "ERROR: Xen_DiskSettingData has unsupported AllocationUnits"; goto Error; } } /* Limit and VirtualQuantity properties mean the same when we create the VBD */ propertyvalue = CMGetProperty(disk_rasd, "VirtualQuantity", status); if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) disk_size = (propertyvalue.value.uint64) * multiplier; if (vbd_type == XEN_VBD_TYPE_CD) vdi_type = XEN_VDI_TYPE_USER; /* We have enough information... create the Xen device records so we can */ /* create new devices or identify existing ones */ /* Create the VDI device record */ rc = CMPI_RC_ERR_FAILED; *vdi_rec = xen_vdi_record_alloc(); if (*vdi_rec == NULL) { error_msg = "ERROR: Unable to malloc memory"; goto Error; } (*vdi_rec)->virtual_size = disk_size; #if OSS_XENAPI (*vdi_rec)->other_config = xen_string_string_map_alloc(0); vdi_location = ""; (*vdi_rec)->other_config->contents[0].key= strdup("location"); (*vdi_rec)->other_config->contents[0].val = strdup(vdi_location); (*vdi_rec)->other_config->size = 1; #else (*vdi_rec)->other_config = xen_string_string_map_alloc(0); (*vdi_rec)->other_config->size = 0; #endif (*vdi_rec)->type = vdi_type; (*vdi_rec)->read_only = vbd_readonly; (*vdi_rec)->name_label = vdi_name_label; (*vdi_rec)->name_description = vdi_name_desc; #if XENAPI_VERSION > 400 (*vdi_rec)->managed = true; #endif /* If VDI has already been created, use it */ if (vdi_uuid) { _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("VDI specified in the RASD: -%s-", vdi_uuid)); (*vdi_rec)->uuid = vdi_uuid; } /* create the VBD record */ *vbd_rec = xen_vbd_record_alloc(); if (*vbd_rec == NULL) { error_msg = "ERROR: Unable to malloc memory"; goto Error; } if (vbd_uuid) (*vbd_rec)->uuid = vbd_uuid; #if XENAPI_VERSION > 400 if (vbd_device) (*vbd_rec)->userdevice = vbd_device; (*vbd_rec)->other_config = xen_string_string_map_alloc(0); #endif (*vbd_rec)->bootable = vbd_bootable; (*vbd_rec)->mode = vbd_mode; (*vbd_rec)->type = vbd_type; (*vbd_rec)->qos_algorithm_params = xen_string_string_map_alloc(0); if (vbd_type == XEN_VBD_TYPE_CD) (*vdi_rec)->sharable = true; else (*vdi_rec)->sharable = false; /* Identify the Storage Repository where this VDI will be created (if its being created) */ if (sr_label) { if (!_get_sr(broker, session, sr_label, true, sr, status)) { _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("--- getting SR for %s failed", sr_label)); goto Error; } free(sr_label); } return 1; Error: if (sr_label) free(sr_label); if (vdi_name_label) { free(vdi_name_label); if (*vdi_rec) (*vdi_rec)->name_label = NULL; } if(vdi_name_desc) { free(vdi_name_desc); } if(vbd_device) { free(vbd_device); } if(vbd_uuid) { free(vbd_uuid); } /* frees fields as well */ if (*vbd_rec) { xen_vbd_record_free(*vbd_rec); *vbd_rec = NULL; } if (*vdi_rec) { xen_vdi_record_free(*vdi_rec); *vdi_rec = NULL; } xen_utils_set_status(broker, status, rc, error_msg, session->xen); return 0; }
CMPIStatus Linux_FanProviderSetInstance( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const CMPIInstance * ci, const char ** properties) { UNUSED(mi); UNUSED(ctx); UNUSED(rslt); UNUSED(properties); CMPIStatus rc = {CMPI_RC_OK, NULL}; CMPIData data; char const * device_id = NULL; struct cim_fan * sptr; cim_fan_prop_value_t cfpv; cim_fan_error_t cmdrc; char const * tmp = NULL; char buf[200]; _OSBASE_TRACE(1, ("--- %s CMPI SetInstance() called", _ClassName)); _check_system_key_value_pairs(_broker, cop, "SystemCreationClassName", "SystemName", &rc); if (rc.rc != CMPI_RC_OK) { _OSBASE_TRACE(1, ("--- %s CMPI SetInstance() failed : %s", _ClassName, CMGetCharPtr(rc.msg))); return rc; } data = CMGetKey(cop, "DeviceID", &rc); if (data.value.string == NULL) { CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_FAILED, "Could not get fan ID." ); _OSBASE_TRACE(1, ("--- %s CMPI SetInstance() failed : %s", _ClassName, CMGetCharPtr(rc.msg))); } device_id = CMGetCharPtr(data.value.string); if (device_id) { cmdrc = get_fan_data_by_id(device_id, &sptr); } if (cmdrc || !sptr) { CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_NOT_FOUND, cim_fan_strerror(cmdrc)); _OSBASE_TRACE(1, ("--- %s CMPI SetInstance() exited : %s", _ClassName,CMGetCharPtr(rc.msg))); return rc; } data = CMGetProperty(ci, "MinSpeed", &rc); if (!rc.rc && data.value.uint64 != (uint64_t) sptr->min_speed) { tmp = "MinSpeed"; cfpv.min_speed = data.value.uint64; cmdrc = set_fan_prop_by_id(device_id, CIM_FAN_MIN_SPEED, &cfpv); } data = CMGetProperty(ci , "MaxSpeed", &rc); if (!cmdrc && !rc.rc && data.value.uint64 != (uint64_t) sptr->max_speed) { tmp = "MaxSpeed"; cfpv.max_speed = data.value.uint64; set_fan_prop_by_id(device_id, CIM_FAN_MAX_SPEED, &cfpv); } data = CMGetProperty(ci, "Divisor", &rc); if (!cmdrc && !rc.rc && data.value.uint32 != sptr->divisor) { tmp = "Divisor"; cfpv.divisor = data.value.uint32; set_fan_prop_by_id(device_id, CIM_FAN_DIV, &cfpv); } data = CMGetProperty(ci, "Pulses", &rc); if (!cmdrc && !rc.rc && data.value.uint32 != sptr->pulses) { tmp = "Pulses"; cfpv.pulses = data.value.uint32; set_fan_prop_by_id(device_id, CIM_FAN_PULSES, &cfpv); } data = CMGetProperty(ci, "Beep", &rc); if (!cmdrc && !rc.rc && data.value.boolean != sptr->beep) { tmp = "Beep"; cfpv.beep = data.value.uint32; set_fan_prop_by_id(device_id, CIM_FAN_BEEP, &cfpv); } if (cmdrc) { if (tmp && cmdrc == CIM_FAN_SEN_NO_ENTRY) { snprintf(buf, 200, "System interface for fan(name=\"%s\", chip=\"%s\") does not" " provide a way to set \"%s\".", sptr->name, sptr->chip_name, tmp); CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_FAILED, buf); }else { CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_FAILED, cim_fan_strerror(cmdrc)) } _OSBASE_TRACE(2, ("--- %s CMPI SetInstance() exited : %s", _ClassName, CMGetCharPtr(rc.msg))); }else {
CMPIStatus Linux_FanProviderGetInstance( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const char **properties) { UNUSED(mi); CMPIInstance * ci = NULL; CMPIStatus rc = {CMPI_RC_OK, NULL}; struct cim_fan * sptr = NULL; CMPIData data; CMPIArray * other_identifying_info = NULL; CMPIString * sys_path = NULL; CMPIString * fan_name = NULL; CMPIString * device_id = NULL; cim_fan_error_t cmdrc; _OSBASE_TRACE(1,("--- %s CMPI GetInstance() called",_ClassName)); _check_system_key_value_pairs(_broker, cop, "SystemCreationClassName", "SystemName", &rc); if (rc.rc != CMPI_RC_OK) { _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() failed : %s", _ClassName, CMGetCharPtr(rc.msg))); return rc; } data = CMGetKey(cop, "OtherIdentifyingInfo", &rc); if ( !rc.rc && data.type == CMPI_stringA && (other_identifying_info = data.value.array) && !rc.rc && (CMGetArrayCount(other_identifying_info, &rc) > 1) && !rc.rc) { data = CMGetArrayElementAt(other_identifying_info, 0, &rc); if (!rc.rc) sys_path = data.value.string; data = CMGetArrayElementAt(other_identifying_info, 1, &rc); if (!rc.rc) fan_name = data.value.string; } device_id = CMGetKey(cop, "DeviceID", &rc).value.string; if ((sys_path == NULL || fan_name == NULL) && (device_id == NULL)) { CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_FAILED, "Could not get fan ID." ); _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() failed : %s", _ClassName, CMGetCharPtr(rc.msg))); return rc; } if (sys_path && fan_name) { cmdrc = get_fan_data(CMGetCharPtr(sys_path), CMGetCharPtr(fan_name), &sptr); } if ((cmdrc || !sptr) && device_id) { cmdrc = get_fan_data_by_id(CMGetCharPtr(device_id), &sptr); } if (cmdrc || !sptr) { CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_NOT_FOUND, cim_fan_strerror(cmdrc)); _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() exited : %s", _ClassName,CMGetCharPtr(rc.msg))); return rc; } ci = _makeInst_Fan(_broker, ctx, cop, properties, sptr, &rc); if (sptr) free_fan(sptr); if (ci == NULL) { if (rc.msg != NULL) { _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() failed : %s", _ClassName, CMGetCharPtr(rc.msg))); }else { _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() failed", _ClassName)); } return rc; } CMReturnInstance(rslt, ci); CMReturnDone(rslt); _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() exited", _ClassName)); return rc; }
static int _testCMPIObjectPath() { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIObjectPath *objPath = NULL; CMPIObjectPath *clonedObjPath = NULL; CMPIObjectPath *otherObjPath = NULL; CMPIObjectPath *fakeObjPath = NULL; const char *hostName = "HOSTNAME"; const char *nameSpace = "root/dummy"; const char *className = "classname"; CMPIString *returnedHostname = NULL; CMPIBoolean equalHostname = 0; CMPIString *returnedNamespace = NULL; CMPIBoolean equalNamespace = 0; CMPIString *returnedClassName; CMPIBoolean equalClassName = 0; CMPIString *returnedObjectPath; CMPIBoolean cloneSuccessful = 0; CMPIBoolean getKeySuccessful = 0; CMPIBoolean getKeyCountSuccessful = 0; CMPIBoolean getKeyAtSuccessful = 0; const char *objectPath1 = NULL; const char *objectPath2 = NULL; CMPIData data; CMPIValue value; unsigned int keyCount = 0; objPath = make_ObjectPath(_broker, _Namespace, _ClassName); rc = CMSetHostname(objPath, hostName); returnedHostname = CMGetHostname(objPath, &rc); if (strcmp(hostName, CMGetCharsPtr(returnedHostname, &rc)) == 0) { equalHostname = 1; } rc = CMSetNameSpace(objPath, nameSpace); returnedNamespace = CMGetNameSpace(objPath, &rc); if (strcmp(nameSpace, CMGetCharsPtr(returnedNamespace, &rc)) == 0) { equalNamespace = 1; } rc = CMSetClassName(objPath, className); returnedClassName = CMGetClassName(objPath, &rc); if (strcmp(className, CMGetCharsPtr(returnedClassName, &rc)) == 0) { equalClassName = 1; } otherObjPath = make_ObjectPath(_broker, _Namespace, _ClassName); returnedNamespace = CMGetNameSpace(otherObjPath, &rc); rc = CMSetNameSpaceFromObjectPath(otherObjPath, objPath); returnedNamespace = CMGetNameSpace(otherObjPath, &rc); if (strcmp(nameSpace, CMGetCharsPtr(returnedNamespace, &rc)) == 0) { equalNamespace = 1; } returnedHostname = CMGetHostname(otherObjPath, &rc); rc = CMSetHostAndNameSpaceFromObjectPath(otherObjPath, objPath); returnedHostname = CMGetHostname(otherObjPath, &rc); if (strcmp(hostName, CMGetCharsPtr(returnedHostname, &rc)) == 0) { equalHostname = 1; } returnedObjectPath = CMObjectPathToString(objPath, &rc); objectPath1 = CMGetCharsPtr(returnedObjectPath, &rc); clonedObjPath = objPath->ft->clone(objPath, &rc); returnedObjectPath = CMObjectPathToString(clonedObjPath, &rc); rc = clonedObjPath->ft->release(clonedObjPath); objectPath2 = CMGetCharsPtr(returnedObjectPath, &rc); if (strcmp(objectPath1, objectPath2) == 0) { cloneSuccessful = 1; } else { cloneSuccessful = 0; } fakeObjPath = CMNewObjectPath(_broker, "root#cimv2", "Sample_Instance", &rc); rc = CMAddKey(fakeObjPath, "ElementName", (CMPIValue *) "Fake", CMPI_chars); rc = CMAddKey(otherObjPath, "ElementName1", (CMPIValue *) "otherObjPath", CMPI_chars); data = CMGetKey(fakeObjPath, "ElementName", &rc); if (strcmp(CMGetCharsPtr(data.value.string, &rc), "Fake") == 0) { getKeySuccessful = 1; } keyCount = CMGetKeyCount(fakeObjPath, &rc); if (keyCount == 1) { getKeyCountSuccessful = 1; } data = CMGetKeyAt(fakeObjPath, 0, NULL, &rc); if (rc.rc == 0) { getKeyAtSuccessful = 1; } value.uint16 = 67; rc = CMAddKey(fakeObjPath, "Numeric_key_unsigned", (CMPIValue *) & value, CMPI_uint16); data = CMGetKey(fakeObjPath, "Numeric_key_unsigned", &rc); value.sint16 = -67; rc = CMAddKey(fakeObjPath, "Numeric_key_signed", (CMPIValue *) & value, CMPI_sint16); data = CMGetKey(fakeObjPath, "Numeric_key_signed", &rc); value.boolean = 1; rc = CMAddKey(fakeObjPath, "Boolean_key", (CMPIValue *) & value, CMPI_boolean); data = CMGetKey(fakeObjPath, "Boolean_key", &rc); CMGetKeyAt(objPath, 500, NULL, &rc); if (rc.rc != CMPI_RC_ERR_NO_SUCH_PROPERTY) { return 1; } rc = objPath->ft->release(objPath); rc = fakeObjPath->ft->release(fakeObjPath); return 0; }