|
From: <jc...@us...> - 2008-04-23 23:23:25
|
Revision: 588
http://omc.svn.sourceforge.net/omc/?rev=588&view=rev
Author: jcarey
Date: 2008-04-23 16:23:28 -0700 (Wed, 23 Apr 2008)
Log Message:
-----------
Initial impl of the vmbuilderservice provider
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
Added Paths:
-----------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-04-23 22:12:30 UTC (rev 587)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-04-23 23:23:28 UTC (rev 588)
@@ -1,16 +1,16 @@
-#include $(top_srcdir)/Makefile.incl.am
+include $(top_srcdir)/Makefile.incl.am
-#provider_LTLIBRARIES = libomc_xenvmbuilder.la
+provider_LTLIBRARIES = libomc_xenvmbuilder.la
-#INCLUDES = -I$(top_srcdir)/src/include
+INCLUDES = -I$(top_builddir)
-#libomc_xenvmbuilder_la_SOURCES = \
-# mysource.c
+libomc_xenvmbuilder_la_SOURCES = \
+ builder-service.c
-#libomc_xenvmbuilder_la_LDFLAGS = \
-# -lpthread \
-# -lomc_cmpi \
-# -version-info 1
+libomc_xenvmbuilder_la_LDFLAGS = \
+ -lpthread \
+ -lomc_cmpi \
+ -version-info 1
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-04-23 23:23:28 UTC (rev 588)
@@ -0,0 +1,529 @@
+/*******************************************************************************
+* Copyright (C) 2005,2006,2007,2008 Novell, Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistributions of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* - Neither the name of Novell, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*
+* Author: Jon Carey (jc...@no...)
+******************************************************************************/
+#include "config.h"
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <time.h>
+#include <limits.h>
+#include <errno.h>
+#include <signal.h>
+#include <cmpidt.h>
+#include <cmpift.h>
+#include <cmpimacs.h>
+#include <omc/linuxProcUtils.h>
+#include <omc/string.h>
+#include <omc/exec.h>
+#include <omc/base.h>
+#include <omc/cmpiUtils.h>
+#include <omc/cmpiSimpleAssoc.h>
+
+
+/* NULL terminated list of key property names for this class */
+static const char* service_class_keys[] =
+{
+ "CreationClassName",
+ "Name",
+ "SystemCreationClassName",
+ "SystemName",
+ NULL
+};
+
+#define SERVICE_NAME "xen-vmbuilder"
+#define RPM_NAME "omc-xenvm-builder"
+
+
+/* Enable this for tracing */
+#ifdef OMC_DEBUG
+#undef OMC_DEBUG
+#endif
+
+#ifdef OMC_DEBUG
+#define DEBUGOUT(fmt, args...) printf(fmt,## args)
+#else
+#define DEBUGOUT(fmt, args...)
+#endif
+
+/*
+ * Global handle to the CIM broker
+ * This is initialized by the CIMOM when the provider is loaded
+ */
+static const CMPIBroker* _broker;
+
+/*****************************************************************************/
+static int
+fillServiceInstance(
+ CMPIInstance* instance,
+ const char* hostName)
+{
+ unsigned short wku16;
+ CMPIDateTime* datetime;
+ CMPIArray *pra;
+
+ CMSetProperty(instance, "CreationClassName", (CMPIValue*)"XEN_VMBuilderService", CMPI_chars);
+ CMSetProperty(instance, "Name", (CMPIValue*)SERVICE_NAME, CMPI_chars);
+ CMSetProperty(instance, "SystemCreationClassName", (CMPIValue*)omcGetComputerSystemClassName(), CMPI_chars);
+ CMSetProperty(instance, "SystemName", (CMPIValue*)hostName, CMPI_chars);
+ pra = CMNewArray(_broker, 1, CMPI_uint16, NULL);
+ wku16 = 2;
+ CMSetArrayElementAt(pra, 0, (CMPIValue*)&wku16, CMPI_uint16);
+ CMSetProperty(instance, "AvailableRequestedStates", (CMPIValue*)&pra, CMPI_uint16A);
+ CMSetProperty(instance, "BuilderVersion", (CMPIValue*)PACKAGE_VERSION, CMPI_chars);
+ CMSetProperty(instance, "Caption", (CMPIValue*)"VM Builder Service", CMPI_chars);
+ CMSetProperty(instance, "Description", (CMPIValue*)"Service that facilitates "
+ "the building of new virutal machine images/configuration", CMPI_chars);
+ CMSetProperty(instance, "ElementName", (CMPIValue*)SERVICE_NAME, CMPI_chars);
+ wku16 = 2;
+ CMSetProperty(instance, "EnabledDefault", (CMPIValue*)&wku16, CMPI_uint16);
+ CMSetProperty(instance, "EnabledState", (CMPIValue*)&wku16, CMPI_uint16);
+ wku16 = 5;
+ CMSetProperty(instance, "HealthState", (CMPIValue*)&wku16, CMPI_uint16);
+ datetime = CMNewDateTimeFromBinary(_broker, omcGetRPMInstallDate(RPM_NAME), 0, NULL);
+ CMSetProperty(instance, "InstallDate", (CMPIValue*)&datetime, CMPI_dateTime);
+ pra = CMNewArray(_broker, 1, CMPI_uint16, NULL);
+ wku16 = 2;
+ CMSetArrayElementAt(pra, 0, (CMPIValue*)&wku16, CMPI_uint16);
+ CMSetProperty(instance, "OperationalStatus", (CMPIValue*)&pra, CMPI_uint16A);
+ wku16 = 12;
+ CMSetProperty(instance, "RequestedState", (CMPIValue*)&wku16, CMPI_uint16);
+ CMSetProperty(instance, "StartMode", (CMPIValue*)"Automatic", CMPI_chars);
+ return 0;
+}
+
+/******************************************************************************
+ CMPI INSTANCE PROVIDER FUNCTIONS
+******************************************************************************/
+
+
+
+/******************************************************************************
+EnumInstanceNames()
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIResult* results: [out] Results
+ CMPIObjectPath* cop: [in] target namespace and classname, and desired objectpath
+ char **properties: [in] propertylist filter, null=all
+******************************************************************************/
+static CMPIStatus
+EnumInstanceNames(
+ CMPIInstanceMI* self,
+ const CMPIContext* context,
+ const CMPIResult* results,
+ const CMPIObjectPath* cop)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ CMPIObjectPath* objectpath;
+ char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ char hname[256];
+ char *className;
+
+ DEBUGOUT("EnumInstanceNames() called\n");
+
+ className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_VMBuilderService") == 0)
+ {
+ objectpath = CMNewObjectPath(_broker, ns, "XEN_VMBuilderService", &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath))
+ {
+ DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() failed - %s\n", CMGetCharPtr(status.msg));
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, "Failed creating new object path");
+ return status;
+ }
+
+ if (!omcGetComputerSystemName(hname, sizeof(hname)))
+ {
+ omcStrNCpy(hname, "localhost", sizeof(hname));
+ }
+
+ CMAddKey(objectpath, "CreationClassName", (CMPIValue*)"XEN_VMBuilderService", CMPI_chars);
+ CMAddKey(objectpath, "Name", (CMPIValue*)SERVICE_NAME, CMPI_chars);
+ CMAddKey(objectpath, "SystemCreationClassName", (CMPIValue*)omcGetComputerSystemClassName(), CMPI_chars);
+ CMAddKey(objectpath, "SystemName", (CMPIValue*)hname, CMPI_chars);
+ CMReturnObjectPath(results, objectpath);
+ CMReturnDone(results);
+ }
+ DEBUGOUT("Leaving EnumInstanceNames(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ return status;
+}
+
+/******************************************************************************
+EnumInstances()
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIResult* results: [out] Results
+ CMPIObjectPath* cop: [in] target namespace and classname, and desired objectpath
+ char **properties: [in] propertylist filter, null=all
+******************************************************************************/
+static CMPIStatus
+EnumInstances(
+ CMPIInstanceMI* self,
+ const CMPIContext* context,
+ const CMPIResult* results,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ char * ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ CMPIInstance* instance;
+ char hname[256], *className;
+
+ DEBUGOUT("EnumInstances() called\n");
+
+ className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_VMBuilderService") == 0)
+ {
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderService",
+ service_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance))
+ {
+ DEBUGOUT("EnumInstances(): CMNewInstance() failed - %s\n", CMGetCharPtr(status.msg));
+ return status;
+ }
+
+ if (!omcGetComputerSystemName(hname, sizeof(hname)))
+ {
+ omcStrNCpy(hname, "localhost", sizeof(hname));
+ }
+ fillServiceInstance(instance, hname);
+ CMReturnInstance(results, instance);
+ CMReturnDone(results);
+ }
+ DEBUGOUT("Leaving EnumInstances(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ return status;
+}
+
+
+/******************************************************************************
+GetInstance()
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIResult* results: [out] Results
+ CMPIObjectPath* cop: [in] target namespace and classname, and desired objectpath
+ char **properties: [in] propertylist filter, null=all
+******************************************************************************/
+static CMPIStatus
+GetInstance(
+ CMPIInstanceMI* self,
+ const CMPIContext* context,
+ const CMPIResult* results,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ CMPIInstance* instance;
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ const char *className;
+ char hname[256];
+
+ DEBUGOUT("GetInstance() called\n");
+
+ className = CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_VMBuilderService") == 0)
+ {
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderService",
+ service_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance))
+ {
+ DEBUGOUT("EnumInstances(): CMNewInstance() failed - %s\n", CMGetCharPtr(status.msg));
+ }
+ else
+ {
+ if (!omcGetComputerSystemName(hname, sizeof(hname)))
+ {
+ omcStrNCpy(hname, "localhost", sizeof(hname));
+ }
+ fillServiceInstance(instance, hname);
+ CMReturnInstance(results, instance);
+ }
+ }
+ DEBUGOUT("Leaving GetInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ return status;
+}
+
+
+/******************************************************************************
+ModifyInstance() - modify instance
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIResult* results: [out] Results
+ CMPIObjectPath* cop: [in] target namespace and classname, and objectpath
+ CMPIInstance* newInst: [in] new (modified) instance data
+******************************************************************************/
+static CMPIStatus
+ModifyInstance(
+ CMPIInstanceMI* self,
+ const CMPIContext* context,
+ const CMPIResult* results,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* newinstance,
+ const char** properties)
+{
+ CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
+ return status;
+}
+
+
+/******************************************************************************
+CreateInstance()
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIResult* results: [out] Results
+ CMPIObjectPath* cop: [in] target namespace and classname, and objectpath
+ CMPIInstance* newInst: [in] new instance data
+******************************************************************************/
+static CMPIStatus
+CreateInstance(
+ CMPIInstanceMI* self,
+ const CMPIContext* context,
+ const CMPIResult* results,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* newinstance)
+{
+ CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
+ return status;
+}
+
+
+/******************************************************************************
+DeleteInstance()
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIResult* results: [out] Results
+ CMPIObjectPath* cop: [in] target namespace and classname
+******************************************************************************/
+static CMPIStatus
+DeleteInstance(
+ CMPIInstanceMI* self,
+ const CMPIContext* context,
+ const CMPIResult* results,
+ const CMPIObjectPath* cop)
+{
+ CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
+ return status;
+}
+
+/******************************************************************************
+ExecQuery() - like getInstance, but that match query
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIResult* results: [out] Results
+ CMPIObjectPath* cop: [in] target namespace and classname
+ char *language: [in] query language, ie "WQL"
+ char *query: [in] text of query, in <query language>
+******************************************************************************/
+static CMPIStatus
+ExecQuery(
+ CMPIInstanceMI* self,
+ const CMPIContext* context,
+ const CMPIResult* results,
+ const CMPIObjectPath* cop,
+ const char* language,
+ const char* query)
+{
+ CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
+ return status;
+}
+
+/******************************************************************************
+ Init()
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+******************************************************************************/
+static void
+Init(
+ CMPIInstanceMI* self)
+{
+ DEBUGOUT("Initialize() called\n");
+
+ DEBUGOUT("Leaving Initialize()\n");
+}
+
+/******************************************************************************
+Cleanup() - pre unload
+ params: CMPIInstanceMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIBoolean terminating
+******************************************************************************/
+static CMPIStatus
+Cleanup(
+ CMPIInstanceMI* self,
+ const CMPIContext* context,
+ CMPIBoolean terminating)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+
+ DEBUGOUT("Cleanup() called\n");
+
+ DEBUGOUT("Leaving Cleanup(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ return status;
+}
+
+// ****************************************************************************
+// MethodInit() - init
+// params: CMPIMethodMI* self: [in] Handle to this provider
+// ****************************************************************************
+static void
+MethodInit(
+ CMPIMethodMI * self)
+{
+ DEBUGOUT("MethodInitialize() called\n");
+
+ // do work here if necessary
+
+ DEBUGOUT("Leaving MethodInitialize()\n");
+}
+
+/******************************************************************************
+MethodCleanup() - pre unload
+ params: CMPIMethodMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIBoolean terminating
+******************************************************************************/
+static CMPIStatus
+MethodCleanup(
+ CMPIMethodMI* self,
+ const CMPIContext* context,
+ CMPIBoolean terminating)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+
+ DEBUGOUT("MethodCleanup() called\n");
+
+ DEBUGOUT("Leaving Cleanup(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ return status;
+}
+
+// ****************************************************************************
+// InvokeMethod()
+// params: CMPIMethodMI* self: [in] Handle to this provider
+// CMPIContext* context: [in] any additional context info
+// CMPIResult* results: [out] Results
+// CMPIObjectPath* cop: [in] target namespace and classname, and desired objectpath
+// char *methodName
+// CMPIArgs *in
+// CMPIArgs *out
+// ****************************************************************************
+static CMPIStatus
+InvokeMethod(
+ CMPIMethodMI* self,
+ const CMPIContext* context,
+ const CMPIResult* results,
+ const CMPIObjectPath* cop,
+ const char *methodName,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ CMPIString *class = NULL;
+ CMPIValue rv;
+ /* char *ns = CMGetCharPtr(CMGetNameSpace(cop, NULL)); */
+
+ DEBUGOUT("InvokeMethod() called. methodName: %s\n", methodName);
+
+ class = CMGetClassName(cop, &status);
+ if (strcasecmp(CMGetCharPtr(class), "XEN_VMBuilderService") != 0)
+ {
+ DEBUGOUT("InvokeMethod() INVALID class name %s\n", CMGetCharPtr(class));
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_CLASS,
+ CMGetCharPtr(class));
+ return status;
+ }
+
+ if (strcasecmp("CreateVM", methodName) == 0)
+ {
+ OMC_SETSTATUS(_broker, &status,
+ CMPI_RC_ERR_NOT_SUPPORTED,
+ "Not implemented yet");
+ rv.uint32 = 1; // Not supported
+ CMReturnData(results, &rv, CMPI_uint32);
+ CMReturnDone(results);
+ }
+ else if (strcasecmp("RequestStateChange", methodName) == 0)
+ {
+ CMLogMessage(_broker, 1, "VMBuilderService provider",
+ "RequestStateChange called, but not supported", NULL);
+ rv.uint32 = 1; // Not supported
+ CMReturnData(results, &rv, CMPI_uint32);
+ CMReturnDone(results);
+ }
+ else if (strcasecmp("StartService", methodName) == 0)
+ {
+ CMLogMessage(_broker, 1, "VMBuilderService provider",
+ "StartService called, but not supported", NULL);
+ rv.uint32 = 1; // Not supported
+ OMC_SETSTATUS(_broker, &status,
+ CMPI_RC_ERR_NOT_SUPPORTED,
+ "Cannot start VMBuilder Service. Always running");
+ rv.uint32 = 1; // Not supported
+ CMReturnData(results, &rv, CMPI_uint32);
+ CMReturnDone(results);
+ }
+ else if (strcasecmp("StopService", methodName) == 0)
+ {
+ CMLogMessage(_broker, 1, "VMBuilderService provider",
+ "StopService called, but not supported", NULL);
+ OMC_SETSTATUS(_broker, &status,
+ CMPI_RC_ERR_NOT_SUPPORTED,
+ "Cannot stop VMBuilder Service. Always running");
+ rv.uint32 = 1; // Not supported
+ CMReturnData(results, &rv, CMPI_uint32);
+ CMReturnDone(results);
+ }
+ else
+ {
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, methodName);
+ }
+ DEBUGOUT("Leaving InvokeMethod(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ return status;
+}
+
+/*****************************************************************************
+ SETUP CMPI INSTANCE PROVIDER FUNCTION TABLE
+******************************************************************************/
+
+/* Macros to create entry points, function tables, etc.
+ Params:
+ 1: _optional_ prefix for function names.
+ 2: the name of the provider (within the cimom - must be unique among all
+ providers. Recommended: <OMC_FooClass>_Provider
+ This is the same name that must be used to register the provider
+ with the cimom
+ 3: local static variable for CMPIBroker (cimom handle)
+ Initialized by cimom when the provider is loaded.
+ 4: provider's additional init function, called right after provider load.
+ If no additional init is required, specify "CMNoHook"
+*/
+
+CMInstanceMIStub( , XEN_VMBuilderService, _broker, Init(&mi));
+CMMethodMIStub( , XEN_VMBuilderService, _broker, MethodInit(&mi));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|