# HG changeset patch # User root@hyperion.shrike # Node ID 6d6b0d8399025f70ec614ece8229960cd40c5086 # Parent 34c2273697580245e04cc065e7d10b869d32f11f This patch adds the Xen_Console and the Xen_ComputerSystemConsole providers. Signed-off-by : Rajagopalan Subrahmanian, diff -r 34c227369758 -r 6d6b0d839902 Makefile.am --- a/Makefile.am Fri Feb 02 11:31:33 2007 -0700 +++ b/Makefile.am Fri Feb 09 17:39:40 2007 -0500 @@ -18,6 +18,7 @@ # Author: Dr. Gareth S. Bestor # Contributors: Tokunbo Adeshiyan # Jim Fehlig +# Rajagopalan Subrahmanian # Description: # Automake input file for the CMPI Xen CIM provider. # ============================================================================= @@ -83,6 +84,8 @@ XEN_MOFS = \ schema/Xen_ComputerSystemDisk.mof \ schema/Xen_NetworkPort.mof \ schema/Xen_ComputerSystemNetworkPort.mof \ + schema/Xen_Console.mof \ + schema/Xen_ComputerSystemConsole.mof \ schema/Xen_ComputerSystemIndication.mof \ schema/Xen_VirtualizationCapabilities.mof \ schema/Xen_HasVirtualizationCapabilities.mof \ @@ -143,6 +146,8 @@ XEN_REGS = \ schema/Xen_ComputerSystemDisk.registration \ schema/Xen_NetworkPort.registration \ schema/Xen_ComputerSystemNetworkPort.registration \ + schema/Xen_Console.registration \ + schema/Xen_ComputerSystemConsole.registration \ schema/Xen_ComputerSystemIndication.registration \ schema/Xen_VirtualizationCapabilities.registration \ schema/Xen_HasVirtualizationCapabilities.registration \ diff -r 34c227369758 -r 6d6b0d839902 src/Makefile.am --- a/src/Makefile.am Fri Feb 02 11:31:33 2007 -0700 +++ b/src/Makefile.am Fri Feb 09 17:39:40 2007 -0500 @@ -18,6 +18,7 @@ # Author: Dr. Gareth S. Bestor # Contributors: Tokunbo Adeshiyan # Jim Fehlig +# Rajagopalan Subrahmanian # Description: # Automake input file for the CMPI Xen CIM provider. # ============================================================================= @@ -50,6 +51,7 @@ noinst_HEADERS = \ Xen_Processor_Resource.h \ Xen_Disk_Resource.h \ Xen_NetworkPort_Resource.h \ + Xen_Console_Resource.h \ Xen_VirtualizationCapabilities_Resource.h \ Xen_OperatingSystem_Resource.h \ Xen_ComputerSystemSettingData_Resource.h \ @@ -87,6 +89,8 @@ provider_LTLIBRARIES = \ libXen_ComputerSystemDisk.la \ libXen_NetworkPort.la \ libXen_ComputerSystemNetworkPort.la \ + libXen_Console.la \ + libXen_ComputerSystemConsole.la \ libXen_ComputerSystemIndication.la \ libXen_VirtualizationCapabilities.la \ libXen_HasVirtualizationCapabilities.la \ @@ -198,6 +202,11 @@ libXen_NetworkPort_la_LIBADD = libXen_Pr libXen_NetworkPort_la_LIBADD = libXen_ProviderCommon.la libXen_NetworkPort_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ +libXen_Console_la_SOURCES = Xen_Console.c Xen_Console_Resource.c +libXen_Console_la_CFLAGS = -I../ @LIBXEN_CFLAGS@ +libXen_Console_la_LIBADD = libXen_ProviderCommon.la +libXen_Console_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ + #libXen_HostedNetworkPort_la_SOURCES = Xen_HostedNetworkPort.c #libXen_HostedNetworkPort_la_LIBADD = libXen_ProviderCommon.la #libXen_HostedNetworkPort_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ @@ -205,6 +214,10 @@ libXen_ComputerSystemNetworkPort_la_SOUR libXen_ComputerSystemNetworkPort_la_SOURCES = Xen_ComputerSystemNetworkPort.c libXen_ComputerSystemNetworkPort_la_LIBADD = libXen_ProviderCommon.la libXen_ComputerSystemNetworkPort_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ + +libXen_ComputerSystemConsole_la_SOURCES = Xen_ComputerSystemConsole.c +libXen_ComputerSystemConsole_la_LIBADD = libXen_ProviderCommon.la +libXen_ComputerSystemConsole_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ libXen_ComputerSystemIndication_la_SOURCES = Xen_ComputerSystemIndication.c libXen_ComputerSystemIndication_la_LIBADD = libXen_ProviderCommon.la diff -r 34c227369758 -r 6d6b0d839902 schema/Xen_ComputerSystemConsole.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/Xen_ComputerSystemConsole.mof Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,20 @@ +// Copyright (c) 2006 IBM. All rights reserved. + +// ================================================================== +// Xen_ComputerSystemConsole +// ================================================================== +[Association, + Provider ("cmpi:Xen_ComputerSystemConsole"), + Description ( + "A class derived from CIM_SystemDevice to represent " + "the association of a Xen virtual machine/domain with its " + "Console" +class Xen_ComputerSystemConsole : CIM_SystemDevice +{ + [Override("PartComponent")] + Xen_Console REF PartComponent; + + [Override("GroupComponent")] + Xen_ComputerSystem REF GroupComponent; +}; + diff -r 34c227369758 -r 6d6b0d839902 schema/Xen_ComputerSystemConsole.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/Xen_ComputerSystemConsole.registration Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,2 @@ +# Classname Namespace ProviderName ProviderModule ProviderTypes ... +Xen_ComputerSystemConsole root/cimv2 Xen_ComputerSystemConsole Xen_ComputerSystemConsole association diff -r 34c227369758 -r 6d6b0d839902 schema/Xen_Console.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/Xen_Console.mof Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,18 @@ +// Copyright (c) 2006 IBM. All rights reserved. +// ================================================================== +// Xen_Console +// ================================================================== +[Provider ("cmpi:Xen_Console"), + Description ( + "A class derived from CIM_LogicalDevice to represent " + "a console attached to a Xen domain.")] +class Xen_Console : CIM_LogicalDevice +{ + [Description ("UUID")] + string UUID; + [Description ("URI for this console")] + string URI; + [Description ("Console Protocol")] + string Protocol; +}; + diff -r 34c227369758 -r 6d6b0d839902 schema/Xen_Console.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/Xen_Console.registration Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,2 @@ +# Classname Namespace ProviderName ProviderModule ProviderTypes ... +Xen_Console root/cimv2 Xen_Console Xen_Console instance diff -r 34c227369758 -r 6d6b0d839902 src/Xen_ComputerSystemConsole.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Xen_ComputerSystemConsole.c Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,533 @@ +// Copyright (C) 2006 Unisys Corporation +// +// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ============================================================================ +// Authors: Rajagopalan Subrahmanian +// Contributors: +// Description: +// ============================================================================ + +#include + +/* Include the required CMPI data types, function headers, and macros */ +#include "cmpidt.h" +#include "cmpift.h" +#include "cmpimacs.h" + + +// ---------------------------------------------------------------------------- +// COMMON GLOBAL VARIABLES +// ---------------------------------------------------------------------------- + +/* Handle to the CIM broker. Initialized when the provider lib is loaded. */ +static const CMPIBroker *_BROKER; + +/* Include utility functions */ +#include "cmpiutil.h" + +/* Include _SBLIM_TRACE() logging support */ +#include "cmpitrace.h" + + +// ============================================================================ +// CMPI ASSOCIATION PROVIDER FUNCTION TABLE +// ============================================================================ + +// ---------------------------------------------------------------------------- +// Info for the class supported by the association provider +// ---------------------------------------------------------------------------- + +/* Name of the left and right hand side classes of this association. */ +static char * _ASSOCCLASS = "Xen_ComputerSystemConsole"; +static char * _LHSCLASSNAME = "Xen_Console"; +static char * _RHSCLASSNAME = "Xen_ComputerSystem"; +static char * _LHSPROPERTYNAME = "PartComponent"; +static char * _RHSPROPERTYNAME = "GroupComponent"; +static char * _LHSKEYNAME = "SystemName"; +static char * _RHSKEYNAME = "Name"; + +// ---------------------------------------------------------------------------- +// AssociationCleanup() +// Perform any necessary cleanup immediately before this provider is unloaded. +// ---------------------------------------------------------------------------- +static CMPIStatus AssociationCleanup( + CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + CMPIBoolean terminating) /* [in] True if MB is terminating */ +{ + CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ + + _SBLIM_ENTER("AssociationCleanup"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + + /* Nothing needs to be done for cleanup. */ + _SBLIM_RETURNSTATUS(status); +} + + +// ---------------------------------------------------------------------------- +// AssociatorNames() +// ---------------------------------------------------------------------------- +static CMPIStatus AssociatorNames( + CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */ + const char * assocClass, + const char * resultClass, + const char * role, + const char * resultRole) +{ + CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ + char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */ + char *targetclass; /* Class of the target object(s). */ + + char *sourcekeyname; + char *targetkeyname; + + _SBLIM_ENTER("AssociatorNames"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass)); + _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass)); + _SBLIM_TRACE(2, ("--- role=\"%s\"", role)); + _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole)); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass)); + + /* Check that the requested association class, if any, is supported. */ + if (assocClass != NULL) { + CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL); + if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) { + _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request.")); + goto exit; + } + } + + /* Check that the reference matches the required role, if any. */ + if ((role != NULL) && strcmp(role, sourceclass) != 0) { + _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request.")); + goto exit; + } + + /* Determine the target class from the source class. */ + if (strcmp(sourceclass, _LHSCLASSNAME) == 0) { + sourcekeyname = _LHSKEYNAME; + targetclass = _RHSCLASSNAME; + targetkeyname = _RHSKEYNAME; + } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) { + sourcekeyname = _RHSKEYNAME; + targetclass = _LHSCLASSNAME; + targetkeyname = _LHSKEYNAME; + } else { + _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request.")); + goto exit; + } + _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass)); + + CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL); + char * sourcename = CMGetCharPtr(namedata.value.string); + _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename)); + + /* Create an object path for the result class. */ + CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { + _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); + goto exit; + } + + /* Get the list of all target class object paths from the CIMOM. */ + CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) { + _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class"); + goto exit; + } + + /* Return all object paths that exactly match the target class and resultClass, if specified. */ + while (CMHasNext(objectpaths, NULL)) { + CMPIData data = CMGetNext(objectpaths, NULL); + char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL)); + if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) { + /* Only return entries whose name matches the reference. */ + namedata = CMGetKey(data.value.ref, targetkeyname, &status); + char * resultname = CMGetCharPtr(namedata.value.string); + if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, data.value.ref); + } + } + + CMReturnDone(results); + +exit: + _SBLIM_RETURNSTATUS(status); +} + + +// ---------------------------------------------------------------------------- +// Associators() +// ---------------------------------------------------------------------------- +static CMPIStatus Associators( + CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */ + const char *assocClass, + const char *resultClass, + const char *role, + const char *resultRole, + const char ** properties) /* [in] List of desired properties (NULL=all). */ +{ + CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ + char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */ + char *targetclass; /* Class of the target object(s). */ + + char *sourcekeyname; + char *targetkeyname; + + _SBLIM_ENTER("Associators"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass)); + _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass)); + _SBLIM_TRACE(2, ("--- role=\"%s\"", role)); + _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole)); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass)); + + /* Check that the requested association class, if any, is supported. */ + if (assocClass != NULL) { + CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL); + if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) { + _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request.")); + goto exit; + } + } + + /* Check that the reference matches the required role, if any. */ + if ((role != NULL) && strcmp(role, sourceclass) != 0) { + _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request.")); + goto exit; + } + + /* Determine the target class from the source class. */ + if (strcmp(sourceclass, _LHSCLASSNAME) == 0) { + sourcekeyname = _LHSKEYNAME; + targetclass = _RHSCLASSNAME; + targetkeyname = _RHSKEYNAME; + } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) { + sourcekeyname = _RHSKEYNAME; + targetclass = _LHSCLASSNAME; + targetkeyname = _LHSKEYNAME; + } else { + _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request.")); + goto exit; + } + _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass)); + + CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL); + char * sourcename = CMGetCharPtr(namedata.value.string); + _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename)); + + /* Create an object path for the result class. */ + CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { + _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); + goto exit; + } + + /* Get the list of all target class instances from the CIMOM. */ + CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) { + _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class"); + goto exit; + } + + /* Return all instances that exactly match the target class and resultClass, if specified. */ + while (CMHasNext(instances, NULL)) { + CMPIData data = CMGetNext(instances, NULL); + char *class = CMGetCharPtr(CMGetClassName(CMGetObjectPath(data.value.inst,NULL), NULL)); + if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) { + /* Only return entries whose name matches the reference. */ + namedata = CMGetProperty(data.value.inst, targetkeyname, NULL); + char * resultname = CMGetCharPtr(namedata.value.string); + // BUG - returning data causes crash !?! + _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL)))); + if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, data.value.inst); + } + } + + CMReturnDone(results); + +exit: + _SBLIM_RETURNSTATUS(status); +} + + +// ---------------------------------------------------------------------------- +// ReferenceNames() +// ---------------------------------------------------------------------------- +static CMPIStatus ReferenceNames( + CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */ + const char *assocClass, + const char *role) +{ + CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ + char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */ + char *targetclass; /* Class of the target object(s). */ + + char *sourcekeyname; + char *targetkeyname; + + _SBLIM_ENTER("ReferenceNames"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass)); + _SBLIM_TRACE(2, ("--- role=\"%s\"", role)); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass)); + + /* Check that the requested association class, if any, is supported. */ + if (assocClass != NULL) { + CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL); + if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) { + _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request.")); + goto exit; + } + } + + /* Check that the reference matches the required role, if any. */ + if ((role != NULL) && strcmp(role, sourceclass) != 0) { + _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request.")); + goto exit; + } + + /* Determine the target class from the source class. */ + if (strcmp(sourceclass, _LHSCLASSNAME) == 0) { + sourcekeyname = _LHSKEYNAME; + targetclass = _RHSCLASSNAME; + targetkeyname = _RHSKEYNAME; + } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) { + sourcekeyname = _RHSKEYNAME; + targetclass = _LHSCLASSNAME; + targetkeyname = _LHSKEYNAME; + } else { + _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request.")); + goto exit; + } + _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass)); + + CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL); + char * sourcename = CMGetCharPtr(namedata.value.string); + _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename)); + + /* Create an object path for the result class. */ + CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { + _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); + goto exit; + } + + /* Get the list of all target class object paths from the CIMOM. */ + CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) { + _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class"); + goto exit; + } + + /* Return all object paths that exactly match the target class and resultClass, if specified. */ + while (CMHasNext(objectpaths, NULL)) { + CMPIData data = CMGetNext(objectpaths, NULL); + char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL)); + if (strcmp(class,targetclass) == 0) { + + /* Create an object path for the association. */ + CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) { + _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); + goto exit; + } + + /* Assign the references in the association appropriately. */ + if (strcmp(sourceclass, _RHSCLASSNAME) == 0) { + CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref); + CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref); + } else { + CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref); + CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref); + } + + /* Only return entries whose name matches the reference. */ + namedata = CMGetKey(data.value.ref, targetkeyname, &status); + char * resultname = CMGetCharPtr(namedata.value.string); + if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, refobjectpath); + } + } + +exit: + _SBLIM_RETURNSTATUS(status); +} + + +// ---------------------------------------------------------------------------- +// References() +// ---------------------------------------------------------------------------- +static CMPIStatus References( + CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */ + const char *assocClass, + const char *role, + const char **properties) /* [in] List of desired properties (NULL=all). */ +{ + CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ + char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */ + char *targetclass; /* Class of the target object(s). */ + + char *sourcekeyname; + char *targetkeyname; + + _SBLIM_ENTER("References"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass)); + _SBLIM_TRACE(2, ("--- role=\"%s\"", role)); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass)); + + /* Check that the requested association class, if any, is supported. */ + if (assocClass != NULL) { + CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL); + if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) { + _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request.")); + goto exit; + } + } + + /* Check that the reference matches the required role, if any. */ + if ((role != NULL) && strcmp(role, sourceclass) != 0) { + _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request.")); + goto exit; + } + + /* Determine the target class from the source class. */ + if (strcmp(sourceclass, _LHSCLASSNAME) == 0) { + sourcekeyname = _LHSKEYNAME; + targetclass = _RHSCLASSNAME; + targetkeyname = _RHSKEYNAME; + } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) { + sourcekeyname = _RHSKEYNAME; + targetclass = _LHSCLASSNAME; + targetkeyname = _LHSKEYNAME; + } else { + _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request.")); + goto exit; + } + _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass)); + + CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL); + char * sourcename = CMGetCharPtr(namedata.value.string); + _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename)); + + /* Create an object path for the result class. */ + CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { + _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); + goto exit; + } + + /* Get the list of all target class object paths from the CIMOM. */ + CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) { + _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class"); + goto exit; + } + + /* Return all object paths that exactly match the target class and resultClass, if specified. */ + while (CMHasNext(objectpaths, NULL)) { + CMPIData data = CMGetNext(objectpaths, NULL); + char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL)); + if (strcmp(class,targetclass) == 0) { + + /* Create an instance for the association. */ + CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace, _ASSOCCLASS, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) { + _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); + goto exit; + } + + /* Assign the references in the association appropriately. */ + if (strcmp(sourceclass, _RHSCLASSNAME) == 0) { + CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref); + CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref); + } else { + CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref); + CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref); + } + + /* Only return entries whose name matches the reference. */ + namedata = CMGetKey(data.value.ref, targetkeyname, &status); + char * resultname = CMGetCharPtr(namedata.value.string); + if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, refinstance); + } + } +exit: + _SBLIM_RETURNSTATUS(status); +} + + +// ---------------------------------------------------------------------------- +// AssociationInitialize() +// Perform any necessary initialization immediately after this provider is +// first loaded. +// ---------------------------------------------------------------------------- +static void AssociationInitialize( + CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context) /* [in] Additional context info, if any. */ +{ + _SBLIM_ENTER("AssociationInitialize"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + + /* Nothing needs to be done to initialize this provider */ + _SBLIM_RETURN(); +} + + +// ============================================================================ +// CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP +// ============================================================================ +CMAssociationMIStub( , Xen_ComputerSystemNetworkPort, _BROKER, AssociationInitialize(&mi, ctx)); diff -r 34c227369758 -r 6d6b0d839902 src/Xen_Console.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Xen_Console.c Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,614 @@ +// Copyright (C) 2006 IBM Corporation +// +// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ============================================================================ +// Authors: Rajagopalan Subrahmanian, +// Contributors: +// Description: This file +// ============================================================================ + +/* Include the required CMPI data types, function headers, and macros */ +#include "cmpidt.h" +#include "cmpift.h" +#include "cmpimacs.h" + +/* Include utility functions */ +#include "cmpiutil.h" + +/* Include _SBLIM_TRACE() logging support */ +#include "cmpitrace.h" + +/* Include Xen utilities */ +#include "xen_utils.h" + +/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */ +#include "Xen_Console_Resource.h" + + +// ---------------------------------------------------------------------------- +// COMMON GLOBAL VARIABLES +// ---------------------------------------------------------------------------- + +/* Handle to the CIM broker. Initialized when the provider lib is loaded. */ +static const CMPIBroker *_BROKER; + +/* Xen session object. Initialize when the provider is loaded, close when + * provider unloaded. */ +static xen_utils_session *session = NULL; + + +// ============================================================================ +// CMPI INSTANCE PROVIDER FUNCTION TABLE +// ============================================================================ + +// ---------------------------------------------------------------------------- +// Info for the class supported by the instance provider +// ---------------------------------------------------------------------------- + +/* Name of the class implemented by this instance provider. */ +/*** CUSTOMIZE FOR EACH PROVIDER ***/ +static char * _CLASSNAME = "Xen_Console"; + +/* NULL terminated list of key properties of this class. */ +/*** CUSTOMIZE FOR EACH PROVIDER ***/ +const static char * _KEYNAMES[] = {"SystemName", "SystemCreationClassName", "DeviceID", "CreationClassName", NULL}; + +// ---------------------------------------------------------------------------- +// Cleanup() +// Perform any necessary cleanup immediately before this provider is unloaded. +// ---------------------------------------------------------------------------- +static CMPIStatus Cleanup( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + CMPIBoolean terminating) /* [in] True if MB is terminating */ +{ + CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ + + _SBLIM_ENTER("Cleanup"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + + if (session) { + xen_utils_xen_close(session); + session = NULL; + } + _SBLIM_RETURNSTATUS(status); +} + +// ---------------------------------------------------------------------------- +// EnumInstanceNames() +// Return a list of all the instances names (return their object paths only). +// ---------------------------------------------------------------------------- +static CMPIStatus EnumInstanceNames( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */ +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + _RESOURCES * resources; /* Handle to the list of system resources. */ + _RESOURCE * resource; /* Handle to each system resource. */ + char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + int found = 0; /* Found any instances? */ + + _SBLIM_ENTER("EnumInstanceNames"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + + /* Get a handle to the list of system resources. */ + if (!Xen_Console_getResources(session, &resources)) { + _SBLIM_TRACE(1,("--- _getResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); + goto exit; + } + + /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ + while (Xen_Console_getNextResource(session, resources, &resource)) { + /* Create a new CMPIInstance to store this resource. */ + CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { + _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); + goto exit; + } + + /* Set the instance property values from the resource data. */ + if (!Xen_Console_setInstanceFromResource(session, resource, instance, _BROKER)) { + _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); + goto exit; + } + + /* Free the resource data. */ + if (!Xen_Console_freeResource(resource)) { + _SBLIM_TRACE(1,("--- _freeResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); + goto exit; + } + + /* Return the CMPIObjectPath for this instance. */ + CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { + _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance"); + goto exit; + } + CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */ + + _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL)))); + CMReturnObjectPath(results, objectpath); + found++; + } + + _SBLIM_TRACE(2,("--- %d object paths found", found)); + CMReturnDone(results); + +exit: + /* Free the list of system resources. */ + if (!Xen_Console_freeResources(resources)) { + _SBLIM_TRACE(1,("--- _freeResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); + } + + _SBLIM_RETURNSTATUS(status); +} + +// ---------------------------------------------------------------------------- +// EnumInstances() +// Return a list of all the instances (return all the instance data). +// ---------------------------------------------------------------------------- +static CMPIStatus EnumInstances( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */ + const char ** properties) /* [in] List of desired properties (NULL=all). */ +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + _RESOURCES * resources; /* Handle to the list of system resources. */ + _RESOURCE * resource; /* Handle to each system resource. */ + char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + int found = 0; /* Found any resource instances? */ + + _SBLIM_ENTER("EnumInstances"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + + /* Get a handle to the list of system resources. */ + if (!Xen_Console_getResources(session, &resources)) { + _SBLIM_TRACE(1,("--- _getResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); + goto exit; + } + + /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ + while (Xen_Console_getNextResource(session, resources, &resource)) { + /* Create a new CMPIInstance to store this resource. */ + CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { + _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); + goto exit; + } + + /* Setup a filter to only return the desired properties. */ + status = CMSetPropertyFilter(instance, properties, _KEYNAMES); + if (status.rc != CMPI_RC_OK) { + _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); + goto exit; + } + + /* Set the instance property values from the resource data. */ + if (!Xen_Console_setInstanceFromResource(session, resource, instance, _BROKER)) { + _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); + goto exit; + } + + /* Free the resource data. */ + if (!Xen_Console_freeResource(resource)) { + _SBLIM_TRACE(1,("--- _freeResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); + goto exit; + } + + /* Return the CMPIInstance for this instance. */ + _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); + CMReturnInstance(results, instance); + found++; + } + + _SBLIM_TRACE(2,("--- %d instances found", found)); + CMReturnDone(results); + +exit: + /* Free the list of system resources. */ + if (!Xen_Console_freeResources(resources)) { + _SBLIM_TRACE(1,("--- _freeResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); + } + + _SBLIM_RETURNSTATUS(status); +} + +// ---------------------------------------------------------------------------- +// GetInstance() +// Return the instance data for the specified instance only. +// ---------------------------------------------------------------------------- +static CMPIStatus GetInstance( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ + const char ** properties) /* [in] List of desired properties (NULL=all). */ +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + _RESOURCES * resources; /* Handle to the list of system resources. */ + _RESOURCE * resource; /* Handle to the system resource. */ + char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + int found = 0; /* Found the target instance? */ + + _SBLIM_ENTER("GetInstance"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + + /* Get a handle to the list of system resources. */ + if (!Xen_Console_getResources(session, &resources)) { + _SBLIM_TRACE(1,("--- _getResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); + goto exit; + } + + /* Get the target resource. */ + found = Xen_Console_getResourceForObjectPath(session, &resource, reference); + if (!found || (resource == NULL)) { + _SBLIM_TRACE(1,("--- Target instance not found")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); + goto exit; + } + + /* Create a new CMPIInstance to store this resource. */ + CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { + _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); + goto exit; + } + + /* Setup a filter to only return the desired properties. */ + status = CMSetPropertyFilter(instance, properties, _KEYNAMES); + if (status.rc != CMPI_RC_OK) { + _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); + goto exit; + } + + /* Set the instance property values from the resource data. */ + if (!Xen_Console_setInstanceFromResource(session, resource, instance, _BROKER)) { + _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); + goto exit; + } + + /* Free the resource data. */ + if (!Xen_Console_freeResource(resource)) { + _SBLIM_TRACE(1,("--- _freeResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); + goto exit; + } + + /* Return the CMPIInstance for this instance. */ + _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); + CMReturnInstance(results, instance); + + _SBLIM_TRACE(2,("--- instance found")); + CMReturnDone(results); + +exit: + /* Free the list of system resources. */ + if (!Xen_Console_freeResources(resources)) { + _SBLIM_TRACE(1,("--- _freeResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); + } + + _SBLIM_RETURNSTATUS(status); +} + +// ---------------------------------------------------------------------------- +// SetInstance() +// Save modified instance data for the specified instance. +// ---------------------------------------------------------------------------- +static CMPIStatus SetInstance( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ + const CMPIInstance * newinstance, /* [in] Contains the new instance data. */ + const char **properties) +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + _RESOURCES * resources; /* Handle to the list of system resources. */ + _RESOURCE * resource; /* Handle to the system resource. */ + char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + int found = 0; /* Found the target instance? */ + + _SBLIM_ENTER("SetInstance"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + + /* Get a handle to the list of system resources. */ + if (!Xen_Console_getResources(session, &resources)) { + _SBLIM_TRACE(1,("--- _getResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); + goto exit; + } + + /* Get the target resource. */ + found = Xen_Console_getResourceForObjectPath(session, &resource, reference); + if (!found || (resource == NULL)) { + _SBLIM_TRACE(1,("--- Target instance not found")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); + goto exit; + } + + _SBLIM_TRACE(2,("--- instance found", found)); + + /* Update the target resource data with the new instance property values. */ + int rc = Xen_Console_setResourceFromInstance(resource, newinstance, _BROKER); + + /* Free the resource data. */ + if (!Xen_Console_freeResource(resource)) { + _SBLIM_TRACE(1,("--- _freeResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); + goto exit; + } + + if (rc != 1) { + if (rc == -1) { + _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); + } else { + _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties"); + } + goto exit; + } + +exit: + /* Free the list of system resources. */ + if (!Xen_Console_freeResources(resources)) { + _SBLIM_TRACE(1,("--- _freeResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); + } + + _SBLIM_RETURNSTATUS(status); +} + +// ---------------------------------------------------------------------------- +// CreateInstance() +// Create a new instance from the specified instance data. +// ---------------------------------------------------------------------------- +static CMPIStatus CreateInstance( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ + const CMPIInstance * newinstance) /* [in] Contains the new instance data. */ +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + _RESOURCES * resources; /* Handle to the list of system resources. */ + _RESOURCE * resource; /* Handle to the system resource. */ + char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + int found = 0; /* Found the target instance? */ + + _SBLIM_ENTER("CreateInstance"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + + /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */ + reference = CMGetObjectPath(newinstance, NULL); + + /* Get a handle to the list of system resources. */ + if (!Xen_Console_getResources(session, &resources)) { + _SBLIM_TRACE(1,("--- _getResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); + goto exit; + } + + /* Get the target resource. */ + found = Xen_Console_getResourceForObjectPath(session, &resource, reference); + + /* Free the resource data. */ + if (!Xen_Console_freeResource(resource)) { + _SBLIM_TRACE(1,("--- _freeResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); + goto exit; + } + + if (found) { + _SBLIM_TRACE(1,("--- Target instance already exists")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists"); + goto exit; + } + + /* Create a new resource with the new instance property values. */ + int rc = Xen_Console_createResourceFromInstance(resources, &resource, newinstance, _BROKER); + if (rc != 1) { + if (rc == -1) { + _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); + } else { + _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties"); + } + goto exit; + } + + /* Return the object path for the newly created instance. */ + CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL); + CMSetNameSpace(objectpath, namespace); + CMReturnObjectPath(results, objectpath); + CMReturnDone(results); + +exit: + /* Free the list of system resources. */ + if (!Xen_Console_freeResources(resources)) { + _SBLIM_TRACE(1,("--- _freeResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); + } + + _SBLIM_RETURNSTATUS(status); +} + +// ---------------------------------------------------------------------------- +// DeleteInstance() +// Delete or remove the specified instance from the system. +// ---------------------------------------------------------------------------- +static CMPIStatus DeleteInstance( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */ +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + _RESOURCES * resources; /* Handle to the list of system resources. */ + _RESOURCE * resource; /* Handle to the system resource. */ + char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + int found = 0; /* Found the target instance? */ + + _SBLIM_ENTER("DeleteInstance"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + + /* Get a handle to the list of system resources. */ + if (!Xen_Console_getResources(session, &resources)) { + _SBLIM_TRACE(1,("--- _getResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); + goto exit; + } + + /* Get the target resource. */ + found = Xen_Console_getResourceForObjectPath(session, &resource, reference); + if (!found || (resource == NULL)) { + _SBLIM_TRACE(1,("--- Target instance not found")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); + goto exit; + } + + _SBLIM_TRACE(2,("--- instance found", found)); + + /* Delete the target resource. */ + int rc = Xen_Console_deleteResource(resources, resource); + + /* Free the resource data. */ + if (!Xen_Console_freeResource(resource)) { + _SBLIM_TRACE(1,("--- _freeResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); + goto exit; + } + + if (rc != 1) { + if (rc == -1) { + _SBLIM_TRACE(1,("--- __deleteResource() unsupported")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); + } else { + _SBLIM_TRACE(1,("--- _deleteResource() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource"); + } + goto exit; + } + +exit: + /* Free the list of system resources. */ + if (!Xen_Console_freeResources(resources)) { + _SBLIM_TRACE(1,("--- _freeResources() failed")); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); + } + + _SBLIM_RETURNSTATUS(status); +} + + +// ---------------------------------------------------------------------------- +// ExecQuery() +// Return a list of all the instances that satisfy the specified query filter. +// ---------------------------------------------------------------------------- +static CMPIStatus ExecQuery( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context, /* [in] Additional context info, if any. */ + const CMPIResult * results, /* [out] Results of this operation. */ + const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ + const char * language, /* [in] Name of the query language. */ + const char * query) /* [in] Text of the query written in the query language. */ +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ + + _SBLIM_ENTER("ExecQuery"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); + _SBLIM_TRACE(2, ("--- language=\"%s\"", language)); + _SBLIM_TRACE(2, ("--- query=\"%s\"", query)); + _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + + /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */ + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); + + CMReturnDone(results); + +exit: + _SBLIM_RETURNSTATUS(status); +} + +// ---------------------------------------------------------------------------- +// Initialize() +// Perform any necessary initialization immediately after this provider is +// first loaded. +// ---------------------------------------------------------------------------- +static void Initialize( + CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ + const CMPIContext * context) /* [in] Additional context info, if any. */ +{ + _SBLIM_ENTER("Initialize"); + _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); + // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); + + /* Initialized Xen session object. */ + if (session == NULL) + xen_utils_xen_init(&session); + + _SBLIM_RETURN(); +} + +// ============================================================================ +// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP +// ============================================================================ +CMInstanceMIStub( , Xen_Console, _BROKER, Initialize(&mi, ctx)); diff -r 34c227369758 -r 6d6b0d839902 src/Xen_Console.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Xen_Console.h Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,104 @@ +// Copyright (C) 2006 IBM Corporation +// +// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ============================================================================ +// Authors:Rajagopalan Subrahmanian +// +// Contributors: +// +// Description: +// ============================================================================ + +/* Include required libxen headers. */ +#include +#include + +#include "xen_utils.h" + +/*** CUSTOMIZE FOR EACH PROVIDER ***/ +/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES. + THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS + LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC. + THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN + ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ +typedef struct { + xen_console_set *consoles; + unsigned int currentconsolenum; +} _RESOURCES; + +/*** CUSTOMIZE FOR EACH PROVIDER ***/ +/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE. + THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH + RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE + PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE + ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */ +typedef xen_console_record _RESOURCE; + +/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */ + +/* Include the required CMPI data types. */ +#include "cmpidt.h" + +// ---------------------------------------------------------------------------- +// Generic resource access methods for CMPI providers. +// Return value: +// -1 = Unsupported +// 0 = Failed +// 1 = OK +// ---------------------------------------------------------------------------- + +/* Get a handle to the list of all system resources for this class. */ +int Xen_Console_getResources(xen_utils_session *session, + _RESOURCES ** resources); + +/* Free/deallocate/cleanup the resources list after use. */ +int Xen_Console_freeResources(_RESOURCES * resources); + +/* Iterator to get the next resource from the resources list. */ +int Xen_Console_getNextResource(xen_utils_session *session, + _RESOURCES * resources, + _RESOURCE ** resource); + +/* Get the specific resource that matches the CMPI object path. */ +int Xen_Console_getResourceForObjectPath(xen_utils_session *session, + _RESOURCE ** resource, + const CMPIObjectPath * objectpath); + +/* Free/deallocate/cleanup a resource after use. */ +int Xen_Console_freeResource(_RESOURCE * resource); + +/* Set the property values of a CMPI instance from a specific resource. */ +int Xen_Console_setInstanceFromResource(xen_utils_session *session, + _RESOURCE * resource, + const CMPIInstance * instance, + const CMPIBroker * broker); + +// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS + +/* Delete the specified resource from the system. */ +int Xen_Console_deleteResource(_RESOURCES * resources, + _RESOURCE * resource); + +/* Modify the specified resource using the property values of a CMPI instance. */ +int Xen_Console_setResourceFromInstance(_RESOURCE * resource, + const CMPIInstance * instance, + const CMPIBroker * broker); + +/* Create a new resource using the property values of a CMPI instance. */ +int Xen_Console_createResourceFromInstance(_RESOURCES * resources, + _RESOURCE ** resource, + const CMPIInstance * instance, + const CMPIBroker * broker); + diff -r 34c227369758 -r 6d6b0d839902 src/Xen_Console_Resource.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Xen_Console_Resource.c Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,286 @@ +// Copyright (C) 2006 IBM Corporation +// +// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ============================================================================ +// Authors: Rajagopalan Subrahmanian, +// +// Contributors: +// +// Description: +// ============================================================================ + +#include +#include +#include + +#include +#include +#include + +#include "Xen_Console_Resource.h" + +/* Include the required CMPI data types, function headers, and macros. */ +#include "cmpidt.h" +#include "cmpift.h" +#include "cmpimacs.h" + +#include "xen_utils.h" + +/* Include _SBLIM_TRACE() logging support */ +#include "cmpitrace.h" + +// ---------------------------------------------------------------------------- + +static int concat_console_lists(xen_console_set **target, xen_console_set *source) +{ + + int total_size; + int i, j; + + /* Nothing to concatenate if source is empty */ + if (source == NULL || source->size == 0) + return 1; + + /* If targe is empty, assign source to target */ + if (*target == NULL) { + *target = source; + return 1; + } + + /* realloc memory and append source to target */ + total_size = (*target)->size + source->size; + *target = realloc(*target, sizeof(xen_console_set) + (total_size * sizeof(xen_console))); + if (*target == NULL) + return 0; + + for (j = (*target)->size, i = 0; i < source->size; i++) { + (*target)->contents[j + i] = source->contents[i]; + source->contents[i] = NULL; + } + (*target)->size = total_size; + + /* Free source list - it has been copied to target */ + xen_console_set_free(source); + return 1; +} + + +/* Get a handle to the list of all system resources for this class. */ +int Xen_Console_getResources(xen_utils_session *session, + _RESOURCES ** resources) +{ + xen_domain_resources *res; + xen_console_set *all_consoles = NULL; + xen_vm_record *vm_rec = NULL; + + /* malloc a new handle for the resources list. */ + *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES)); + if (*resources == NULL) + return 0; + + /* Get a list of domain resources. */ + if (!xen_utils_get_domain_resources(session, &res)) { + *resources = NULL; + return 0; + } + + /* Create list of console resources from consoles found in each domain. */ + while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) { + /* Ignore halted vms */ + if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) { + xen_vm_record_free(vm_rec); + continue; + } + + xen_console_set *console_set; + if (!xen_vm_get_consoles(session->xen, &console_set, vm_rec->handle)) + goto Error; + + if (!concat_console_lists(&all_consoles, console_set)) + goto Error; + + xen_vm_record_free(vm_rec); + } + + (*resources)->consoles = all_consoles; + (*resources)->currentconsolenum = 0; + + return 1; + + Error: + xen_vm_record_free(vm_rec); + xen_utils_free_domain_resources(res); + free(*resources); + *resources = NULL; + return 0; +} + +// ---------------------------------------------------------------------------- + +/* Free/deallocate/cleanup the resources list after use. */ +int Xen_Console_freeResources(_RESOURCES * resources) +{ + if (resources != NULL) { + if (resources->consoles != NULL) + xen_console_set_free(resources->consoles); + free(resources); + resources = NULL; + } + + return 1; +} + +// ---------------------------------------------------------------------------- + +/* Iterator to get the next resource from the resources list. */ +int Xen_Console_getNextResource(xen_utils_session *session, + _RESOURCES * resources, + _RESOURCE ** resource) +{ + if (resources == NULL || resources->consoles == NULL) + return 0; + + /* Check if reached the end of the list of consoles. */ + if (resources->currentconsolenum == resources->consoles->size) + return 0; + + /* Get the current console record. */ + if (!xen_console_get_record(session->xen, resource, resources->consoles->contents[resources->currentconsolenum])) + return 0; + + resources->currentconsolenum++; + return 1; +} + +// ---------------------------------------------------------------------------- + +/* Get the specific resource that matches the CMPI object path. */ +int Xen_Console_getResourceForObjectPath(xen_utils_session *session, + _RESOURCE ** resource, + const CMPIObjectPath * objectpath) +{ + CMPIData namedata; + char *keyvalue; + int ccode; + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + + if (CMIsNullObject(objectpath)) return 0; + + /* Get the console resource based on DeviceID (console uuid) */ + namedata = CMGetKey(objectpath, "DeviceID", &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) + return 0; + + keyvalue = CMGetCharPtr(namedata.value.string); + if ((keyvalue == NULL) || (*keyvalue == '\0')) + return 0; + + xen_console console; + if (!xen_console_get_by_uuid(session->xen, &console, keyvalue)) + return 0; + + ccode = xen_console_get_record(session->xen, resource, console); + xen_console_free(console); + return ccode; +} + +// ---------------------------------------------------------------------------- + +/* Free/deallocate/cleanup the resource after use. */ +int Xen_Console_freeResource(_RESOURCE * resource) +{ + xen_console_record_free(resource); + return 1; +} + +// ---------------------------------------------------------------------------- + +/* Set the property values of a CMPI instance from a specific resource. */ +int Xen_Console_setInstanceFromResource(xen_utils_session *session, + _RESOURCE * resource, + const CMPIInstance * instance, + const CMPIBroker * broker) +{ + xen_vm_record *alloced_vm_rec = NULL; + xen_vm_record *vm_rec; + + if (resource == NULL) return 0; + if (CMIsNullObject(instance)) return 0; + + xen_vm_record_opt *vm_rec_opt = resource->vm; + if (vm_rec_opt->is_record) { + vm_rec = vm_rec_opt->u.record; + } + else { + if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) { + /* Error description in session object! */ + return 0; + } + alloced_vm_rec = vm_rec; + } + + /* Set the CMPIInstance properties from the resource data. */ + CMSetProperty(instance, "SystemCreationClassName",(CMPIValue *)"Xen_ComputerSystem", CMPI_chars); + CMSetProperty(instance, "SystemName",(CMPIValue *)vm_rec->name_label, CMPI_chars); + CMSetProperty(instance, "CreationClassName",(CMPIValue *)"Xen_Console", CMPI_chars); + + CMSetProperty(instance, "DeviceID",(CMPIValue *)resource->uuid, CMPI_chars); + + CMSetProperty(instance, "Caption",(CMPIValue *)"Console", CMPI_chars); + CMSetProperty(instance, "Description",(CMPIValue *)"Console", CMPI_chars); + + CMSetProperty(instance, "URI", (CMPIValue *)resource->uri, CMPI_chars); + if (resource->protocol==XEN_CONSOLE_PROTOCOL_VT100) CMSetProperty(instance, "Protocol",(CMPIValue *)"VT100", CMPI_chars); + if (resource->protocol==XEN_CONSOLE_PROTOCOL_RFB) CMSetProperty(instance, "Protocol",(CMPIValue *)"Remote Framebuffer - VNC", CMPI_chars); + if (resource->protocol==XEN_CONSOLE_PROTOCOL_RDP) CMSetProperty(instance, "Protocol",(CMPIValue *)"Remote Desktop", CMPI_chars); + if (alloced_vm_rec) + xen_vm_record_free(alloced_vm_rec); + + return 1; +} + +// ---------------------------------------------------------------------------- + +/* Delete the specified resource from the system. */ +int Xen_Console_deleteResource(_RESOURCES * resources, + _RESOURCE * resource) +{ + /* Unsupported. */ + return -1; +} + +// ---------------------------------------------------------------------------- + +/* Modify the specified resource using the property values of a CMPI instance. */ +int Xen_Console_setResourceFromInstance(_RESOURCE * resource, + const CMPIInstance * instance, + const CMPIBroker * broker) +{ + /* Unsupported. */ + return -1; +} + +// ---------------------------------------------------------------------------- + +/* Create a new resource using the property values of a CMPI instance. */ +int Xen_Console_createResourceFromInstance(_RESOURCES * resources, + _RESOURCE ** resource, + const CMPIInstance * instance, + const CMPIBroker * broker) +{ + /* Unsupported. */ + return -1; +} + diff -r 34c227369758 -r 6d6b0d839902 src/Xen_Console_Resource.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Xen_Console_Resource.h Fri Feb 09 17:39:40 2007 -0500 @@ -0,0 +1,104 @@ +// Copyright (C) 2006 IBM Corporation +// +// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ============================================================================ +// Authors: Rajagopalan Subrahmanian +// +// Contributors: +// +// Description: +// ============================================================================ + +/* Include required libxen headers. */ +#include +#include + +#include "xen_utils.h" + +/*** CUSTOMIZE FOR EACH PROVIDER ***/ +/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES. + THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS + LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC. + THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN + ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ +typedef struct { + xen_console_set *consoles; + unsigned int currentconsolenum; +} _RESOURCES; + +/*** CUSTOMIZE FOR EACH PROVIDER ***/ +/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE. + THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH + RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE + PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE + ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */ +typedef xen_console_record _RESOURCE; + +/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */ + +/* Include the required CMPI data types. */ +#include "cmpidt.h" + +// ---------------------------------------------------------------------------- +// Generic resource access methods for CMPI providers. +// Return value: +// -1 = Unsupported +// 0 = Failed +// 1 = OK +// ---------------------------------------------------------------------------- + +/* Get a handle to the list of all system resources for this class. */ +int Xen_Console_getResources(xen_utils_session *session, + _RESOURCES ** resources); + +/* Free/deallocate/cleanup the resources list after use. */ +int Xen_Console_freeResources(_RESOURCES * resources); + +/* Iterator to get the next resource from the resources list. */ +int Xen_Console_getNextResource(xen_utils_session *session, + _RESOURCES * resources, + _RESOURCE ** resource); + +/* Get the specific resource that matches the CMPI object path. */ +int Xen_Console_getResourceForObjectPath(xen_utils_session *session, + _RESOURCE ** resource, + const CMPIObjectPath * objectpath); + +/* Free/deallocate/cleanup a resource after use. */ +int Xen_Console_freeResource(_RESOURCE * resource); + +/* Set the property values of a CMPI instance from a specific resource. */ +int Xen_Console_setInstanceFromResource(xen_utils_session *session, + _RESOURCE * resource, + const CMPIInstance * instance, + const CMPIBroker * broker); + +// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS + +/* Delete the specified resource from the system. */ +int Xen_Console_deleteResource(_RESOURCES * resources, + _RESOURCE * resource); + +/* Modify the specified resource using the property values of a CMPI instance. */ +int Xen_Console_setResourceFromInstance(_RESOURCE * resource, + const CMPIInstance * instance, + const CMPIBroker * broker); + +/* Create a new resource using the property values of a CMPI instance. */ +int Xen_Console_createResourceFromInstance(_RESOURCES * resources, + _RESOURCE ** resource, + const CMPIInstance * instance, + const CMPIBroker * broker); +