
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1193820858 -3600 # Node ID bd925f5f9fdacc3ed34b34eb17e348e8304ec382 # Parent 53903e7822dde586f073ffe469c544c1a37954a4 Enhance RegisteredProfile to support getInstance and gets static ID Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 53903e7822dd -r bd925f5f9fda src/Virt_RegisteredProfile.c --- a/src/Virt_RegisteredProfile.c Tue Oct 30 12:48:28 2007 +0100 +++ b/src/Virt_RegisteredProfile.c Wed Oct 31 09:54:18 2007 +0100 @@ -38,27 +38,12 @@ const static CMPIBroker *_BROKER; -static bool reg_prof_set_id(CMPIInstance *instance, - struct reg_prof *profile) -{ - char *id; - - if (asprintf(&id, "%s_%s", profile->reg_name, - profile->reg_version) == -1) - id = NULL; - - if(id) - CMSetProperty(instance, "InstanceID", - (CMPIValue *)id, CMPI_chars); - - return id != NULL; -} - CMPIInstance *reg_prof_instance(const CMPIBroker *broker, - const CMPIObjectPath *ref, + const char *namespace, + const char **properties, struct reg_prof *profile) { - CMPIStatus s; + CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIObjectPath *op; CMPIInstance *instance = NULL; char *classname; @@ -70,7 +55,7 @@ CMPIInstance *reg_prof_instance(const CM goto out; } - op = CMNewObjectPath(broker, NAMESPACE(ref), classname, &s); + op = CMNewObjectPath(broker, namespace, classname, &s); if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) goto out; @@ -78,10 +63,16 @@ CMPIInstance *reg_prof_instance(const CM if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) goto out; - reg_prof_set_id(instance, profile); - - CMSetProperty(instance, "CreationClassName", - (CMPIValue *)classname, CMPI_chars); + if (properties) { + s = CMSetPropertyFilter(instance, properties, NULL); + if (s.rc != CMPI_RC_OK) { + printf("Setting of property filter failed\n"); + goto out; + } + } + + CMSetProperty(instance, "InstanceID", + (CMPIValue *)profile->reg_id, CMPI_chars); CMSetProperty(instance, "RegisteredOrganization", (CMPIValue *)&profile->reg_org, CMPI_uint16); @@ -103,27 +94,17 @@ static CMPIStatus enum_profs(const CMPIO const char **properties, bool names_only) { + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instance; int i; - CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *instance; for (i = 0; profiles[i] != NULL; i++) { - instance = reg_prof_instance(_BROKER, ref, profiles[i]); + instance = reg_prof_instance(_BROKER, NAMESPACE(ref), properties, profiles[i]); if (instance == NULL) { CMSetStatusWithChars(_BROKER, &s, CMPI_RC_ERR_FAILED, "Can't create profile instance."); goto out; } - - if (properties) { - s = CMSetPropertyFilter(instance, properties, NULL); - if (s.rc != CMPI_RC_OK) { - CMSetStatusWithChars(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Property filter failed."); - goto out; - } - } if (names_only) cu_return_instance_name(results, instance); @@ -132,6 +113,41 @@ static CMPIStatus enum_profs(const CMPIO } out: + return s; +} + +static CMPIStatus get_prof(const CMPIObjectPath *ref, + const CMPIResult *results, + const char **properties) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instance = NULL; + char* id; + int i; + + id = cu_get_str_path(ref, "InstanceID"); + if (id == NULL) { + CMSetStatusWithChars(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "No InstanceID specified"); + return s; + } + + for (i = 0; profiles[i] != NULL; i++) { + if(STREQ(id, profiles[i]->reg_id)) { + instance = reg_prof_instance(_BROKER, NAMESPACE(ref), properties, profiles[i]); + break; + } + } + + if(instance) + CMReturnInstance(results, instance); + else + CMSetStatus(&s, CMPI_RC_ERR_NOT_FOUND); + + + free(id); + return s; } @@ -152,7 +168,15 @@ static CMPIStatus EnumInstances(CMPIInst return enum_profs(reference, results, properties, false); } -DEFAULT_GI(); +static CMPIStatus GetInstance(CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference, + const char **properties) +{ + return get_prof(reference, results, properties); +} + DEFAULT_CI(); DEFAULT_MI(); DEFAULT_DI(); diff -r 53903e7822dd -r bd925f5f9fda src/Virt_RegisteredProfile.h --- a/src/Virt_RegisteredProfile.h Tue Oct 30 12:48:28 2007 +0100 +++ b/src/Virt_RegisteredProfile.h Wed Oct 31 09:54:18 2007 +0100 @@ -22,7 +22,8 @@ #define __VIRT_REGISTERED_PROFILE_H CMPIInstance *reg_prof_instance(const CMPIBroker *broker, - const CMPIObjectPath *ref, + const char *namespace, + const char **properties, struct reg_prof *profile); #endif diff -r 53903e7822dd -r bd925f5f9fda src/profiles.h --- a/src/profiles.h Tue Oct 30 12:48:28 2007 +0100 +++ b/src/profiles.h Wed Oct 31 09:54:18 2007 +0100 @@ -20,6 +20,7 @@ */ struct reg_prof { uint16_t reg_org; // Valid: 1 = Other, 2 = DMTF + char *reg_id; char *reg_name; char *reg_version; int ad_types; @@ -28,49 +29,27 @@ struct reg_prof { char *provider_name; }; -struct reg_prof Processor = { +struct reg_prof SystemVirtualization = { .reg_org = 2, - .reg_name = "Processor Profile", - .reg_version = "2.15", - .provider_name = "Processor" + .reg_id = "DSP1042-1.0.0a", + .reg_name = "System Virtualization Profile", + .reg_version = "1.0.0a", + .provider_name = "HostSystem" }; -struct reg_prof LogicalDisk = { +struct reg_prof VirtualSystem = { .reg_org = 2, - .reg_name = "Logical Disk Profile", - .reg_version = "2.15", - .provider_name = "LogicalDisk" -}; - -struct reg_prof NetworkPort = { - .reg_org = 2, - .reg_name = "Network Port Profile", - .reg_version = "2.15", - .provider_name = "NetworkPort" -}; - -struct reg_prof ComputerSystem = { - .reg_org = 2, - .reg_name = "Computer System Profile", - .reg_version = "2.15", + .reg_id = "DSP1057-1.0.0a", + .reg_name = "Virtual System Profile", + .reg_version = "1.0.0a", .provider_name = "ComputerSystem" }; -struct reg_prof SVP = { - .reg_org = 2, - .reg_name = "System Virtualization Profile", - .reg_version = "2.15", - .provider_name = "VirtualSystemManagementService" -}; - // Make sure to add pointer to your reg_prof struct here. struct reg_prof *profiles[] = { - &Processor, - &LogicalDisk, - &NetworkPort, - &ComputerSystem, - &SVP, + &SystemVirtualization, + &VirtualSystem, NULL };