[PATCH 0 of 2] Updates to RegisteredProfile and ElementConformsToProfile

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1193915264 -3600 # Node ID b14cdc8c5e904694b025850856a238cf7a4f93db # Parent 50cd94057045e93e7978797b0c204731191e6909 Enhance RegisteredProfile to support getInstance and gets static ID Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 50cd94057045 -r b14cdc8c5e90 src/Virt_RegisteredProfile.c --- a/src/Virt_RegisteredProfile.c Thu Nov 01 11:07:40 2007 +0100 +++ b/src/Virt_RegisteredProfile.c Thu Nov 01 12:07:44 2007 +0100 @@ -38,39 +38,22 @@ 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; classname = get_typed_class("RegisteredProfile"); if (classname == NULL) { - //TRACE(1, "Can't assemble classname."); - printf("Can't assemble classname.\n"); - goto out; - } - - op = CMNewObjectPath(broker, NAMESPACE(ref), classname, &s); + goto out; + } + + op = CMNewObjectPath(broker, namespace, classname, &s); if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) goto out; @@ -78,10 +61,15 @@ 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) { + goto out; + } + } + + CMSetProperty(instance, "InstanceID", + (CMPIValue *)profile->reg_id, CMPI_chars); CMSetProperty(instance, "RegisteredOrganization", (CMPIValue *)&profile->reg_org, CMPI_uint16); @@ -103,27 +91,20 @@ 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,44 @@ 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 +171,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 50cd94057045 -r b14cdc8c5e90 src/Virt_RegisteredProfile.h --- a/src/Virt_RegisteredProfile.h Thu Nov 01 11:07:40 2007 +0100 +++ b/src/Virt_RegisteredProfile.h Thu Nov 01 12:07:44 2007 +0100 @@ -22,8 +22,9 @@ #define __VIRT_REGISTERED_PROFILE_H CMPIInstance *reg_prof_instance(const CMPIBroker *broker, - const CMPIObjectPath *ref, - struct reg_prof *profile); + const char *namespace, + const char **properties, + struct reg_prof *profile); #endif diff -r 50cd94057045 -r b14cdc8c5e90 src/profiles.h --- a/src/profiles.h Thu Nov 01 11:07:40 2007 +0100 +++ b/src/profiles.h Thu Nov 01 12:07:44 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 };

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1193915708 -3600 # Node ID 94b0d9a380ab954890de0b4867057f2db84f17e0 # Parent b14cdc8c5e904694b025850856a238cf7a4f93db Adoption of changes in RegisteredProfile to association ElementConformsToProfile; ECTP uses upcalls to retrieve ManagedElements and minor bug fixes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r b14cdc8c5e90 -r 94b0d9a380ab src/Makefile.am --- a/src/Makefile.am Thu Nov 01 12:07:44 2007 +0100 +++ b/src/Makefile.am Thu Nov 01 12:15:08 2007 +0100 @@ -7,7 +7,6 @@ noinst_HEADERS = profiles.h svpc_types.h Virt_ComputerSystemIndication.h \ Virt_Device.h \ Virt_DevicePool.h \ - Virt_ElementConformsToProfile.h \ Virt_EnabledLogicalElementCapabilities.h \ Virt_HostSystem.h \ Virt_RASD.h \ diff -r b14cdc8c5e90 -r 94b0d9a380ab src/Virt_ElementConformsToProfile.c --- a/src/Virt_ElementConformsToProfile.c Thu Nov 01 12:07:44 2007 +0100 +++ b/src/Virt_ElementConformsToProfile.c Thu Nov 01 12:15:08 2007 +0100 @@ -35,7 +35,6 @@ #include "std_association.h" #include "Virt_RegisteredProfile.h" -#include "Virt_ElementConformsToProfile.h" /* Associate an XXX_RegisteredProfile to the proper XXX_ManagedElement. * @@ -46,75 +45,53 @@ const static CMPIBroker *_BROKER; -static CMPIStatus prof_from_ref(struct reg_prof *prof, - const CMPIObjectPath *ref) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; - char *tmp_str; - int tmp_int; - - memset(prof, 0, sizeof(*prof)); - - prof->reg_name = cu_get_str_path(ref, "RegisteredName"); - prof->reg_version = cu_get_str_path(ref, "RegisteredVersion"); - prof->other_reg_org = cu_get_str_path(ref, "OtherRegisteredOrganization"); - - tmp_str = cu_get_str_path(ref, "RegisteredOrganization"); - if (tmp_str) { - sscanf(tmp_str, "%d", &tmp_int); - prof->reg_org = (uint16_t)tmp_int; - } - - free(tmp_str); - return s; - -} - -static bool compare_profiles(struct reg_prof *target, - struct reg_prof *candidate) -{ - if (!STREQC(target->reg_name, candidate->reg_name)) - return false; - - COMPARE_OPT_STR(target, candidate, reg_version); - COMPARE_OPT_NUM(target, candidate, reg_org); - //COMPARE_OPT_NUM(target, candidate, ad_types); - COMPARE_OPT_STR(target, candidate, other_reg_org); - //COMPARE_OPT_STR(target, candidate, ad_type_descriptions); - - return true; -} - -static CMPIInstance *elem_instance(const CMPIObjectPath *ref, - char *provider_name) -{ - CMPIStatus s; +static CMPIStatus elem_instances(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list, + struct reg_prof *profile) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIObjectPath *op; - CMPIInstance *instance = NULL; + CMPIEnumeration *en = NULL; + CMPIData data ; char *classname; - classname = get_typed_class(provider_name); + classname = get_typed_class(profile->provider_name); if (classname == NULL) { - //TRACE("Can't assemble classname."); - printf("Can't assemble classname.\n"); - goto out; - } - - op = CMNewObjectPath(_BROKER, NAMESPACE(ref), classname, &s); + CMSetStatusWithChars(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Can't assemble classname." ); + goto out; + } + + op = CMNewObjectPath(_BROKER, "/root/ibmsd", classname, &s); if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) - goto out; - - instance = CMNewInstance(_BROKER, op, &s); - if ((s.rc != CMPI_RC_OK) || CMIsNullObject(instance)) - goto out; - - CMSetProperty(instance, "CreationClassName", (CMPIValue *)classname, - CMPI_chars); - - out: + goto error; + + en = CBEnumInstances(_BROKER, info->context , op, NULL, &s); + if (en == NULL) { + CMSetStatusWithChars(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Upcall enumInstances to target class failed."); + goto error; + } + + while (CMHasNext(en, &s)) { + data = CMGetNext(en, &s); + if (CMIsNullObject(data.value.inst)) { + CMSetStatusWithChars(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to retrieve enumeration entry."); + goto error; + } + + inst_list_add(list, data.value.inst); + } + + error: free(classname); - - return instance; + out: + return s; } static CMPIStatus prof_to_elem(const CMPIObjectPath *ref, @@ -122,25 +99,28 @@ static CMPIStatus prof_to_elem(const CMP struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *instance; - struct reg_prof target; - struct reg_prof *candidate; + char *id; int i; - - s = prof_from_ref(&target, ref); + + id = cu_get_str_path(ref, "InstanceID"); + if (id == NULL) { + CMSetStatusWithChars(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "No InstanceID specified"); + goto out; + } for (i = 0; profiles[i] != NULL; i++) { - candidate = profiles[i]; - if (!compare_profiles(&target, candidate)) - continue; - - instance = elem_instance(ref, candidate->provider_name); - if (instance == NULL) - goto out; - - inst_list_add(list, instance); - } - + if (STREQ(id, profiles[i]->reg_id)) { + s = elem_instances(ref, info, list, profiles[i]); + if ((s.rc != CMPI_RC_OK)) + goto error; + break; + } + } + + error: + free(id); out: return s; } @@ -152,74 +132,62 @@ static CMPIStatus elem_to_prof(const CMP CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *instance; char *classname; - char *provider_name; struct reg_prof *candidate; int i; - classname = cu_get_str_path(ref, "CreationClassName"); + classname = class_base_name(CLASSNAME(ref)); if (classname == NULL) { CMSetStatusWithChars(_BROKER, &s, CMPI_RC_ERR_FAILED, - "Can't get class name from element."); - goto error1; - } - - provider_name = class_base_name(classname); - if (provider_name == NULL) { - CMSetStatusWithChars(_BROKER, &s, CMPI_RC_ERR_FAILED, - "Can't get provider name."); - goto error2; + "Can't get class name."); + goto out; } for (i = 0; profiles[i] != NULL; i++) { candidate = profiles[i]; - if (!STREQC(candidate->provider_name, provider_name)) + if (!STREQC(candidate->provider_name, classname)) continue; - instance = reg_prof_instance(_BROKER, ref, candidate); + instance = reg_prof_instance(_BROKER, + "/root/interop", + NULL, + candidate); if (instance == NULL) { CMSetStatusWithChars(_BROKER, &s, CMPI_RC_ERR_FAILED, "Can't create profile instance."); - goto error3; + goto error; } inst_list_add(list, instance); } - error3: - free(provider_name); - error2: + error: free(classname); - error1: - return s; -} - -static CMPIInstance *make_ref(const CMPIObjectPath *ref, - const CMPIInstance *inst, + out: + return s; +} + +static CMPIInstance *make_ref(const CMPIObjectPath *source_op, + const CMPIInstance *target_inst, struct std_assoc_info *info, struct std_assoc *assoc) { - CMPIInstance *refinst; - char *base; - - base = class_base_name(assoc->target_class); - - refinst = get_typed_instance(_BROKER, - base, - NAMESPACE(ref)); - if (refinst != NULL) { - CMPIObjectPath *instop; - - instop = CMGetObjectPath(inst, NULL); - - CMSetProperty(refinst, assoc->source_prop, - (CMPIValue *)ref, CMPI_ref); - CMSetProperty(refinst, assoc->target_prop, - (CMPIValue *)instop, CMPI_ref); - } - - free(base); - - return refinst; + CMPIInstance *assoc_inst; + + assoc_inst = get_typed_instance(_BROKER, + "ElementConformsToProfile", + NAMESPACE(source_op)); + + if (!CMIsNullObject(assoc_inst)) { + CMPIObjectPath *target_op; + target_op = CMGetObjectPath(target_inst, NULL); + + CMSetProperty(assoc_inst, assoc->source_prop, + (CMPIValue *)&(source_op), CMPI_ref); + CMSetProperty(assoc_inst, assoc->target_prop, + (CMPIValue *)&(target_op), CMPI_ref); + } + + return assoc_inst; } struct std_assoc forward = { diff -r b14cdc8c5e90 -r 94b0d9a380ab src/Virt_ElementConformsToProfile.h --- a/src/Virt_ElementConformsToProfile.h Thu Nov 01 12:07:44 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Copyright IBM Corp. 2007 - * - * Authors: - * Heidi Eckhart <heidieck@linux.vnet.ibm.com> - * Jay Gagnon <grendel@linux.vnet.ibm.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#define COMPARE_OPT_STR(t, c, field) \ - if (t->field && \ - !STREQC(t->field, c->field)) \ - return false; \ - -#define COMPARE_OPT_NUM(t, c, field) \ - if (t->field && \ - t->field != c->field) \ - return false; \ - -/* - * Local Variables: - * mode: C - * c-set-style: "K&R" - * tab-width: 8 - * c-basic-offset: 8 - * indent-tabs-mode: nil - * End: - */

Alright I think this set is ready for inclusion. +1 Thanks for the work and all that explanation, Heidi. :) -- -Jay
participants (2)
-
Heidi Eckhart
-
Jay Gagnon