
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1205412152 -3600 # Node ID 450c46695ca4265d74f2686b64d1be27b96bd3db # Parent 91c4e3da0404a28014dbff799a841d951ce235f5 Add association ReferencedProfile for conformance to DMTF's Profile Registration Profile Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 91c4e3da0404 -r 450c46695ca4 Makefile.am --- a/Makefile.am Thu Mar 13 13:42:27 2008 +0100 +++ b/Makefile.am Thu Mar 13 13:42:32 2008 +0100 @@ -45,7 +45,8 @@ INTEROP_MOFS = \ schema/ComputerSystem.mof \ schema/HostSystem.mof \ schema/RegisteredProfile.mof \ - schema/ElementConformsToProfile.mof + schema/ElementConformsToProfile.mof \ + schema/ReferencedProfile.mof REGS = \ @@ -89,7 +90,8 @@ REGS = \ INTEROP_REGS = \ schema/RegisteredProfile.registration \ - schema/ElementConformsToProfile.registration + schema/ElementConformsToProfile.registration \ + schema/ReferencedProfile.registration pkgdata_DATA = $(MOFS) $(REGS) pkgdata_SCRIPTS = provider-register.sh diff -r 91c4e3da0404 -r 450c46695ca4 schema/ReferencedProfile.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/ReferencedProfile.mof Thu Mar 13 13:42:32 2008 +0100 @@ -0,0 +1,34 @@ +// Copyright IBM Corp. 2008 + +[Association, + Description ( + "Associates a RegisteredProfile with its scoping RegisteredProfile."), + Provider("cmpi::Virt_ReferencedProfile") +] +class Xen_ReferencedProfile : CIM_ReferencedProfile +{ + + [Override ("Antecedent")] + Xen_RegisteredProfile REF Antecedent; + + [Override ("Dependent")] + Xen_RegisteredProfile REF Dependent; + +}; + +[Association, + Description ( + "Associates a RegisteredProfile with its scoping RegisteredProfile."), + Provider("cmpi::Virt_ReferencedProfile") +] +class KVM_ReferencedProfile : CIM_ReferencedProfile +{ + + [Override ("Antecedent")] + KVM_RegisteredProfile REF Antecedent; + + [Override ("Dependent")] + KVM_RegisteredProfile REF Dependent; + +}; + diff -r 91c4e3da0404 -r 450c46695ca4 schema/ReferencedProfile.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/ReferencedProfile.registration Thu Mar 13 13:42:32 2008 +0100 @@ -0,0 +1,4 @@ +# Copyright IBM Corp. 2008 +# Classname Namespace ProviderName ProviderModule ProviderTypes +Xen_ReferencedProfile root/interop Virt_ReferencedProfile Virt_ReferencedProfile association +KVM_ReferencedProfile root/interop Virt_ReferencedProfile Virt_ReferencedProfile association diff -r 91c4e3da0404 -r 450c46695ca4 src/Makefile.am --- a/src/Makefile.am Thu Mar 13 13:42:27 2008 +0100 +++ b/src/Makefile.am Thu Mar 13 13:42:32 2008 +0100 @@ -46,6 +46,7 @@ provider_LTLIBRARIES = libVirt_ComputerS libVirt_HostedDependency.la \ libVirt_RegisteredProfile.la \ libVirt_ElementConformsToProfile.la \ + libVirt_ReferencedProfile.la \ libVirt_SettingsDefineCapabilities.la \ libVirt_HostedResourcePool.la \ libVirt_ElementCapabilities.la \ @@ -98,6 +99,10 @@ libVirt_ElementConformsToProfile_la_DEPE libVirt_ElementConformsToProfile_la_DEPENDENCIES = libVirt_RegisteredProfile.la libVirt_ElementConformsToProfile_la_SOURCES = Virt_ElementConformsToProfile.c libVirt_ElementConformsToProfile_la_LIBADD = -lVirt_RegisteredProfile + +libVirt_ReferencedProfile_la_DEPENDENCIES = libVirt_RegisteredProfile.la +libVirt_ReferencedProfile_la_SOURCES = Virt_ReferencedProfile.c +libVirt_ReferencedProfile_la_LIBADD = -lVirt_RegisteredProfile libVirt_EnabledLogicalElementCapabilities_la_SOURCES = Virt_EnabledLogicalElementCapabilities.c diff -r 91c4e3da0404 -r 450c46695ca4 src/Virt_ReferencedProfile.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_ReferencedProfile.c Thu Mar 13 13:42:32 2008 +0100 @@ -0,0 +1,226 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Heidi Eckhart <heidieck@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 + */ +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> + +#include "cmpidt.h" +#include "cmpift.h" +#include "cmpimacs.h" + +#include <libcmpiutil/libcmpiutil.h> +#include "misc_util.h" +#include "profiles.h" +#include <libcmpiutil/std_association.h> + +#include "config.h" + +#include "Virt_RegisteredProfile.h" + +const static CMPIBroker *_BROKER; + +static struct reg_prof *get_reg_prof_by_ref(const CMPIObjectPath *ref) +{ + const char* name; + int i; + + if (cu_get_str_path(ref, "InstanceID", &name) != CMPI_RC_OK) + return NULL; + + for (i = 0; profiles[i] != NULL; i++) { + if(STREQ(name, profiles[i]->reg_id)) + return profiles[i]; + } + + return NULL; +} + +static CMPIStatus prof_to_prof(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + virConnectPtr conn = NULL; + struct reg_prof *source; + struct reg_prof *scope; + int i; + + if (!match_hypervisor_prefix(ref, info)) + goto out; + + s = get_profile_by_ref(_BROKER, ref, info->properties, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + if (conn == NULL) + goto out; + + source = get_reg_prof_by_ref(ref); + if (source == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Can't find RegisteredProfile instance"); + goto out; + } + + if (source->scoping_profile != NULL) { + s = get_profile(_BROKER, + ref, + info->properties, + CIM_INTEROP_NS, + pfx_from_conn(conn), + source->scoping_profile, + &inst); + if (s.rc != CMPI_RC_OK) + goto out; + inst_list_add(list, inst); + } + + for (i = 0; profiles[i] != NULL; i++) { + if (profiles[i]->scoping_profile == NULL) + continue; + + scope = profiles[i]->scoping_profile; + if (!STREQC(scope->reg_id, source->reg_id)) + continue; + + s = get_profile(_BROKER, + ref, + info->properties, + CIM_INTEROP_NS, + pfx_from_conn(conn), + profiles[i], + &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + inst_list_add(list, inst); + } + + out: + virConnectClose(conn); + + return s; +} + +static CMPIInstance *make_ref(const CMPIObjectPath *source_ref, + const CMPIInstance *target_inst, + struct std_assoc_info *info, + struct std_assoc *assoc); + +static char* registered_profile[] = { + "Xen_RegisteredProfile", + "KVM_RegisteredProfile", + NULL +}; + +static char* assoc_classname[] = { + "Xen_ReferencedProfile", + "KVM_ReferencedProfile", + NULL +}; + +static struct std_assoc forward = { + .source_class = (char**)®istered_profile, + .source_prop = "Antecedent", + + .target_class = (char**)®istered_profile, + .target_prop = "Dependent", + + .assoc_class = (char**)&assoc_classname, + + .handler = prof_to_prof, + .make_ref = make_ref +}; + +static struct std_assoc backward = { + .source_class = (char**)®istered_profile, + .source_prop = "Dependent", + + .target_class = (char**)®istered_profile, + .target_prop = "Antecedent", + + .assoc_class = (char**)&assoc_classname, + + .handler = prof_to_prof, + .make_ref = make_ref +}; + +static struct std_assoc *assoc_handlers[] = { + &forward, + &backward, + NULL +}; + +static CMPIInstance *make_ref(const CMPIObjectPath *source_ref, + const CMPIInstance *target_inst, + struct std_assoc_info *info, + struct std_assoc *assoc) +{ + CMPIInstance *ref_inst = NULL; + struct std_assoc *ref_assoc = NULL; + struct reg_prof *source; + char* assoc_classname; + + assoc_classname = class_base_name(assoc->assoc_class[0]); + + ref_inst = get_typed_instance(_BROKER, + CLASSNAME(source_ref), + assoc_classname, + NAMESPACE(source_ref)); + + source = get_reg_prof_by_ref(source_ref); + if (source->scoping_profile != NULL) + ref_assoc = &backward; + else + ref_assoc = assoc; + + if (ref_inst != NULL) { + CMPIObjectPath *target_ref; + + target_ref = CMGetObjectPath(target_inst, NULL); + + set_reference(ref_assoc, ref_inst, + source_ref, target_ref); + } + + free(assoc_classname); + + return ref_inst; +} + +STDA_AssocMIStub(, + Virt_ReferencedProfile, + _BROKER, + libvirt_cim_init(), + assoc_handlers); +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */