|
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.
|
|
From: <jc...@us...> - 2008-04-29 22:32:27
|
Revision: 593
http://omc.svn.sourceforge.net/omc/?rev=593&view=rev
Author: jcarey
Date: 2008-04-29 15:32:28 -0700 (Tue, 29 Apr 2008)
Log Message:
-----------
Builder database routines
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
Added Paths:
-----------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
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-25 23:47:48 UTC (rev 592)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-04-29 22:32:28 UTC (rev 593)
@@ -4,6 +4,9 @@
libomc_xenvmbuilder.la \
libomc_xenvmbuilderjob.la
+lib_LTLIBRARIES = \
+ libomc_xenvmbuilder_common.la
+
INCLUDES = -I$(top_builddir)
libomc_xenvmbuilder_la_SOURCES = \
@@ -14,6 +17,9 @@
-lomc_cmpi \
-version-info 1
+libomc_xenvmbuilder_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+
libomc_xenvmbuilderjob_la_SOURCES = \
builder-job.c
@@ -22,4 +28,19 @@
-lomc_cmpi \
-version-info 1
+libomc_xenvmbuilderjob_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+libomc_xenvmbuilder_common_la_SOURCES = \
+ vmbuild-db.c \
+ vmbuilder-db.h
+
+libomc_xenvmbuilder_common_la_LDFLAGS = \
+ -lpthread \
+ -lomc_cmpi \
+ -lsqlite3 \
+ -version-info 1
+
+
+
+
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 2008-04-29 22:32:28 UTC (rev 593)
@@ -0,0 +1,449 @@
+#include "vmbuilder-db.h"
+#include <sqlite3.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+#include <omc/string.h>
+#include <errno.h>
+#include <ctype.h>
+
+/*
+ * _create_sql is the schema of the database.
+ * When the database is opened for the very first
+ * time, this sql will be used to set up the schema.
+ */
+const char* _create_sql =
+"CREATE TABLE CreationData("
+ "InstanceID TEXT NOT NULL COLLATE NOCASE,"
+ //-- 2: None
+ //-- 3: Restart
+ //-- 4: Revert to snapshot
+ "AutoMaticRecoveryAction INTEGER,"
+ //-- 2: Turn off
+ //-- 3: Save state
+ //-- 4: Shutdown
+ "AutoMaticShutdownAction INTEGER,"
+ //-- 2: None
+ //-- 3: Restart if previously active
+ //-- 4: Always start up
+ "AutoMaticStartupAction INTEGER,"
+ "AutoMaticStartupActionDelay INTEGER,"
+ "AutoMaticStartupActionSequenceNumber INTEGER,"
+ "CPUArchitecture TEXT,"
+ "Caption TEXT,"
+ //-- 0: Not changable (persistent)
+ //-- 1: Changable (transient)
+ //-- 2: Changable (persistent)
+ //-- 3: Not changable (transient)
+ "ChangableType INTEGER,"
+ "ConfigurationDataRoot TEXT,"
+ "ConfigurationFile TEXT,"
+ "ConfigurationID TEXT,"
+ "ConfigurationName TEXT,"
+ "CreationTime INTEGER,"
+ "Description TEXT,"
+ //-- String Array
+ "Disks TEXT,"
+ "ElementName TEXT,"
+ //-- String Array
+ "ExtraConfigInfo TEXT,"
+ "ExtraInstallArgs TEXT,"
+ //-- 0: Unknown
+ //-- 1: Cirrus
+ //-- 2: None
+ //-- 3: Para
+ //-- 4: Vesa
+ "GraphicsType INTEGER,"
+ //-- 0: Unknown
+ //-- 1: SDL
+ //-- 2: VNC
+ "GraphicsViewerType INTEGER,"
+ "LogDataRoot TEXT,"
+ "MaxMemory INTEGER,"
+ "Memory INTEGER,"
+ //-- String Array
+ "Nics TEXT,"
+ //-- String Array
+ "Notes TEXT,"
+ "NumVCPUs INTEGER,"
+ //-- See MOF
+ "OSType INTEGER,"
+ "RecoveryFile TEXT,"
+ "ResponseFile TEXT,"
+ "SnapshotDataRoot TEXT,"
+ "SourceURL TEXT,"
+ "SuspendDataRoot TEXT,"
+ "SwapFileDataRoot TEXT,"
+ "UUID TEXT,"
+ "VNCPort INTEGER,"
+ //-- 0: Unknown
+ //-- 1: Para
+ //-- 2: Full
+ "VirtType INTEGER,"
+ "VirtualSystemIdentifier TEXT,"
+ "VirtualSystemType TEXT,"
+ "PRIMARY KEY(InstanceID COLLATE NOCASE));"
+"CREATE TABLE Job("
+ "JobName TEXT NOT NULL,"
+ "CreationDataInstanceID TEXT NOT NULL COLLATE NOCASE,"
+ "PRIMARY KEY(JobName, CreationDataInstanceID COLLATE NOCASE));";
+
+typedef struct
+{
+ sqlite3 *db;
+ sqlite3_stmt *stmt;
+ const char* tail;
+ int col_count;
+ char** row_data;
+ int lastcc;
+ char* format_buf;
+} VMBDBCtx_t;
+
+/*
+ * _db_busy_handler is registered with sqlite when
+ * the database is open. It is called when sqlite
+ * encounters a locked condition on the database.
+ */
+static int
+_db_busy_handler(void* cbdata, int call_count)
+{
+ // Logging?
+ if (call_count > 10)
+ {
+ // Been waiting for the lock condition for to long.
+ // return failure, so the sqlite call will fail.
+ return 0;
+ }
+ // Sleep 1 second and return 1 so sqlite will try the
+ // operation again.
+ sleep(1); // unistd sleep(seconds)
+ return 1;
+}
+
+/*
+ * @return 1 if string is nothing but space
+ */
+static int
+_str_is_empty(const char* str)
+{
+ if (str)
+ {
+ while (*str)
+ {
+ if (!isspace(*str))
+ return 0;
+ str++;
+ }
+ }
+ return 1;
+}
+
+/*
+ * @return 1 if the given path is a directory, otherwise 0
+ */
+static int
+_is_dir(const char* path)
+{
+ struct stat st;
+ if (stat(path, &st) == 0
+ && S_ISDIR(st.st_mode))
+ {
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Create a directory. If necessary this method will create any non-existent
+ * parent directories until the full path is created.
+ * Assumption: path argument is an absolute path
+ */
+static int
+_make_dirs(const char* path)
+{
+ char cur_path[PATH_MAX+1];
+ char** toks;
+ size_t number_of_toks, i;
+
+ cur_path[0] = '\0';
+ toks = omcStrTokenize(path, "/", &number_of_toks);
+ if (!toks)
+ {
+ // Invalid path?
+ return -1;
+ }
+
+ for(i = 0; toks[i]; i++)
+ {
+ omcStrAppend(cur_path, "/", sizeof(cur_path));
+ omcStrAppend(cur_path, toks[i], sizeof(cur_path));
+ if (!_is_dir(cur_path))
+ {
+ if (mkdir(cur_path, 0755) != 0)
+ {
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * _get_db_connection will do the following:
+ * - Check for the existence of the database. If it does not exist, it will
+ * create it with the appropriate schema.
+ * - Return a connection (sqlite3*) to the database in the db arg.
+ * - If an error occurs, the err_msg arg will contain an error message
+ * describing the reason for the error.
+ */
+static int
+_get_db_connection(sqlite3** db, char* err_msg, size_t err_msg_len)
+{
+ char *zErr = 0;
+
+ if (!_is_dir(VMB_DB_DIR))
+ {
+ if (_make_dirs(VMB_DB_DIR) != 0)
+ {
+ omcStrNCpy(err_msg, "Failed to create directory "VMB_DB_DIR,
+ err_msg_len);
+ return -1;
+ }
+ }
+ // If database doesn't exist
+ if (access(VMB_DB_NAME, F_OK) != 0)
+ { // Database does NOT exist
+
+ // Create Database
+ if (sqlite3_open(VMB_DB_NAME, db))
+ {
+ snprintf(err_msg, err_msg_len,
+ "Failed to open database "VMB_DB_NAME": %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close(*db);
+ return -1;
+ }
+ // Extend schema
+ if (sqlite3_exec(*db, _create_sql, NULL, NULL, &zErr) != SQLITE_OK)
+ {
+ if (zErr != NULL)
+ {
+ snprintf(err_msg, err_msg_len,
+ "Failed executing sql statement: %s", zErr);
+ sqlite3_free(zErr);
+ }
+ else
+ {
+ omcStrNCpy(err_msg, "Failed executing sql statement", err_msg_len);
+ }
+ sqlite3_close(*db);
+ return -1;
+ }
+ }
+ else
+ { // Database does exist - Just open
+ if (sqlite3_open(VMB_DB_NAME, db))
+ {
+ snprintf(err_msg, err_msg_len,
+ "Failed to open database "VMB_DB_NAME": %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close(*db);
+ return -1;
+ }
+ }
+ sqlite3_busy_handler(*db, _db_busy_handler, NULL);
+ return 0;
+}
+
+/*
+ * Create a connection context to the database
+ */
+int
+db_create_connection(VMBDBCtx* ctx, const char* query, char* err_msg,
+ size_t err_msg_len)
+{
+ VMBDBCtx_t *pctx;
+ if (_str_is_empty(query))
+ {
+ omcStrNCpy(err_msg, "Invalid parameter: query arg is required",
+ err_msg_len);
+ return -1;
+ }
+
+ pctx = (VMBDBCtx_t*) calloc(1, sizeof(VMBDBCtx_t));
+ if (!pctx)
+ {
+ omcStrNCpy(err_msg, "Memory Allocation Error", err_msg_len);
+ return -1;
+ }
+ if (_get_db_connection(&pctx->db, err_msg, err_msg_len) != 0)
+ {
+ free(pctx);
+ return -1;
+ }
+
+ if (sqlite3_prepare(pctx->db, query, strlen(query), &pctx->stmt,
+ &pctx->tail) != SQLITE_OK)
+ {
+ snprintf(err_msg, err_msg_len, "Failed preparing DB Query: %s",
+ sqlite3_errmsg(pctx->db));
+ sqlite3_finalize(pctx->stmt);
+ sqlite3_close(pctx->db);
+ free(pctx);
+ return -1;
+ }
+
+ pctx->col_count = sqlite3_column_count(pctx->stmt);
+ pctx->lastcc = sqlite3_step(pctx->stmt);
+ *ctx = (void*)pctx;
+ return 0;
+}
+
+/*
+ * Destroy a connection context to the database
+ */
+void
+db_destroy_connection(VMBDBCtx ctx)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx)
+ {
+ if (pctx->stmt)
+ {
+ sqlite3_finalize(pctx->stmt);
+ }
+ sqlite3_close(pctx->db);
+ free(pctx);
+ if (pctx->format_buf)
+ {
+ sqlite3_free(pctx->format_buf);
+ }
+ }
+}
+
+/*
+ * @return 1 if the current result set has more rows. Otherwise 0.
+ */
+int
+db_has_more_rows(VMBDBCtx ctx)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ return (pctx && pctx->lastcc == SQLITE_ROW) ? 1 : 0;
+}
+
+/*
+ * Position the cursor to the next row in the result set
+ * if there are more rows.
+ * @return 0 for success otherwise -1
+ */
+int db_goto_next_row(VMBDBCtx ctx)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx)
+ {
+ if (pctx->lastcc == SQLITE_ROW)
+ {
+ pctx->lastcc = sqlite3_step(pctx->stmt);
+ return 0;
+ }
+ }
+ return -1;
+}
+
+/*
+ * @return The number of columns per row for the result set,
+ * or -1 on error.
+ */
+int
+db_get_column_count(VMBDBCtx ctx)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ return pctx ? pctx->col_count : -1;
+}
+
+/*
+ * @return The data for a given column for the current result set,
+ * or NULL on error.
+ */
+const unsigned char*
+db_get_column_data(VMBDBCtx ctx, size_t column_index)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx && pctx->col_count && column_index < pctx->col_count)
+ return sqlite3_column_text(pctx->stmt, (int)column_index);
+ return NULL;
+}
+
+char*
+db_format_sql(VMBDBCtx ctx, const char* format, ...)
+{
+ va_list marker;
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (!pctx)
+ {
+ return NULL;
+ }
+ if (pctx->format_buf)
+ {
+ sqlite3_free(pctx->format_buf);
+ pctx->format_buf = NULL;
+ }
+ va_start(marker, format);
+ pctx->format_buf = sqlite3_vmprintf(format, marker);
+ va_end(marker);
+ return pctx->format_buf;
+}
+
+/*
+ * Execute the specified sql against the database.
+ * If the operation fails -1LL will be returned with
+ * the err_msg param containing and error message describing the failue.
+ * If the operation succeeds, the last insert row id is returned if the
+ * operation caused an insert. If it did not cause an insert 0LL will
+ * be returned.
+ */
+long long
+db_exec(const char* sql, char* err_msg, size_t err_msg_len)
+{
+ int cc;
+ sqlite3 *db;
+ char* zErr = NULL;
+ long long insert_row_id = -1LL;
+
+ if (_get_db_connection(&db, err_msg, err_msg_len) != 0)
+ {
+ return -1LL;
+ }
+
+ cc = sqlite3_exec(db, sql, NULL, NULL, &zErr);
+ if (cc != SQLITE_OK)
+ {
+ if (zErr)
+ {
+ snprintf(err_msg, err_msg_len,
+ "Failed executing sql statement: %s", zErr);
+ sqlite3_free(zErr);
+ }
+ else
+ {
+ omcStrNCpy(err_msg, "Failed executing sql statement", err_msg_len);
+ }
+ }
+ else
+ {
+ insert_row_id = sqlite3_last_insert_rowid(db);
+ }
+
+ sqlite3_close(db);
+ return insert_row_id;
+}
+
+
+
+
+
+
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-04-29 22:32:28 UTC (rev 593)
@@ -0,0 +1,21 @@
+#ifndef VMBGUILDER_DB_H_GUARD_
+#define VMBGUILDER_DB_H_GUARD_
+
+#include <stdlib.h>
+
+#define VMB_DB_DIR "/var/opt/xen-vm-builder/db"
+#define VMB_DB_FILE_NAME "vmbuilder.db"
+#define VMB_DB_NAME VMB_DB_DIR"/"VMB_DB_FILE_NAME
+
+typedef void* VMBDBCtx;
+
+int db_create_connection(VMBDBCtx* ctx, const char* query, char* err_msg, size_t err_msg_len);
+void db_destroy_connection(VMBDBCtx ctx);
+int db_has_more_rows(VMBDBCtx ctx);
+int db_goto_next_row(VMBDBCtx ctx);
+int db_get_column_count(VMBDBCtx ctx);
+const unsigned char* db_get_column_data(VMBDBCtx ctx, size_t column_index);
+char* db_format_sql(VMBDBCtx ctx, const char* format, ...);
+long long db_exec(const char* sql, char* err_msg, size_t err_msg_len);
+
+#endif // VMBGUILDER_DB_H_GUARD_
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jc...@us...> - 2008-04-29 22:55:25
|
Revision: 594
http://omc.svn.sourceforge.net/omc/?rev=594&view=rev
Author: jcarey
Date: 2008-04-29 15:55:15 -0700 (Tue, 29 Apr 2008)
Log Message:
-----------
Changed format to not be tied to a db context
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 2008-04-29 22:32:28 UTC (rev 593)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 2008-04-29 22:55:15 UTC (rev 594)
@@ -100,7 +100,6 @@
int col_count;
char** row_data;
int lastcc;
- char* format_buf;
} VMBDBCtx_t;
/*
@@ -318,10 +317,6 @@
}
sqlite3_close(pctx->db);
free(pctx);
- if (pctx->format_buf)
- {
- sqlite3_free(pctx->format_buf);
- }
}
}
@@ -379,25 +374,22 @@
}
char*
-db_format_sql(VMBDBCtx ctx, const char* format, ...)
+db_create_formatted_sql(const char* format, ...)
{
va_list marker;
- VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
- if (!pctx)
- {
- return NULL;
- }
- if (pctx->format_buf)
- {
- sqlite3_free(pctx->format_buf);
- pctx->format_buf = NULL;
- }
+ char* formatted_sql;
va_start(marker, format);
- pctx->format_buf = sqlite3_vmprintf(format, marker);
+ formatted_sql = sqlite3_vmprintf(format, marker);
va_end(marker);
- return pctx->format_buf;
+ return formatted_sql;
}
+void
+db_destroy_formatted_sql(char* formatted_sql)
+{
+ sqlite3_free(formatted_sql);
+}
+
/*
* Execute the specified sql against the database.
* If the operation fails -1LL will be returned with
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-04-29 22:32:28 UTC (rev 593)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-04-29 22:55:15 UTC (rev 594)
@@ -15,7 +15,8 @@
int db_goto_next_row(VMBDBCtx ctx);
int db_get_column_count(VMBDBCtx ctx);
const unsigned char* db_get_column_data(VMBDBCtx ctx, size_t column_index);
-char* db_format_sql(VMBDBCtx ctx, const char* format, ...);
long long db_exec(const char* sql, char* err_msg, size_t err_msg_len);
+char* db_create_formatted_sql(const char* format, ...);
+void db_destroy_formatted_sql(char* formatted_sql);
#endif // VMBGUILDER_DB_H_GUARD_
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jc...@us...> - 2008-05-05 15:09:49
|
Revision: 596
http://omc.svn.sourceforge.net/omc/?rev=596&view=rev
Author: jcarey
Date: 2008-05-05 08:09:41 -0700 (Mon, 05 May 2008)
Log Message:
-----------
some name changes
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
Added Paths:
-----------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.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-30 17:11:01 UTC (rev 595)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-05-05 15:09:41 UTC (rev 596)
@@ -2,13 +2,17 @@
provider_LTLIBRARIES = \
libomc_xenvmbuilder.la \
- libomc_xenvmbuilderjob.la
+ libomc_xenvmbuilderjob.la \
+ libomc_xencreationdata.la
lib_LTLIBRARIES = \
libomc_xenvmbuilder_common.la
INCLUDES = -I$(top_builddir)
+###
+# libomc_xenvmbuilder
+###
libomc_xenvmbuilder_la_SOURCES = \
builder-service.c
@@ -20,6 +24,9 @@
libomc_xenvmbuilder_la_LIBADD = \
$(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+###
+# libomc_xenvmbuilderjob
+###
libomc_xenvmbuilderjob_la_SOURCES = \
builder-job.c
@@ -31,6 +38,23 @@
libomc_xenvmbuilderjob_la_LIBADD = \
$(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+###
+# libomc_xencreationdata
+###
+libomc_xencreationdata_la_SOURCES = \
+ vmcreation-data.c
+
+libomc_xencreationdata_la_LDFLAGS = \
+ -lpthread \
+ -lomc_cmpi \
+ -version-info 1
+
+libomc_xencreationdata_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+
+###
+# libomc_xenvmbuilder_common
+###
libomc_xenvmbuilder_common_la_SOURCES = \
vmbuild-db.c \
vmbuilder-db.h
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-04-30 17:11:01 UTC (rev 595)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-05 15:09:41 UTC (rev 596)
@@ -226,7 +226,7 @@
CMPIObjectPath* ref = CMNewObjectPath(_broker, ns,
"XEN_VMBUilderJob", &status);
if (status.rc != CMPI_RC_OK || CMIsNullObject(ref)) {
- DEBUGOUT("EnumbInstanceNames(): CMNewObjectPath() "
+ DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() "
"failed - %s\n", CMGetCharPtr(status.msg));
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed creating object path");
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-04-30 17:11:01 UTC (rev 595)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-05 15:09:41 UTC (rev 596)
@@ -95,13 +95,11 @@
char hname[256];
objectpath = CMNewObjectPath(_broker, ns, "XEN_VMBuilderService", pstatus);
- if ((pstatus->rc != CMPI_RC_OK) || CMIsNullObject(objectpath))
- {
+ if ((pstatus->rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
return NULL;
}
- if (!omcGetComputerSystemName(hname, sizeof(hname)))
- {
+ if (!omcGetComputerSystemName(hname, sizeof(hname))) {
omcStrNCpy(hname, "localhost", sizeof(hname));
}
CMAddKey(objectpath, "CreationClassName",
@@ -124,14 +122,15 @@
CMPIArray *pra;
char hostName[256];
- if (!omcGetComputerSystemName(hostName, sizeof(hostName)))
- {
+ if (!omcGetComputerSystemName(hostName, sizeof(hostName))) {
omcStrNCpy(hostName, "localhost", sizeof(hostName));
}
- CMSetProperty(instance, "CreationClassName", (CMPIValue*)"XEN_VMBuilderService", CMPI_chars);
+ 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, "SystemCreationClassName",
+ (CMPIValue*)omcGetComputerSystemClassName(), CMPI_chars);
CMSetProperty(instance, "SystemName", (CMPIValue*)hostName, CMPI_chars);
pra = CMNewArray(_broker, 1, CMPI_uint16, NULL);
wku16 = 2;
@@ -188,11 +187,9 @@
DEBUGOUT("EnumInstanceNames() called\n");
className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
- if (strcasecmp(className, "XEN_VMBuilderService") == 0)
- {
+ if (strcasecmp(className, "XEN_VMBuilderService") == 0) {
objectpath = get_service_ref(ns, &status);
- if ((status.rc != CMPI_RC_OK) || objectpath == NULL)
- {
+ if ((status.rc != CMPI_RC_OK) || objectpath == NULL) {
DEBUGOUT("EnumInstanceNames(): get_service_ref() failed - %s\n",
CMGetCharPtr(status.msg));
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
@@ -202,12 +199,10 @@
CMReturnObjectPath(results, objectpath);
CMReturnDone(results);
}
- else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0)
- {
+ else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) {
CMPIObjectPath *antref, *depref;
objectpath = CMNewObjectPath(_broker, ns, "XEN_VMBuilderHostedService", &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath))
- {
+ 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,
@@ -215,8 +210,7 @@
return status;
}
depref = get_service_ref(ns, &status);
- if ((status.rc != CMPI_RC_OK) || depref == NULL)
- {
+ if ((status.rc != CMPI_RC_OK) || depref == NULL) {
DEBUGOUT("EnumInstanceNames(): get_service_ref() failed - %s\n",
CMGetCharPtr(status.msg));
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
@@ -225,8 +219,7 @@
}
CMAddKey(objectpath, "Dependent", (CMPIValue*)&depref, CMPI_ref);
antref = omccmpiCreateCSObjectPath(_broker, ns, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(antref))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(antref)) {
DEBUGOUT("EnumInstanceNames(): omccmpiCreateCSObjectPath failed - %s\n",
CMGetCharPtr(status.msg));
return status;
@@ -264,12 +257,10 @@
DEBUGOUT("EnumInstances() called\n");
className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
- if (strcasecmp(className, "XEN_VMBuilderService") == 0)
- {
+ 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))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
DEBUGOUT("EnumInstances(): CMNewInstance() failed - %s\n", CMGetCharPtr(status.msg));
return status;
}
@@ -278,13 +269,11 @@
CMReturnInstance(results, instance);
CMReturnDone(results);
}
- else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0)
- {
+ else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) {
CMPIObjectPath *antref, *depref;
instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
hosted_service_class_keys, properties, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
DEBUGOUT("EnumInstances(): failed to create new instance: %s\n",
CMGetCharPtr(status.msg));
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
@@ -292,8 +281,7 @@
return status;
}
depref = get_service_ref(ns, &status);
- if ((status.rc != CMPI_RC_OK) || depref == NULL)
- {
+ if ((status.rc != CMPI_RC_OK) || depref == NULL) {
DEBUGOUT("EnumInstances(): get_service_ref() failed - %s\n",
CMGetCharPtr(status.msg));
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
@@ -302,8 +290,7 @@
}
CMSetProperty(instance, "Dependent", (CMPIValue*)&depref, CMPI_ref);
antref = omccmpiCreateCSObjectPath(_broker, ns, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(antref))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(antref)) {
DEBUGOUT("EnumInstances(): omccmpiCreateCSObjectPath failed - %s\n",
CMGetCharPtr(status.msg));
return status;
@@ -342,61 +329,51 @@
DEBUGOUT("GetInstance() called\n");
className = CMGetCharPtr(CMGetClassName(cop, NULL));
- if (strcasecmp(className, "XEN_VMBuilderService") == 0)
- {
+ if (strcasecmp(className, "XEN_VMBuilderService") == 0) {
objectpath = get_service_ref(ns, &status);
- if (status.rc != CMPI_RC_OK || objectpath == NULL)
- {
+ if (status.rc != CMPI_RC_OK || objectpath == NULL) {
DEBUGOUT("GetInstance(): get_service_ref failed - %s\n",
CMGetCharPtr(status.msg));
return status;
}
- if (!omccmpiAreObjectPathsSame(cop, objectpath, &status))
- {
+ if (!omccmpiAreObjectPathsSame(cop, objectpath, &status)) {
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Instance does not exists");
return status;
}
instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderService",
service_class_keys, properties, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
DEBUGOUT("EnumInstances(): CMNewInstance() failed - %s\n", CMGetCharPtr(status.msg));
}
- else
- {
+ else {
fillServiceInstance(instance);
CMReturnInstance(results, instance);
}
}
- if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0)
- {
+ if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) {
CMPIData antecedent, dependent;
antecedent = CMGetKey(cop, "Antecedent", &status);
- if (status.rc != CMPI_RC_OK || CMIsNullValue(antecedent))
- {
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(antecedent)) {
DEBUGOUT("GetInstance(): CMGetKey(\"Antecedent\") failed - %s\n",
CMGetCharPtr(status.msg));
CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_NO_SUCH_PROPERTY,
"Antecedent missing");
return status;
}
- if (antecedent.type != CMPI_ref)
- {
+ if (antecedent.type != CMPI_ref) {
DEBUGOUT("GetInstance(): Invalid 'Antecedent' key property type\n");
CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER,
"Antecedent key invalid");
return status;
}
objectpath = omccmpiCreateCSObjectPath(_broker, ns, &status);
- if (status.rc != CMPI_RC_OK || CMIsNullObject(objectpath))
- {
+ if (status.rc != CMPI_RC_OK || CMIsNullObject(objectpath)) {
DEBUGOUT("GetInstance(): omccmpiCreateCSObjectPath failed - %s\n",
CMGetCharPtr(status.msg));
return status;
}
- if (!omccmpiAreObjectPathsSame(antecedent.value.ref, objectpath, &status))
- {
+ if (!omccmpiAreObjectPathsSame(antecedent.value.ref, objectpath, &status)) {
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Instance does not exists");
return status;
@@ -407,16 +384,14 @@
CMSetProperty(instance, "Antecedent", (CMPIValue*)&objectpath, CMPI_ref);
dependent = CMGetKey(cop, "Dependent", &status);
- if (status.rc != CMPI_RC_OK || CMIsNullValue(dependent))
- {
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(dependent)) {
DEBUGOUT("GetInstance(): CMGetKey(\"Dependent\") failed - %s\n",
CMGetCharPtr(status.msg));
CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_NO_SUCH_PROPERTY,
"Dependent missing");
return status;
}
- if (dependent.type != CMPI_ref)
- {
+ if (dependent.type != CMPI_ref) {
DEBUGOUT("GetInstance(): Invalid 'Dependent' key property type\n");
CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER,
"Dependent key invalid");
@@ -424,14 +399,13 @@
}
objectpath = get_service_ref(ns, &status);
- if (status.rc != CMPI_RC_OK || objectpath == NULL)
- {
+ if (status.rc != CMPI_RC_OK || objectpath == NULL) {
DEBUGOUT("GetInstance(): get_service_ref failed - %s\n",
CMGetCharPtr(status.msg));
return status;
}
- if (!omccmpiAreObjectPathsSame(dependent.value.ref, objectpath, &status))
- {
+ if (!omccmpiAreObjectPathsSame(dependent.value.ref, objectpath,
+ &status)) {
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Instance does not exists");
return status;
@@ -622,16 +596,13 @@
DEBUGOUT("InvokeMethod() called. methodName: %s\n", methodName);
class = CMGetClassName(cop, &status);
- if (strcasecmp(CMGetCharPtr(class), "XEN_VMBuilderService") != 0)
- {
+ 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)
- {
+ if (strcasecmp("CreateVM", methodName) == 0) {
OMC_SETSTATUS(_broker, &status,
CMPI_RC_ERR_NOT_SUPPORTED,
"Not implemented yet");
@@ -639,16 +610,14 @@
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
}
- else if (strcasecmp("RequestStateChange", methodName) == 0)
- {
+ 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)
- {
+ else if (strcasecmp("StartService", methodName) == 0) {
CMLogMessage(_broker, 1, "VMBuilderService provider",
"StartService called, but not supported", NULL);
rv.uint32 = 1; // Not supported
@@ -659,8 +628,7 @@
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
}
- else if (strcasecmp("StopService", methodName) == 0)
- {
+ else if (strcasecmp("StopService", methodName) == 0) {
CMLogMessage(_broker, 1, "VMBuilderService provider",
"StopService called, but not supported", NULL);
OMC_SETSTATUS(_broker, &status,
@@ -670,8 +638,7 @@
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
}
- else
- {
+ else {
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, methodName);
}
DEBUGOUT("Leaving InvokeMethod(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
@@ -737,43 +704,36 @@
DEBUGOUT("doReferences called\n");
- if (strcasecmp(assocClass, "XEN_VMBuilderHostedService") == 0)
- {
+ if (strcasecmp(assocClass, "XEN_VMBuilderHostedService") == 0) {
char *objsClassName = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
/* Is target an OS object? */
- if(strcasecmp(objsClassName, "OMC_UnitaryComputerSystem") == 0)
- {
- if (role && *role && strcasecmp(role, "Antecedent") != 0)
- {
+ if(strcasecmp(objsClassName, "OMC_UnitaryComputerSystem") == 0) {
+ if (role && *role && strcasecmp(role, "Antecedent") != 0) {
/* Unknown role */
return status;
}
- if (resultRole && *resultRole && strcasecmp(resultRole, "Dependent") != 0)
- {
+ if (resultRole && *resultRole && strcasecmp(resultRole,
+ "Dependent") != 0) {
/* Unknown resultRole */
return status;
}
- if (resultClass && *resultClass)
- {
+ if (resultClass && *resultClass) {
if (!omccmpiClassIsDerivedFrom("XEN_VMBuilderService",
- resultClass, _broker, ns, &status))
- {
+ resultClass, _broker, ns, &status)) {
return status;
}
}
instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
hosted_service_class_keys, properties, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
CMGetCharPtr(status.msg));
return status;
}
csOp = omccmpiCreateCSObjectPath(_broker, ns, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(csOp))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(csOp)) {
DEBUGOUT("doReferences(): omccmpiCreateCSObjectPath failed - %s\n",
CMGetCharPtr(status.msg));
return status;
@@ -782,8 +742,7 @@
CMSetProperty(instance, "Antecedent", (CMPIValue*)&csOp, CMPI_ref);
objectpath = get_service_ref(ns, &status);
- if ((status.rc != CMPI_RC_OK) || objectpath == NULL)
- {
+ if ((status.rc != CMPI_RC_OK) || objectpath == NULL) {
DEBUGOUT("doReferences(): get_service_ref() failed - %s\n",
CMGetCharPtr(status.msg));
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
@@ -793,38 +752,32 @@
CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, CMPI_ref);
omccmpiSimpleAssocResults(ctx, instance, &status);
}
- else if(strcasecmp(objsClassName, "XEN_VMBuilderService") == 0)
- {
- if (role && *role && strcasecmp(role, "Dependent") != 0)
- {
+ else if(strcasecmp(objsClassName, "XEN_VMBuilderService") == 0) {
+ if (role && *role && strcasecmp(role, "Dependent") != 0) {
/* Unknown role */
return status;
}
- if (resultRole && *resultRole && strcasecmp(resultRole, "Antecedent") != 0)
- {
+ if (resultRole && *resultRole && strcasecmp(resultRole,
+ "Antecedent") != 0) {
/* Unknown resultRole */
return status;
}
- if (resultClass && *resultClass)
- {
+ if (resultClass && *resultClass) {
if (!omccmpiClassIsDerivedFrom("OMC_UnitaryComputerSystem",
- resultClass, _broker, ns, &status))
- {
+ resultClass, _broker, ns, &status)) {
return status;
}
}
instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
hosted_service_class_keys, properties, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
CMGetCharPtr(status.msg));
return status;
}
csOp = omccmpiCreateCSObjectPath(_broker, ns, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(csOp))
- {
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(csOp)) {
DEBUGOUT("doReferences(): omccmpiCreateCSObjectPath failed - %s\n",
CMGetCharPtr(status.msg));
return status;
@@ -832,8 +785,7 @@
CMSetProperty(instance, "Antecedent", (CMPIValue*)&csOp, CMPI_ref);
objectpath = get_service_ref(ns, &status);
- if ((status.rc != CMPI_RC_OK) || objectpath == NULL)
- {
+ if ((status.rc != CMPI_RC_OK) || objectpath == NULL) {
DEBUGOUT("doReferences(): get_service_ref() failed - %s\n",
CMGetCharPtr(status.msg));
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
@@ -885,7 +837,7 @@
_broker, context, results, cop, assocClass,
resultClass, role, resultRole, properties);
- DEBUGOUT("Leaving Associatiors(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving Associatiors(): %s", (status.rc == CMPI_RC_OK)?"succeeded":"failed");
return status;
}
@@ -920,7 +872,7 @@
context, results, cop, assocClass, resultClass, role,
resultRole);
- DEBUGOUT("Leaving AssociatiorNames(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving AssociatiorNames(): %s", (status.rc == CMPI_RC_OK)?"succeeded":"failed");
return status;
}
@@ -950,7 +902,7 @@
status = omccmpiSimpleReferences( doReferences, self, _broker, context,
results, cop, resultClass, role, properties);
- DEBUGOUT("Leaving References(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving References(): %s", (status.rc == CMPI_RC_OK)?"succeeded":"failed");
return status;
}
@@ -980,7 +932,7 @@
status = omccmpiSimpleReferenceNames( doReferences, self, _broker,
context, results, cop, resultClass, role);
- DEBUGOUT("Leaving ReferenceNames(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving ReferenceNames(): %s", (status.rc == CMPI_RC_OK)?"succeeded":"failed");
return status;
}
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 2008-04-30 17:11:01 UTC (rev 595)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 2008-05-05 15:09:41 UTC (rev 596)
@@ -246,7 +246,7 @@
* Create a connection context to the database
*/
int
-db_create_connection(VMBDBCtx* ctx, const char* query, char* err_msg,
+db_get_select_results(VMBDBCtx* ctx, const char* query, char* err_msg,
size_t err_msg_len)
{
VMBDBCtx_t *pctx;
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-05 15:09:41 UTC (rev 596)
@@ -0,0 +1,411 @@
+#include "vmbuilder-db.h"
+#include <sqlite3.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+#include <omc/string.h>
+#include <errno.h>
+#include <ctype.h>
+
+/*
+ * _create_sql is the schema of the database.
+ * When the database is opened for the very first
+ * time, this sql will be used to set up the schema.
+ */
+const char* _create_sql =
+"CREATE TABLE CreationData("
+ "InstanceID TEXT NOT NULL COLLATE NOCASE,"
+ //-- 2: None
+ //-- 3: Restart
+ //-- 4: Revert to snapshot
+ "AutoMaticRecoveryAction INTEGER,"
+ //-- 2: Turn off
+ //-- 3: Save state
+ //-- 4: Shutdown
+ "AutoMaticShutdownAction INTEGER,"
+ //-- 2: None
+ //-- 3: Restart if previously active
+ //-- 4: Always start up
+ "AutoMaticStartupAction INTEGER,"
+ "AutoMaticStartupActionDelay INTEGER,"
+ "AutoMaticStartupActionSequenceNumber INTEGER,"
+ "CPUArchitecture TEXT,"
+ "Caption TEXT,"
+ //-- 0: Not changable (persistent)
+ //-- 1: Changable (transient)
+ //-- 2: Changable (persistent)
+ //-- 3: Not changable (transient)
+ "ChangableType INTEGER,"
+ "ConfigurationDataRoot TEXT,"
+ "ConfigurationFile TEXT,"
+ "ConfigurationID TEXT,"
+ "ConfigurationName TEXT,"
+ "CreationTime INTEGER,"
+ "Description TEXT,"
+ //-- String Array
+ "Disks TEXT,"
+ "ElementName TEXT,"
+ //-- String Array
+ "ExtraConfigInfo TEXT,"
+ "ExtraInstallArgs TEXT,"
+ //-- 0: Unknown
+ //-- 1: Cirrus
+ //-- 2: None
+ //-- 3: Para
+ //-- 4: Vesa
+ "GraphicsType INTEGER,"
+ //-- 0: Unknown
+ //-- 1: SDL
+ //-- 2: VNC
+ "GraphicsViewerType INTEGER,"
+ "LogDataRoot TEXT,"
+ "MaxMemory INTEGER,"
+ "Memory INTEGER,"
+ //-- String Array
+ "Nics TEXT,"
+ //-- String Array
+ "Notes TEXT,"
+ "NumVCPUs INTEGER,"
+ //-- See MOF
+ "OSType INTEGER,"
+ "RecoveryFile TEXT,"
+ "ResponseFile TEXT,"
+ "SnapshotDataRoot TEXT,"
+ "SourceURL TEXT,"
+ "SuspendDataRoot TEXT,"
+ "SwapFileDataRoot TEXT,"
+ "UUID TEXT,"
+ "VNCPort INTEGER,"
+ //-- 0: Unknown
+ //-- 1: Para
+ //-- 2: Full
+ "VirtType INTEGER,"
+ "VirtualSystemIdentifier TEXT,"
+ "VirtualSystemType TEXT,"
+ "PRIMARY KEY(InstanceID COLLATE NOCASE));"
+"CREATE TABLE Job("
+ "JobName TEXT NOT NULL,"
+ "CreationDataInstanceID TEXT NOT NULL COLLATE NOCASE,"
+ "PRIMARY KEY(JobName, CreationDataInstanceID COLLATE NOCASE));";
+
+typedef struct
+{
+ sqlite3 *db;
+ sqlite3_stmt *stmt;
+ const char* tail;
+ int col_count;
+ char** row_data;
+ int lastcc;
+} VMBDBCtx_t;
+
+/*
+ * _db_busy_handler is registered with sqlite when
+ * the database is open. It is called when sqlite
+ * encounters a locked condition on the database.
+ */
+static int
+_db_busy_handler(void* cbdata, int call_count)
+{
+ // Logging?
+ if (call_count > 10) {
+ // Been waiting for the lock condition for to long.
+ // return failure, so the sqlite call will fail.
+ return 0;
+ }
+ // Sleep 1 second and return 1 so sqlite will try the
+ // operation again.
+ sleep(1); // unistd sleep(seconds)
+ return 1;
+}
+
+/*
+ * @return 1 if string is nothing but space
+ */
+static int
+_str_is_empty(const char* str)
+{
+ if (str) {
+ while (*str) {
+ if (!isspace(*str))
+ return 0;
+ str++;
+ }
+ }
+ return 1;
+}
+
+/*
+ * @return 1 if the given path is a directory, otherwise 0
+ */
+static int
+_is_dir(const char* path)
+{
+ struct stat st;
+ if (stat(path, &st) == 0
+ && S_ISDIR(st.st_mode)) {
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Create a directory. If necessary this method will create any non-existent
+ * parent directories until the full path is created.
+ * Assumption: path argument is an absolute path
+ */
+static int
+_make_dirs(const char* path)
+{
+ char cur_path[PATH_MAX+1];
+ char** toks;
+ size_t number_of_toks, i;
+
+ cur_path[0] = '\0';
+ toks = omcStrTokenize(path, "/", &number_of_toks);
+ if (!toks) {
+ // Invalid path?
+ return -1;
+ }
+
+ for(i = 0; toks[i]; i++) {
+ omcStrAppend(cur_path, "/", sizeof(cur_path));
+ omcStrAppend(cur_path, toks[i], sizeof(cur_path));
+ if (!_is_dir(cur_path)) {
+ if (mkdir(cur_path, 0755) != 0) {
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * _get_db_connection will do the following:
+ * - Check for the existence of the database. If it does not exist, it will
+ * create it with the appropriate schema.
+ * - Return a connection (sqlite3*) to the database in the db arg.
+ * - If an error occurs, the err_msg arg will contain an error message
+ * describing the reason for the error.
+ */
+static int
+_get_db_connection(sqlite3** db, char* err_msg, size_t err_msg_len)
+{
+ char *zErr = 0;
+
+ if (!_is_dir(VMB_DB_DIR)) {
+ if (_make_dirs(VMB_DB_DIR) != 0) {
+ omcStrNCpy(err_msg, "Failed to create directory "VMB_DB_DIR,
+ err_msg_len);
+ return -1;
+ }
+ }
+ // If database doesn't exist
+ if (access(VMB_DB_NAME, F_OK) != 0) {
+ // Database does NOT exist
+
+ // Create Database
+ if (sqlite3_open(VMB_DB_NAME, db)) {
+ snprintf(err_msg, err_msg_len,
+ "Failed to open database "VMB_DB_NAME": %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close(*db);
+ return -1;
+ }
+ // Extend schema
+ if (sqlite3_exec(*db, _create_sql, NULL, NULL, &zErr) != SQLITE_OK) {
+ if (zErr != NULL) {
+ snprintf(err_msg, err_msg_len,
+ "Failed executing sql statement: %s", zErr);
+ sqlite3_free(zErr);
+ }
+ else {
+ omcStrNCpy(err_msg, "Failed executing sql statement", err_msg_len);
+ }
+ sqlite3_close(*db);
+ return -1;
+ }
+ }
+ else { // Database does exist - Just open
+ if (sqlite3_open(VMB_DB_NAME, db)) {
+ snprintf(err_msg, err_msg_len,
+ "Failed to open database "VMB_DB_NAME": %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close(*db);
+ return -1;
+ }
+ }
+ sqlite3_busy_handler(*db, _db_busy_handler, NULL);
+ return 0;
+}
+
+/*
+ * Create a connection context to the database
+ */
+int
+db_get_select_results(VMBDBCtx* ctx, const char* query, char* err_msg,
+ size_t err_msg_len)
+{
+ VMBDBCtx_t *pctx;
+ if (_str_is_empty(query)) {
+ omcStrNCpy(err_msg, "Invalid parameter: query arg is required",
+ err_msg_len);
+ return -1;
+ }
+
+ pctx = (VMBDBCtx_t*) calloc(1, sizeof(VMBDBCtx_t));
+ if (!pctx) {
+ omcStrNCpy(err_msg, "Memory Allocation Error", err_msg_len);
+ return -1;
+ }
+ if (_get_db_connection(&pctx->db, err_msg, err_msg_len) != 0) {
+ free(pctx);
+ return -1;
+ }
+
+ if (sqlite3_prepare(pctx->db, query, strlen(query), &pctx->stmt,
+ &pctx->tail) != SQLITE_OK) {
+ snprintf(err_msg, err_msg_len, "Failed preparing DB Query: %s",
+ sqlite3_errmsg(pctx->db));
+ sqlite3_finalize(pctx->stmt);
+ sqlite3_close(pctx->db);
+ free(pctx);
+ return -1;
+ }
+
+ pctx->col_count = sqlite3_column_count(pctx->stmt);
+ pctx->lastcc = sqlite3_step(pctx->stmt);
+ *ctx = (void*)pctx;
+ return 0;
+}
+
+/*
+ * Destroy a connection context to the database
+ */
+void
+db_destroy_connection(VMBDBCtx ctx)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx) {
+ if (pctx->stmt) {
+ sqlite3_finalize(pctx->stmt);
+ }
+ sqlite3_close(pctx->db);
+ free(pctx);
+ }
+}
+
+/*
+ * @return 1 if the current result set has more rows. Otherwise 0.
+ */
+int
+db_has_more_rows(VMBDBCtx ctx)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ return (pctx && pctx->lastcc == SQLITE_ROW) ? 1 : 0;
+}
+
+/*
+ * Position the cursor to the next row in the result set
+ * if there are more rows.
+ * @return 0 for success otherwise -1
+ */
+int db_goto_next_row(VMBDBCtx ctx)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx && pctx->lastcc == SQLITE_ROW) {
+ pctx->lastcc = sqlite3_step(pctx->stmt);
+ return 0;
+ }
+ return -1;
+}
+
+/*
+ * @return The number of columns per row for the result set,
+ * or -1 on error.
+ */
+int
+db_get_column_count(VMBDBCtx ctx)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ return pctx ? pctx->col_count : -1;
+}
+
+/*
+ * @return The data for a given column for the current result set,
+ * or NULL on error.
+ */
+const unsigned char*
+db_get_column_data(VMBDBCtx ctx, size_t column_index)
+{
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx && pctx->col_count && column_index < pctx->col_count) {
+ return sqlite3_column_text(pctx->stmt, (int)column_index);
+ }
+ return NULL;
+}
+
+char*
+db_create_formatted_sql(const char* format, ...)
+{
+ va_list marker;
+ char* formatted_sql;
+ va_start(marker, format);
+ formatted_sql = sqlite3_vmprintf(format, marker);
+ va_end(marker);
+ return formatted_sql;
+}
+
+void
+db_destroy_formatted_sql(char* formatted_sql)
+{
+ sqlite3_free(formatted_sql);
+}
+
+/*
+ * Execute the specified sql against the database.
+ * If the operation fails -1LL will be returned with
+ * the err_msg param containing and error message describing the failue.
+ * If the operation succeeds, the last insert row id is returned if the
+ * operation caused an insert. If it did not cause an insert 0LL will
+ * be returned.
+ */
+long long
+db_exec(const char* sql, char* err_msg, size_t...
[truncated message content] |
|
From: <jc...@us...> - 2008-05-05 15:11:16
|
Revision: 597
http://omc.svn.sourceforge.net/omc/?rev=597&view=rev
Author: jcarey
Date: 2008-05-05 08:10:58 -0700 (Mon, 05 May 2008)
Log Message:
-----------
some name changes...
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
Added Paths:
-----------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
Removed Paths:
-------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.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-05-05 15:09:41 UTC (rev 596)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-05-05 15:10:58 UTC (rev 597)
@@ -56,7 +56,7 @@
# libomc_xenvmbuilder_common
###
libomc_xenvmbuilder_common_la_SOURCES = \
- vmbuild-db.c \
+ vmbuilder-db.c \
vmbuilder-db.h
libomc_xenvmbuilder_common_la_LDFLAGS = \
Deleted: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 2008-05-05 15:09:41 UTC (rev 596)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 2008-05-05 15:10:58 UTC (rev 597)
@@ -1,411 +0,0 @@
-#include "vmbuilder-db.h"
-#include <sqlite3.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
-#include <string.h>
-#include <omc/string.h>
-#include <errno.h>
-#include <ctype.h>
-
-/*
- * _create_sql is the schema of the database.
- * When the database is opened for the very first
- * time, this sql will be used to set up the schema.
- */
-const char* _create_sql =
-"CREATE TABLE CreationData("
- "InstanceID TEXT NOT NULL COLLATE NOCASE,"
- //-- 2: None
- //-- 3: Restart
- //-- 4: Revert to snapshot
- "AutoMaticRecoveryAction INTEGER,"
- //-- 2: Turn off
- //-- 3: Save state
- //-- 4: Shutdown
- "AutoMaticShutdownAction INTEGER,"
- //-- 2: None
- //-- 3: Restart if previously active
- //-- 4: Always start up
- "AutoMaticStartupAction INTEGER,"
- "AutoMaticStartupActionDelay INTEGER,"
- "AutoMaticStartupActionSequenceNumber INTEGER,"
- "CPUArchitecture TEXT,"
- "Caption TEXT,"
- //-- 0: Not changable (persistent)
- //-- 1: Changable (transient)
- //-- 2: Changable (persistent)
- //-- 3: Not changable (transient)
- "ChangableType INTEGER,"
- "ConfigurationDataRoot TEXT,"
- "ConfigurationFile TEXT,"
- "ConfigurationID TEXT,"
- "ConfigurationName TEXT,"
- "CreationTime INTEGER,"
- "Description TEXT,"
- //-- String Array
- "Disks TEXT,"
- "ElementName TEXT,"
- //-- String Array
- "ExtraConfigInfo TEXT,"
- "ExtraInstallArgs TEXT,"
- //-- 0: Unknown
- //-- 1: Cirrus
- //-- 2: None
- //-- 3: Para
- //-- 4: Vesa
- "GraphicsType INTEGER,"
- //-- 0: Unknown
- //-- 1: SDL
- //-- 2: VNC
- "GraphicsViewerType INTEGER,"
- "LogDataRoot TEXT,"
- "MaxMemory INTEGER,"
- "Memory INTEGER,"
- //-- String Array
- "Nics TEXT,"
- //-- String Array
- "Notes TEXT,"
- "NumVCPUs INTEGER,"
- //-- See MOF
- "OSType INTEGER,"
- "RecoveryFile TEXT,"
- "ResponseFile TEXT,"
- "SnapshotDataRoot TEXT,"
- "SourceURL TEXT,"
- "SuspendDataRoot TEXT,"
- "SwapFileDataRoot TEXT,"
- "UUID TEXT,"
- "VNCPort INTEGER,"
- //-- 0: Unknown
- //-- 1: Para
- //-- 2: Full
- "VirtType INTEGER,"
- "VirtualSystemIdentifier TEXT,"
- "VirtualSystemType TEXT,"
- "PRIMARY KEY(InstanceID COLLATE NOCASE));"
-"CREATE TABLE Job("
- "JobName TEXT NOT NULL,"
- "CreationDataInstanceID TEXT NOT NULL COLLATE NOCASE,"
- "PRIMARY KEY(JobName, CreationDataInstanceID COLLATE NOCASE));";
-
-typedef struct
-{
- sqlite3 *db;
- sqlite3_stmt *stmt;
- const char* tail;
- int col_count;
- char** row_data;
- int lastcc;
-} VMBDBCtx_t;
-
-/*
- * _db_busy_handler is registered with sqlite when
- * the database is open. It is called when sqlite
- * encounters a locked condition on the database.
- */
-static int
-_db_busy_handler(void* cbdata, int call_count)
-{
- // Logging?
- if (call_count > 10) {
- // Been waiting for the lock condition for to long.
- // return failure, so the sqlite call will fail.
- return 0;
- }
- // Sleep 1 second and return 1 so sqlite will try the
- // operation again.
- sleep(1); // unistd sleep(seconds)
- return 1;
-}
-
-/*
- * @return 1 if string is nothing but space
- */
-static int
-_str_is_empty(const char* str)
-{
- if (str) {
- while (*str) {
- if (!isspace(*str))
- return 0;
- str++;
- }
- }
- return 1;
-}
-
-/*
- * @return 1 if the given path is a directory, otherwise 0
- */
-static int
-_is_dir(const char* path)
-{
- struct stat st;
- if (stat(path, &st) == 0
- && S_ISDIR(st.st_mode)) {
- return 1;
- }
- return 0;
-}
-
-/*
- * Create a directory. If necessary this method will create any non-existent
- * parent directories until the full path is created.
- * Assumption: path argument is an absolute path
- */
-static int
-_make_dirs(const char* path)
-{
- char cur_path[PATH_MAX+1];
- char** toks;
- size_t number_of_toks, i;
-
- cur_path[0] = '\0';
- toks = omcStrTokenize(path, "/", &number_of_toks);
- if (!toks) {
- // Invalid path?
- return -1;
- }
-
- for(i = 0; toks[i]; i++) {
- omcStrAppend(cur_path, "/", sizeof(cur_path));
- omcStrAppend(cur_path, toks[i], sizeof(cur_path));
- if (!_is_dir(cur_path)) {
- if (mkdir(cur_path, 0755) != 0) {
- return -1;
- }
- }
- }
- return 0;
-}
-
-/*
- * _get_db_connection will do the following:
- * - Check for the existence of the database. If it does not exist, it will
- * create it with the appropriate schema.
- * - Return a connection (sqlite3*) to the database in the db arg.
- * - If an error occurs, the err_msg arg will contain an error message
- * describing the reason for the error.
- */
-static int
-_get_db_connection(sqlite3** db, char* err_msg, size_t err_msg_len)
-{
- char *zErr = 0;
-
- if (!_is_dir(VMB_DB_DIR)) {
- if (_make_dirs(VMB_DB_DIR) != 0) {
- omcStrNCpy(err_msg, "Failed to create directory "VMB_DB_DIR,
- err_msg_len);
- return -1;
- }
- }
- // If database doesn't exist
- if (access(VMB_DB_NAME, F_OK) != 0) {
- // Database does NOT exist
-
- // Create Database
- if (sqlite3_open(VMB_DB_NAME, db)) {
- snprintf(err_msg, err_msg_len,
- "Failed to open database "VMB_DB_NAME": %s",
- sqlite3_errmsg(*db));
- sqlite3_close(*db);
- return -1;
- }
- // Extend schema
- if (sqlite3_exec(*db, _create_sql, NULL, NULL, &zErr) != SQLITE_OK) {
- if (zErr != NULL) {
- snprintf(err_msg, err_msg_len,
- "Failed executing sql statement: %s", zErr);
- sqlite3_free(zErr);
- }
- else {
- omcStrNCpy(err_msg, "Failed executing sql statement", err_msg_len);
- }
- sqlite3_close(*db);
- return -1;
- }
- }
- else { // Database does exist - Just open
- if (sqlite3_open(VMB_DB_NAME, db)) {
- snprintf(err_msg, err_msg_len,
- "Failed to open database "VMB_DB_NAME": %s",
- sqlite3_errmsg(*db));
- sqlite3_close(*db);
- return -1;
- }
- }
- sqlite3_busy_handler(*db, _db_busy_handler, NULL);
- return 0;
-}
-
-/*
- * Create a connection context to the database
- */
-int
-db_get_select_results(VMBDBCtx* ctx, const char* query, char* err_msg,
- size_t err_msg_len)
-{
- VMBDBCtx_t *pctx;
- if (_str_is_empty(query)) {
- omcStrNCpy(err_msg, "Invalid parameter: query arg is required",
- err_msg_len);
- return -1;
- }
-
- pctx = (VMBDBCtx_t*) calloc(1, sizeof(VMBDBCtx_t));
- if (!pctx) {
- omcStrNCpy(err_msg, "Memory Allocation Error", err_msg_len);
- return -1;
- }
- if (_get_db_connection(&pctx->db, err_msg, err_msg_len) != 0) {
- free(pctx);
- return -1;
- }
-
- if (sqlite3_prepare(pctx->db, query, strlen(query), &pctx->stmt,
- &pctx->tail) != SQLITE_OK) {
- snprintf(err_msg, err_msg_len, "Failed preparing DB Query: %s",
- sqlite3_errmsg(pctx->db));
- sqlite3_finalize(pctx->stmt);
- sqlite3_close(pctx->db);
- free(pctx);
- return -1;
- }
-
- pctx->col_count = sqlite3_column_count(pctx->stmt);
- pctx->lastcc = sqlite3_step(pctx->stmt);
- *ctx = (void*)pctx;
- return 0;
-}
-
-/*
- * Destroy a connection context to the database
- */
-void
-db_destroy_connection(VMBDBCtx ctx)
-{
- VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
- if (pctx) {
- if (pctx->stmt) {
- sqlite3_finalize(pctx->stmt);
- }
- sqlite3_close(pctx->db);
- free(pctx);
- }
-}
-
-/*
- * @return 1 if the current result set has more rows. Otherwise 0.
- */
-int
-db_has_more_rows(VMBDBCtx ctx)
-{
- VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
- return (pctx && pctx->lastcc == SQLITE_ROW) ? 1 : 0;
-}
-
-/*
- * Position the cursor to the next row in the result set
- * if there are more rows.
- * @return 0 for success otherwise -1
- */
-int db_goto_next_row(VMBDBCtx ctx)
-{
- VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
- if (pctx && pctx->lastcc == SQLITE_ROW) {
- pctx->lastcc = sqlite3_step(pctx->stmt);
- return 0;
- }
- return -1;
-}
-
-/*
- * @return The number of columns per row for the result set,
- * or -1 on error.
- */
-int
-db_get_column_count(VMBDBCtx ctx)
-{
- VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
- return pctx ? pctx->col_count : -1;
-}
-
-/*
- * @return The data for a given column for the current result set,
- * or NULL on error.
- */
-const unsigned char*
-db_get_column_data(VMBDBCtx ctx, size_t column_index)
-{
- VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
- if (pctx && pctx->col_count && column_index < pctx->col_count) {
- return sqlite3_column_text(pctx->stmt, (int)column_index);
- }
- return NULL;
-}
-
-char*
-db_create_formatted_sql(const char* format, ...)
-{
- va_list marker;
- char* formatted_sql;
- va_start(marker, format);
- formatted_sql = sqlite3_vmprintf(format, marker);
- va_end(marker);
- return formatted_sql;
-}
-
-void
-db_destroy_formatted_sql(char* formatted_sql)
-{
- sqlite3_free(formatted_sql);
-}
-
-/*
- * Execute the specified sql against the database.
- * If the operation fails -1LL will be returned with
- * the err_msg param containing and error message describing the failue.
- * If the operation succeeds, the last insert row id is returned if the
- * operation caused an insert. If it did not cause an insert 0LL will
- * be returned.
- */
-long long
-db_exec(const char* sql, char* err_msg, size_t err_msg_len)
-{
- int cc;
- sqlite3 *db;
- char* zErr = NULL;
- long long insert_row_id = -1LL;
-
- if (_get_db_connection(&db, err_msg, err_msg_len) != 0) {
- return -1LL;
- }
-
- cc = sqlite3_exec(db, sql, NULL, NULL, &zErr);
- if (cc != SQLITE_OK) {
- if (zErr) {
- snprintf(err_msg, err_msg_len,
- "Failed executing sql statement: %s", zErr);
- sqlite3_free(zErr);
- }
- else {
- omcStrNCpy(err_msg, "Failed executing sql statement", err_msg_len);
- }
- }
- else {
- insert_row_id = sqlite3_last_insert_rowid(db);
- }
-
- sqlite3_close(db);
- return insert_row_id;
-}
-
-
-
-
-
-
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-05 15:10:58 UTC (rev 597)
@@ -0,0 +1,509 @@
+/*******************************************************************************
+* 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 "vmbuilder-db.h"
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.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* creation_data_keys[] =
+{
+ "InstanceID",
+ NULL
+};
+
+/* If built for debug, enable tracing */
+#ifdef XEN_VMBUILDER_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;
+
+/******************************************************************************
+ 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};
+ char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ char *className;
+ int cc;
+
+ className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+
+ DEBUGOUT("EnumInstanceNames() called class:%s\n", className);
+ if (strcasecmp(className, "XEN_VMBuilderVirtualSystemCreationData") == 0) {
+ CMPIObjectPath* ref;
+ VMBDBCtx dbctx;
+ char err_msg[256];
+ char* iid;
+
+ cc = db_get_select_results(&dbctx, "select InstanceID from CreationData"
+ err_msg, sizeof(err_msg));
+ if (cc != 0) {
+ DEBUGOUT("EnumInstanceNames(): Failed to connect to database: %s"
+ err_msg);
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
+ return status;
+ }
+ ref = CMNewObjectPath(_broker, ns,
+ "XEN_VMBuilderVirtualSystemCreationData", &status);
+ while (db_has_more_rows(dbctx)) {
+ iid = (char*)db_get_column_data(dbctx, 0);
+ CMAddKey(ref, "InstanceID", (CMPIValue*)iid, CMPI_chars);
+ CMReturnObjectPath(results, ref);
+ db_goto_next_row(dbctx);
+ }
+ db_destroy_connection(dbctx);
+ 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 *className;
+
+ DEBUGOUT("EnumInstances() called\n");
+
+ className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_VMBuilderVirtualSystemCreationData") == 0) {
+ cc = db_get_select_results(&dbctx, "select InstanceID from CreationData"
+ err_msg, sizeof(err_msg));
+ if (cc != 0) {
+ DEBUGOUT("EnumInstanceNames(): Failed to connect to database: %s"
+ err_msg);
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
+ return status;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ char** names = NULL;
+ names = get_job_names();
+ if (names) {
+ const char* p;
+ VMInstallInfo info;
+ int i;
+ for(i = 0; names[i]; i++) {
+ if(get_job_info(names[i], &info) == 0) {
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderVirtualSystemCreationData",
+ creation_data_keys, properties, &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullObject(instance)) {
+ DEBUGOUT("EnumInstances(): CMNewInstance() failed - %s\n",
+ CMGetCharPtr(status.msg));
+ return status;
+ }
+ CMSetProperty(instance, "Name", (CMPIValue*)names[i],
+ CMPI_chars);
+ CMSetProperty(instance, "VMName", (CMPIValue*)info.name,
+ CMPI_chars);
+ CMSetProperty(instance, "VncURL", (CMPIValue*)info.vnc,
+ CMPI_chars);
+ CMSetProperty(instance, "VM_UUID", (CMPIValue*)info.uuid,
+ CMPI_chars);
+ CMSetProperty(instance, "ExitCode",
+ (CMPIValue*)&info.exit_code, CMPI_uint32);
+ CMSetProperty(instance, "InstallLogFileLocation",
+ (CMPIValue*)info.log, CMPI_chars);
+ p = (info.state > 8) ? "UNKNOWN" : job_states[info.state];
+ CMSetProperty(instance, "JobStatus", (CMPIValue*)p,
+ CMPI_chars);
+ CMSetProperty(instance, "StatusFileName", (CMPIValue*)info.inotify,
+ CMPI_chars);
+ CMReturnInstance(results, instance);
+ }
+ }
+ free(names);
+ }
+ 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;
+ //CMPIObjectPath *objectpath;
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ //char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ const char *className;
+
+ DEBUGOUT("GetInstance() called\n");
+
+ className = CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_VMBuilderVirtualSystemCreationData") == 0)
+ {
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ "Instance does not exists");
+ }
+ 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_VMBuilderVirtualSystemCreationData") != 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("Cancel", 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("Detach", 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("KillJob", 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
+ {
+ 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( , omc_xencreationdata, _broker, Init(&mi));
+CMMethodMIStub( , omc_xencreationdata, _broker, MethodInit(&mi));
+
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jc...@us...> - 2008-05-07 20:22:55
|
Revision: 599
http://omc.svn.sourceforge.net/omc/?rev=599&view=rev
Author: jcarey
Date: 2008-05-07 13:22:58 -0700 (Wed, 07 May 2008)
Log Message:
-----------
Dev check pnt
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
Added Paths:
-----------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-05-07 20:14:16 UTC (rev 598)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-05-07 20:22:58 UTC (rev 599)
@@ -56,6 +56,7 @@
# libomc_xenvmbuilder_common
###
libomc_xenvmbuilder_common_la_SOURCES = \
+ vmbuilder-util.c \
vmbuilder-db.c \
vmbuilder-db.h
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-07 20:14:16 UTC (rev 598)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-07 20:22:58 UTC (rev 599)
@@ -246,7 +246,7 @@
* Create a connection context to the database
*/
int
-db_get_select_results(VMBDBCtx* ctx, const char* query, char* err_msg,
+db_create_select_results(VMBDBCtx* ctx, const char* query, char* err_msg,
size_t err_msg_len)
{
VMBDBCtx_t *pctx;
@@ -286,7 +286,7 @@
* Destroy a connection context to the database
*/
void
-db_destroy_connection(VMBDBCtx ctx)
+db_destroy_select_results(VMBDBCtx ctx)
{
VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
if (pctx) {
@@ -302,7 +302,7 @@
* @return 1 if the current result set has more rows. Otherwise 0.
*/
int
-db_has_more_rows(VMBDBCtx ctx)
+db_results_have_more_rows(VMBDBCtx ctx)
{
VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
return (pctx && pctx->lastcc == SQLITE_ROW) ? 1 : 0;
@@ -313,7 +313,7 @@
* if there are more rows.
* @return 0 for success otherwise -1
*/
-int db_goto_next_row(VMBDBCtx ctx)
+int db_results_next_row(VMBDBCtx ctx)
{
VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
if (pctx && pctx->lastcc == SQLITE_ROW) {
@@ -328,7 +328,7 @@
* or -1 on error.
*/
int
-db_get_column_count(VMBDBCtx ctx)
+db_results_column_count(VMBDBCtx ctx)
{
VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
return pctx ? pctx->col_count : -1;
@@ -339,15 +339,86 @@
* or NULL on error.
*/
const unsigned char*
-db_get_column_data(VMBDBCtx ctx, size_t column_index)
+db_get_results_column_text(VMBDBCtx ctx, size_t column_index, int* perr)
{
+ if (perr)
+ *perr = 0;
VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
if (pctx && pctx->col_count && column_index < pctx->col_count) {
return sqlite3_column_text(pctx->stmt, (int)column_index);
}
+ if (perr)
+ *perr = -1;
return NULL;
}
+/*
+ * @return The data for a given column for the current result set,
+ * or -1.0 on error
+ */
+double db_get_results_column_double(VMBDBCtx ctx, size_t column_index, int* perr)
+{
+ if (perr)
+ *perr = 0;
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx && pctx->col_count && column_index < pctx->col_count) {
+ return sqlite3_column_double(pctx->stmt, (int)column_index);
+ }
+ if (perr)
+ *perr = -1;
+ return -1.0;
+}
+
+/*
+ * @return The data for a given column for the current result set,
+ * or -1 on error.
+ */
+int
+db_get_results_column_int(VMBDBCtx ctx, size_t column_index, int* perr)
+{
+ if (perr)
+ *perr = 0;
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx && pctx->col_count && column_index < pctx->col_count) {
+ return sqlite3_column_int(pctx->stmt, (int)column_index);
+ }
+ if (perr)
+ *perr = -1;
+ return -1;
+}
+
+/*
+ * @return The data for a given column for the current result set,
+ * or -1LL on error.
+ */
+long long
+db_get_results_column_int64(VMBDBCtx ctx, size_t column_index, int* perr)
+{
+ if (perr)
+ *perr = 0;
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx && pctx->col_count && column_index < pctx->col_count) {
+ return sqlite3_column_int64(pctx->stmt, (int)column_index);
+ }
+ if (perr)
+ *perr = -1;
+ return -1LL;
+}
+
+int db_column_is_null(VMBDBCtx ctx, size_t column_index, int* perr)
+{
+ if (perr)
+ *perr = 0;
+ VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
+ if (pctx && pctx->col_count && column_index < pctx->col_count) {
+ int cc = sqlit3_column_type(pctx->stmt, (int)column_index);
+ return (cc == SQLITE_NULL) ? 1 : 0;
+ }
+ if (perr)
+ *perr = -1;
+ return -1;
+}
+
char*
db_create_formatted_sql(const char* format, ...)
{
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-05-07 20:14:16 UTC (rev 598)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-05-07 20:22:58 UTC (rev 599)
@@ -9,12 +9,17 @@
typedef void* VMBDBCtx;
-int db_get_select_results(VMBDBCtx* ctx, const char* query, char* err_msg, size_t err_msg_len);
-void db_destroy_connection(VMBDBCtx ctx);
-int db_has_more_rows(VMBDBCtx ctx);
-int db_goto_next_row(VMBDBCtx ctx);
-int db_get_column_count(VMBDBCtx ctx);
-const unsigned char* db_get_column_data(VMBDBCtx ctx, size_t column_index);
+int db_create_select_results(VMBDBCtx* ctx, const char* query, char* err_msg, size_t err_msg_len);
+void db_destroy_select_results(VMBDBCtx ctx);
+int db_results_have_more_rows(VMBDBCtx ctx);
+int db_results_next_row(VMBDBCtx ctx);
+int db_results_column_count(VMBDBCtx ctx);
+const unsigned char* db_get_results_column_text(VMBDBCtx ctx, size_t column_index, int* perr);
+int db_get_results_column_int(VMBDBCtx ctx, size_t column_index, int* perr);
+double db_get_results_column_double(VMBDBCtx ctx, size_t column_index, int* perr);
+long long db_get_results_column_int64(VMBDBCtx ctx, size_t column_index, int* perr);
+int db_column_is_null(VMBDBCtx ctx, size_t column_index, int* perr);
+
long long db_exec(const char* sql, char* err_msg, size_t err_msg_len);
char* db_create_formatted_sql(const char* format, ...);
void db_destroy_formatted_sql(char* formatted_sql);
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c 2008-05-07 20:22:58 UTC (rev 599)
@@ -0,0 +1,81 @@
+#include "vmbuilder-util.h"
+#include <cmpift.h>
+#include <cmpimacs.h>
+#include <omc/string.h>
+
+CMPIArray*
+str2UInt16Array(const CMPIBroker* broker, const char* str)
+{
+ unsigned short wku16;
+ CMPIArray *pra = NULL;
+ size_t tokcnt;
+ char* endptr;
+ char** toks = omcStrTokenize(str, ";", &tokcnt);
+
+ if (toks) {
+ int i;
+ pra = CMNewArray(broker, tokcnt, CMPI_uint16, NULL);
+ for(i = 0; toks[i]; i++) {
+ wku16 = (unsigned short) strtol(toks[i], &endptr, 10);
+ if (endptr == toks[i] || *endptr) {
+ // Non-numeric value. What to do?
+ continue;
+ }
+ CMSetArrayElementAt(pra, i, (CMPIValue*)&wku16, CMPI_uint16);
+ }
+ free(toks);
+ }
+ return pra;
+}
+
+CMPIArray*
+str2StringArray(const CMPIBroker* broker, const char* str)
+{
+ CMPIArray *pra = NULL;
+ char smbuf[8];
+ int strcnt, slen, i;
+ omcStrArray* pstra;
+
+ if (strlen(str) < 9) {
+ // Just return a string array with 1 element
+ CMPIString *pstr = CMNewString(broker, str, NULL);
+ pra = CMNewArray(broker, 1, CMPI_string, NULL);
+ CMSetArrayElementAt(pra, 1, (CMPIValue*)&pstr, CMPI_string);
+ }
+ else {
+ omcStrBuf* pbuf = omcStrBuf_create();
+ if (!pbuf) {
+ return NULL;
+ }
+ if(!(pstra = omcStrArray_create())) {
+ omcStrBuf_destroy(pbuf);
+ return NULL;
+ }
+ strncpy(smbuf, str, 4);
+ smbuf[4] = 0;
+ strcnt = atoi(smbuf);
+ for (i = 0; i < strcnt; i++) {
+ str += 4;
+ strncpy(smbuf, str, 4);
+ smbuf[4] = 0;
+ slen = atoi(smbuf);
+ omcStrBuf_set(pbuf, str+4, slen);
+ omcStrArray_append(pstra, pbuf->bfr);
+ str += slen;
+ }
+ if (omcStrArray_size(pstra) > 0) {
+ int sz = omcStrArray_size(pstra);
+ pra = CMNewArray(broker, sz, CMPI_string, NULL);
+ for (i = 0; i < sz; i++) {
+ CMPIString *pstr = CMNewString(broker,
+ omcStrArray_get_element(pstra, i), NULL);
+ CMSetArrayElementAt(pra, i, (CMPIValue*)&pstr, CMPI_string);
+ }
+ }
+ omcStrBuf_destroy(pbuf);
+ omcStrArray_destroy(pstra);
+ }
+ return pra;
+}
+
+
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h 2008-05-07 20:22:58 UTC (rev 599)
@@ -0,0 +1,9 @@
+#ifndef VMBUILDER_UTIL_H_GUARD
+#define VMBUILDER_UTIL_H_GUARD
+
+#include <cmpidt.h>
+
+CMPIArray* str2UInt16Array(const CMPIBroker* broker, const char* str);
+CMPIArray* str2StringArray(const CMPIBroker* broker, const char* str);
+
+#endif /* VMBUILDER_UTIL_H_GUARD */
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-07 20:14:16 UTC (rev 598)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-07 20:22:58 UTC (rev 599)
@@ -31,6 +31,7 @@
******************************************************************************/
#include "config.h"
#include "vmbuilder-db.h"
+#include "vmbuilder-util.h"
#include <unistd.h>
#include <stdio.h>
@@ -67,6 +68,135 @@
#define DEBUGOUT(fmt, args...)
#endif
+const char* all_cd_fields_query = "SELECT "
+ "InstanceID,"
+ "AutoMaticRecoveryAction,"
+ "AutoMaticShutdownAction,"
+ "AutoMaticStartupAction,"
+ "AutoMaticStartupActionDelay,"
+ "AutoMaticStartupActionSequenceNumber,"
+ "CPUArchitecture,"
+ "Caption,"
+ "ChangableType,"
+ "ConfigurationDataRoot,"
+ "ConfigurationFile,"
+ "ConfigurationID,"
+ "ConfigurationName,"
+ "CreationTime,"
+ "Description,"
+ "Disks,"
+ "ElementName,"
+ "ExtraConfigInfo,"
+ "ExtraInstallArgs,"
+ "GraphicsType,"
+ "GraphicsViewerType,"
+ "LogDataRoot,"
+ "MaxMemory,"
+ "Memory,"
+ "Nics,"
+ "Notes,"
+ "NumVCPUs,"
+ "OSType,"
+ "RecoveryFile,"
+ "ResponseFile,"
+ "SnapshotDataRoot,"
+ "SourceURL,"
+ "SuspendDataRoot,"
+ "SwapFileDataRoot,"
+ "UUID,"
+ "VNCPort,"
+ "VirtType,"
+ "VirtualSystemIdentifier,"
+ "VirtualSystemType "
+ "FROM CreationData;";
+
+enum ALL_CD_FIELDS_NDX {
+ CDF_InstanceID,
+ CDF_AutoMaticRecoveryAction,
+ CDF_AutoMaticShutdownAction,
+ CDF_AutoMaticStartupAction,
+ CDF_AutoMaticStartupActionDelay,
+ CDF_AutoMaticStartupActionSequenceNumber,
+ CDF_CPUArchitecture,
+ CDF_Caption,
+ CDF_ChangableType,
+ CDF_ConfigurationDataRoot,
+ CDF_ConfigurationFile,
+ CDF_ConfigurationID,
+ CDF_ConfigurationName,
+ CDF_CreationTime,
+ CDF_Description,
+ CDF_Disks,
+ CDF_ElementName,
+ CDF_ExtraConfigInfo,
+ CDF_ExtraInstallArgs,
+ CDF_GraphicsType,
+ CDF_GraphicsViewerType,
+ CDF_LogDataRoot,
+ CDF_MaxMemory,
+ CDF_Memory,
+ CDF_Nics,
+ CDF_Notes,
+ CDF_NumVCPUs,
+ CDF_OSType,
+ CDF_RecoveryFile,
+ CDF_ResponseFile,
+ CDF_SnapshotDataRoot,
+ CDF_SourceURL,
+ CDF_SuspendDataRoot,
+ CDF_SwapFileDataRoot,
+ CDF_UUID,
+ CDF_VNCPort,
+ CDF_VirtType,
+ CDF_VirtualSystemIdentifier,
+ CDF_VirtualSystemType
+};
+
+static const char* CreationDataFields[] = {
+ "InstanceID",
+ "AutoMaticRecoveryAction",
+ "AutoMaticShutdownAction",
+ "AutoMaticStartupAction",
+ "AutoMaticStartupActionDelay",
+ "AutoMaticStartupActionSequenceNumber",
+ "CPUArchitecture",
+ "Caption",
+ "ChangableType",
+ "ConfigurationDataRoot",
+ "ConfigurationFile",
+ "ConfigurationID",
+ "ConfigurationName",
+ "CreationTime",
+ "Description",
+ "Disks",
+ "ElementName",
+ "ExtraConfigInfo",
+ "ExtraInstallArgs",
+ "GraphicsType",
+ "GraphicsViewerType",
+ "LogDataRoot",
+ "MaxMemory",
+ "Memory",
+ "Nics",
+ "Notes",
+ "NumVCPUs",
+ "OSType",
+ "RecoveryFile",
+ "ResponseFile",
+ "SnapshotDataRoot",
+ "SourceURL",
+ "SuspendDataRoot",
+ "SwapFileDataRoot",
+ "UUID",
+ "VNCPort",
+ "VirtType",
+ "VirtualSystemIdentifier",
+ "VirtualSystemType",
+ NULL
+};
+
+static int CreationDataFieldCount = (sizeof(CreationDataFields)/sizeof(char*))-1;
+
/*
* Global handle to the CIM broker
* This is initialized by the CIMOM when the provider is loaded
@@ -106,23 +236,23 @@
char err_msg[256];
char* iid;
- cc = db_get_select_results(&dbctx, "select InstanceID from CreationData"
+ cc = db_create_select_results(&dbctx, "select InstanceID from CreationData",
err_msg, sizeof(err_msg));
if (cc != 0) {
- DEBUGOUT("EnumInstanceNames(): Failed to connect to database: %s"
+ DEBUGOUT("EnumInstanceNames(): Failed to connect to database: %s",
err_msg);
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
return status;
}
ref = CMNewObjectPath(_broker, ns,
"XEN_VMBuilderVirtualSystemCreationData", &status);
- while (db_has_more_rows(dbctx)) {
- iid = (char*)db_get_column_data(dbctx, 0);
+ while (db_results_have_more_rows(dbctx)) {
+ iid = (char*)db_get_results_column_text(dbctx, 0, NULL);
CMAddKey(ref, "InstanceID", (CMPIValue*)iid, CMPI_chars);
CMReturnObjectPath(results, ref);
- db_goto_next_row(dbctx);
+ db_results_next_row(dbctx);
}
- db_destroy_connection(dbctx);
+ db_destroy_select_results(dbctx);
CMReturnDone(results);
}
DEBUGOUT("Leaving EnumInstanceNames(): %s\n",
@@ -130,6 +260,151 @@
return status;
}
+/******************************************************************************/
+static void
+set_str_array_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ const unsigned char* txt = db_get_results_column_text(dbctx, col_ndx, NULL);
+ if (txt) {
+ CMPIArray* pra = str2StringArray(_broker, (const char*)txt);
+ if (pra) {
+ CMSetProperty(instance, prop_name, (CMPIValue*)&pra, CMPI_stringA);
+ }
+ }
+}
+
+/******************************************************************************/
+static void
+set_str_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ const unsigned char* txt = db_get_results_column_text(dbctx, col_ndx, NULL);
+ if (txt) {
+ CMSetProperty(instance, prop_name, (CMPIValue*)txt, CMPI_chars);
+ }
+}
+
+/******************************************************************************/
+static void
+set_u16_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ if (!db_column_is_null(dbctx, col_ndx, NULL)) {
+ CMPIUint16 wku16 = (CMPIUint16) db_get_results_column_int(dbctx,
+ col_ndx, NULL);
+ CMSetProperty(instance, prop_name, (CMPIValue*)&wku16, CMPI_uint16);
+ }
+}
+
+/******************************************************************************/
+static void
+set_u8_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ if (!db_column_is_null(dbctx, col_ndx, NULL)) {
+ CMPIUint8 wku8 = (CMPIUint8) db_get_results_column_int(dbctx,
+ col_ndx, NULL);
+ CMSetProperty(instance, prop_name, (CMPIValue*)&wku8, CMPI_uint8);
+ }
+}
+
+/******************************************************************************/
+static void
+set_u32_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ if (!db_column_is_null(dbctx, col_ndx, NULL)) {
+ CMPIUint32 wku32 = (CMPIUint32) db_get_results_column_int(dbctx,
+ col_ndx, NULL);
+ CMSetProperty(instance, prop_name, (CMPIValue*)&wku32, CMPI_uint32);
+ }
+}
+
+/******************************************************************************/
+static void
+set_dt_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name,
+ CMPIBoolean isInterval)
+{
+ if (!db_column_is_null(dbctx, col_ndx, NULL)) {
+ CMPIDateTime* datetime;
+ unsigned long long wku64;
+
+ wku64 = (unsigned long long) db_get_results_column_int64(dbctx,
+ col_ndx, NULL);
+ datetime = CMNewDateTimeFromBinary(_broker, wku64, isInterval, NULL);
+ CMSetProperty(instance, prop_name, (CMPIValue*)&datetime,
+ CMPI_dateTime);
+ }
+}
+
+static void
+_fillInstance(
+ VMBDBCtx dbctx,
+ CMPIInstance* instance)
+{
+ set_str_prop(dbctx, CDF_InstanceID, instance, "InstanceID");
+ set_u16_prop(dbctx, CDF_AutoMaticRecoveryAction, instance, "AutoMaticRecoveryAction");
+ set_u16_prop(dbctx, CDF_AutoMaticShutdownAction, instance, "AutoMaticShutdownAction");
+ set_u16_prop(dbctx, CDF_AutoMaticStartupAction, instance, "AutoMaticStartupAction");
+ set_dt_prop(dbctx, CDF_AutoMaticStartupActionDelay, instance,
+ "AutoMaticStartupActionDelay", 1);
+ set_u16_prop(dbctx, CDF_AutoMaticStartupActionSequenceNumber, instance,
+ "AutoMaticStartupActionSequenceNumber");
+ set_str_prop(dbctx, CDF_CPUArchitecture, instance, "CPUArchitecture");
+ set_str_prop(dbctx, CDF_Caption, instance, "Caption");
+ set_u16_prop(dbctx, CDF_ChangableType, instance, "ChangableType");
+ set_str_prop(dbctx, CDF_ConfigurationDataRoot, instance, "ConfigurationDataRoot");
+ set_str_prop(dbctx, CDF_ConfigurationFile, instance, "ConfigurationFile");
+ set_str_prop(dbctx, CDF_ConfigurationID, instance, "ConfigurationID");
+ set_str_prop(dbctx, CDF_ConfigurationName, instance, "ConfigurationName");
+ set_dt_prop(dbctx, CDF_CreationTime, instance, "CreationTime", 0);
+ set_str_prop(dbctx, CDF_Description, instance, "Description");
+ set_str_array_prop(dbctx, CDF_Disks, instance, "Disks");
+ set_str_prop(dbctx, CDF_ElementName, instance, "ElementName");
+ set_str_array_prop(dbctx, CDF_ExtraConfigInfo, instance, "ExtraConfigInfo");
+ set_str_prop(dbctx, CDF_ExtraInstallArgs, instance, "ExtraInstallArgs");
+ set_u32_prop(dbctx, CDF_GraphicsType, instance, "GraphicsType");
+ set_u32_prop(dbctx, CDF_GraphicsViewerType, instance, "GraphicsViewerType");
+ set_str_prop(dbctx, CDF_LogDataRoot, instance, "LogDataRoot");
+ set_u32_prop(dbctx, CDF_MaxMemory, instance, "MaxMemory");
+ set_u32_prop(dbctx, CDF_Memory, instance, "Memory");
+ set_str_array_prop(dbctx, CDF_Nics, instance, "Nics");
+ set_str_array_prop(dbctx, CDF_Notes, instance, "Notes");
+ set_u8_prop(dbctx, CDF_NumVCPUs, instance, "NumVCPUs");
+ set_u32_prop(dbctx, CDF_OSType, instance, "OSType");
+ set_str_prop(dbctx, CDF_RecoveryFile, instance, "RecoveryFile");
+ set_str_prop(dbctx, CDF_ResponseFile, instance, "ResponseFile");
+ set_str_prop(dbctx, CDF_SnapshotDataRoot, instance, "SnapshotDataRoot");
+ set_str_prop(dbctx, CDF_SourceURL, instance, "SourceURL");
+ set_str_prop(dbctx, CDF_SuspendDataRoot, instance, "SuspendDataRoot");
+ set_str_prop(dbctx, CDF_SwapFileDataRoot, instance, "SwapFileDataRoot");
+ set_str_prop(dbctx, CDF_UUID, instance, "UUID");
+ set_u32_prop(dbctx, CDF_VNCPort, instance, "VNCPort");
+ set_u32_prop(dbctx, CDF_VirtType, instance, "VirtType");
+ set_str_prop(dbctx, CDF_VirtualSystemIdentifier, instance, "VirtualSystemIdentifier");
+ set_str_prop(dbctx, CDF_VirtualSystemType, instance, "VirtualSystemType");
+}
+
/******************************************************************************
EnumInstances()
params: CMPIInstanceMI* self: [in] Handle to this provider
@@ -146,87 +421,39 @@
const CMPIObjectPath* cop,
const char** properties)
{
+ VMBDBCtx dbctx;
CMPIStatus status = {CMPI_RC_OK, NULL};
char * ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
CMPIInstance* instance;
char *className;
+ char err_msg[256];
DEBUGOUT("EnumInstances() called\n");
className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
if (strcasecmp(className, "XEN_VMBuilderVirtualSystemCreationData") == 0) {
- cc = db_get_select_results(&dbctx, "select InstanceID from CreationData"
- err_msg, sizeof(err_msg));
+ int cc = db_create_select_results(&dbctx, all_cd_fields_query, err_msg,
+ sizeof(err_msg));
if (cc != 0) {
- DEBUGOUT("EnumInstanceNames(): Failed to connect to database: %s"
+ DEBUGOUT("EnumInstances(): Failed to connect to database: %s",
err_msg);
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
return status;
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- char** names = NULL;
- names = get_job_names();
- if (names) {
- const char* p;
- VMInstallInfo info;
- int i;
- for(i = 0; names[i]; i++) {
- if(get_job_info(names[i], &info) == 0) {
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderVirtualSystemCreationData",
- creation_data_keys, properties, &status);
- if (status.rc != CMPI_RC_OK || CMIsNullObject(instance)) {
- DEBUGOUT("EnumInstances(): CMNewInstance() failed - %s\n",
- CMGetCharPtr(status.msg));
- return status;
- }
- CMSetProperty(instance, "Name", (CMPIValue*)names[i],
- CMPI_chars);
- CMSetProperty(instance, "VMName", (CMPIValue*)info.name,
- CMPI_chars);
- CMSetProperty(instance, "VncURL", (CMPIValue*)info.vnc,
- CMPI_chars);
- CMSetProperty(instance, "VM_UUID", (CMPIValue*)info.uuid,
- CMPI_chars);
- CMSetProperty(instance, "ExitCode",
- (CMPIValue*)&info.exit_code, CMPI_uint32);
- CMSetProperty(instance, "InstallLogFileLocation",
- (CMPIValue*)info.log, CMPI_chars);
- p = (info.state > 8) ? "UNKNOWN" : job_states[info.state];
- CMSetProperty(instance, "JobStatus", (CMPIValue*)p,
- CMPI_chars);
- CMSetProperty(instance, "StatusFileName", (CMPIValue*)info.inotify,
- CMPI_chars);
- CMReturnInstance(results, instance);
- }
- }
- free(names);
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderVirtualSystemCreationData",
+ creation_data_keys, properties, &status);
+ while (db_results_have_more_rows(dbctx)) {
+ _fillInstance(dbctx, instance);
+ CMReturnInstance(results, instance);
+ db_results_next_row(dbctx);
}
+ db_destroy_select_results(dbctx);
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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jc...@us...> - 2008-05-08 22:20:16
|
Revision: 601
http://omc.svn.sourceforge.net/omc/?rev=601&view=rev
Author: jcarey
Date: 2008-05-08 15:20:17 -0700 (Thu, 08 May 2008)
Log Message:
-----------
Dev check pnt
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-07 21:11:21 UTC (rev 600)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-08 22:20:17 UTC (rev 601)
@@ -128,30 +128,23 @@
if (omcStrStartsWith(lines[i], "vnc ")) {
omcStrNCpy(pinfo->vnc, lines[i]+4, sizeof(pinfo->vnc));
omcStrTrim(pinfo->vnc);
- }
- else if (omcStrStartsWith(lines[i], "uuid ")) {
+ } else if (omcStrStartsWith(lines[i], "uuid ")) {
omcStrNCpy(pinfo->uuid, lines[i]+5, sizeof(pinfo->uuid));
omcStrTrim(pinfo->uuid);
- }
- else if (omcStrStartsWith(lines[i], "name ")) {
+ } else if (omcStrStartsWith(lines[i], "name ")) {
omcStrNCpy(pinfo->name, lines[i]+5, sizeof(pinfo->name));
omcStrTrim(pinfo->name);
- }
- else if (omcStrStartsWith(lines[i], "exit ")) {
+ } else if (omcStrStartsWith(lines[i], "exit ")) {
pinfo->exit_code = atoi(lines[i]+5);
- }
- else if (omcStrStartsWith(lines[i], "id ")) {
+ } else if (omcStrStartsWith(lines[i], "id ")) {
omcStrNCpy(pinfo->id, lines[i]+3, sizeof(pinfo->id));
omcStrTrim(pinfo->id);
- }
- else if (omcStrStartsWith(lines[i], "log ")) {
+ } else if (omcStrStartsWith(lines[i], "log ")) {
omcStrNCpy(pinfo->log, lines[i]+4, sizeof(pinfo->log));
omcStrTrim(pinfo->log);
- }
- else if (omcStrStartsWith(lines[i], "state ")) {
+ } else if (omcStrStartsWith(lines[i], "state ")) {
pinfo->state = atoi(lines[i]+6);
- }
- else if (omcStrStartsWith(lines[i], "inotify ")) {
+ } else if (omcStrStartsWith(lines[i], "inotify ")) {
omcStrNCpy(pinfo->inotify, lines[i]+8, sizeof(pinfo->inotify));
omcStrTrim(pinfo->inotify);
}
@@ -159,8 +152,7 @@
free(lines);
cc = 0;
}
- }
- else {
+ } else {
DEBUGOUT("exec & gather errno: %d-%s\n", errno, strerror(errno));
}
if (output) {
@@ -190,8 +182,7 @@
unsigned int num_elements;
names = omcStrTokenize(output, "\r\n", &num_elements);
}
- }
- else {
+ } else {
DEBUGOUT("exec & gather errno: %d-%s\n", errno, strerror(errno));
}
if (output) {
@@ -547,17 +538,13 @@
rv.uint32 = 1; // Not supported
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
- }
- else if (strcasecmp("Detach", methodName) == 0)
- {
+ } else if (strcasecmp("Detach", 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("KillJob", methodName) == 0)
- {
+ } else if (strcasecmp("KillJob", methodName) == 0) {
CMLogMessage(_broker, 1, "VMBuilderService provider",
"StartService called, but not supported", NULL);
rv.uint32 = 1; // Not supported
@@ -567,9 +554,7 @@
rv.uint32 = 1; // Not supported
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
- }
- else
- {
+ } else {
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, methodName);
}
DEBUGOUT("Leaving InvokeMethod(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-07 21:11:21 UTC (rev 600)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-08 22:20:17 UTC (rev 601)
@@ -198,8 +198,7 @@
}
CMReturnObjectPath(results, objectpath);
CMReturnDone(results);
- }
- else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) {
+ } else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) {
CMPIObjectPath *antref, *depref;
objectpath = CMNewObjectPath(_broker, ns, "XEN_VMBuilderHostedService", &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
@@ -268,8 +267,7 @@
fillServiceInstance(instance);
CMReturnInstance(results, instance);
CMReturnDone(results);
- }
- else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) {
+ } else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) {
CMPIObjectPath *antref, *depref;
instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
hosted_service_class_keys, properties, &status);
@@ -345,8 +343,7 @@
service_class_keys, properties, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
DEBUGOUT("EnumInstances(): CMNewInstance() failed - %s\n", CMGetCharPtr(status.msg));
- }
- else {
+ } else {
fillServiceInstance(instance);
CMReturnInstance(results, instance);
}
@@ -609,15 +606,13 @@
rv.uint32 = 1; // Not supported
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
- }
- else if (strcasecmp("RequestStateChange", methodName) == 0) {
+ } 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) {
+ } else if (strcasecmp("StartService", methodName) == 0) {
CMLogMessage(_broker, 1, "VMBuilderService provider",
"StartService called, but not supported", NULL);
rv.uint32 = 1; // Not supported
@@ -627,8 +622,7 @@
rv.uint32 = 1; // Not supported
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
- }
- else if (strcasecmp("StopService", methodName) == 0) {
+ } else if (strcasecmp("StopService", methodName) == 0) {
CMLogMessage(_broker, 1, "VMBuilderService provider",
"StopService called, but not supported", NULL);
OMC_SETSTATUS(_broker, &status,
@@ -637,8 +631,7 @@
rv.uint32 = 1; // Not supported
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
- }
- else {
+ } else {
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, methodName);
}
DEBUGOUT("Leaving InvokeMethod(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
@@ -751,8 +744,7 @@
}
CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, CMPI_ref);
omccmpiSimpleAssocResults(ctx, instance, &status);
- }
- else if(strcasecmp(objsClassName, "XEN_VMBuilderService") == 0) {
+ } else if(strcasecmp(objsClassName, "XEN_VMBuilderService") == 0) {
if (role && *role && strcasecmp(role, "Dependent") != 0) {
/* Unknown role */
return status;
@@ -794,9 +786,7 @@
}
CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, CMPI_ref);
omccmpiSimpleAssocResults(ctx, instance, &status);
- }
- else
- {
+ } else {
DEBUGOUT("!!! Object type unknown: %s\n", objsClassName);
return status;
}
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-07 21:11:21 UTC (rev 600)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-08 22:20:17 UTC (rev 601)
@@ -221,15 +221,13 @@
snprintf(err_msg, err_msg_len,
"Failed executing sql statement: %s", zErr);
sqlite3_free(zErr);
- }
- else {
+ } else {
omcStrNCpy(err_msg, "Failed executing sql statement", err_msg_len);
}
sqlite3_close(*db);
return -1;
}
- }
- else { // Database does exist - Just open
+ } else { // Database does exist - Just open
if (sqlite3_open(VMB_DB_NAME, db)) {
snprintf(err_msg, err_msg_len,
"Failed to open database "VMB_DB_NAME": %s",
@@ -411,7 +409,7 @@
*perr = 0;
VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx;
if (pctx && pctx->col_count && column_index < pctx->col_count) {
- int cc = sqlit3_column_type(pctx->stmt, (int)column_index);
+ int cc = sqlite3_column_type(pctx->stmt, (int)column_index);
return (cc == SQLITE_NULL) ? 1 : 0;
}
if (perr)
@@ -430,6 +428,19 @@
return formatted_sql;
}
+char*
+db_sql_insert(omcStrBuf* pstrbuf, const char* format, ...)
+{
+ va_list marker;
+ char* formatted_sql;
+ va_start(marker, format);
+ formatted_sql = sqlite3_vmprintf(format, marker);
+ va_end(marker);
+ omcStrBuf_cat(pstrbuf, formatted_sql, 0);
+ sqlite3_free(formatted_sql);
+ return pstrbuf->bfr;
+}
+
void
db_destroy_formatted_sql(char* formatted_sql)
{
@@ -462,12 +473,10 @@
snprintf(err_msg, err_msg_len,
"Failed executing sql statement: %s", zErr);
sqlite3_free(zErr);
- }
- else {
+ } else {
omcStrNCpy(err_msg, "Failed executing sql statement", err_msg_len);
}
- }
- else {
+ } else {
insert_row_id = sqlite3_last_insert_rowid(db);
}
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-05-07 21:11:21 UTC (rev 600)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-05-08 22:20:17 UTC (rev 601)
@@ -2,6 +2,7 @@
#define VMBGUILDER_DB_H_GUARD_
#include <stdlib.h>
+#include <omc/string.h>
#define VMB_DB_DIR "/var/opt/xen-vm-builder/db"
#define VMB_DB_FILE_NAME "vmbuilder.db"
@@ -23,5 +24,6 @@
long long db_exec(const char* sql, char* err_msg, size_t err_msg_len);
char* db_create_formatted_sql(const char* format, ...);
void db_destroy_formatted_sql(char* formatted_sql);
+char* db_sql_insert(omcStrBuf* pstrbuf, const char* format, ...);
#endif // VMBGUILDER_DB_H_GUARD_
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c 2008-05-07 21:11:21 UTC (rev 600)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c 2008-05-08 22:20:17 UTC (rev 601)
@@ -1,8 +1,11 @@
#include "vmbuilder-util.h"
+#include <stdio.h>
+#include <cmpidt.h>
#include <cmpift.h>
#include <cmpimacs.h>
#include <omc/string.h>
+/******************************************************************************/
CMPIArray*
str2UInt16Array(const CMPIBroker* broker, const char* str)
{
@@ -27,7 +30,44 @@
}
return pra;
}
+
+/******************************************************************************/
+omcStrBuf*
+stringArray2Str(const CMPIBroker* broker, const CMPIArray* pra)
+{
+ int empty = 1;
+ CMPIData data;
+ omcStrBuf* pstrbuf = NULL;
+ char wkbfr[32];
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ size_t i, size = CMGetArrayCount(pra, &status);
+ if (!size) {
+ return NULL;
+ }
+ pstrbuf = omcStrBuf_create();
+ snprintf(wkbfr, sizeof(wkbfr), "%04d", (int)size);
+ omcStrBuf_cat(pstrbuf, wkbfr, 0);
+ for (i = 0; i < size; i++) {
+ data = CMGetArrayElementAt(pra, i, &status);
+ if (!CMIsNullValue(data)) {
+ char *p = (char*) CMGetCharPtr(data.value.string);
+ int len = strlen(p);
+ snprintf(wkbfr, sizeof(wkbfr), "%04d", len);
+ omcStrBuf_cat(pstrbuf, wkbfr, 0);
+ omcStrBuf_cat(pstrbuf, p, 0);
+ empty = 0;
+ }
+ }
+
+ if (empty && pstrbuf) {
+ omcStrBuf_destroy(pstrbuf);
+ return NULL;
+ }
+
+ return pstrbuf;
+}
+/******************************************************************************/
CMPIArray*
str2StringArray(const CMPIBroker* broker, const char* str)
{
@@ -41,8 +81,7 @@
CMPIString *pstr = CMNewString(broker, str, NULL);
pra = CMNewArray(broker, 1, CMPI_string, NULL);
CMSetArrayElementAt(pra, 1, (CMPIValue*)&pstr, CMPI_string);
- }
- else {
+ } else {
omcStrBuf* pbuf = omcStrBuf_create();
if (!pbuf) {
return NULL;
@@ -78,4 +117,103 @@
return pra;
}
+/******************************************************************************/
+void
+set_str_array_prop(
+ const CMPIBroker* broker,
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ const unsigned char* txt = db_get_results_column_text(dbctx, col_ndx, NULL);
+ if (txt) {
+ CMPIArray* pra = str2StringArray(broker, (const char*)txt);
+ if (pra) {
+ CMSetProperty(instance, prop_name, (CMPIValue*)&pra, CMPI_stringA);
+ }
+ }
+}
+/******************************************************************************/
+void
+set_str_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ const unsigned char* txt = db_get_results_column_text(dbctx, col_ndx, NULL);
+ if (txt) {
+ CMSetProperty(instance, prop_name, (CMPIValue*)txt, CMPI_chars);
+ }
+}
+
+/******************************************************************************/
+void
+set_u16_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ if (!db_column_is_null(dbctx, col_ndx, NULL)) {
+ CMPIUint16 wku16 = (CMPIUint16) db_get_results_column_int(dbctx,
+ col_ndx, NULL);
+ CMSetProperty(instance, prop_name, (CMPIValue*)&wku16, CMPI_uint16);
+ }
+}
+
+/******************************************************************************/
+void
+set_u8_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ if (!db_column_is_null(dbctx, col_ndx, NULL)) {
+ CMPIUint8 wku8 = (CMPIUint8) db_get_results_column_int(dbctx,
+ col_ndx, NULL);
+ CMSetProperty(instance, prop_name, (CMPIValue*)&wku8, CMPI_uint8);
+ }
+}
+
+/******************************************************************************/
+void
+set_u32_prop(
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name)
+{
+ if (!db_column_is_null(dbctx, col_ndx, NULL)) {
+ CMPIUint32 wku32 = (CMPIUint32) db_get_results_column_int(dbctx,
+ col_ndx, NULL);
+ CMSetProperty(instance, prop_name, (CMPIValue*)&wku32, CMPI_uint32);
+ }
+}
+
+/******************************************************************************/
+void
+set_dt_prop(
+ const CMPIBroker* broker,
+ VMBDBCtx dbctx,
+ int col_ndx,
+ CMPIInstance* instance,
+ const char* prop_name,
+ CMPIBoolean isInterval)
+{
+ if (!db_column_is_null(dbctx, col_ndx, NULL)) {
+ CMPIDateTime* datetime;
+ unsigned long long wku64;
+
+ wku64 = (unsigned long long) db_get_results_column_int64(dbctx,
+ col_ndx, NULL);
+ datetime = CMNewDateTimeFromBinary(broker, wku64, isInterval, NULL);
+ CMSetProperty(instance, prop_name, (CMPIValue*)&datetime,
+ CMPI_dateTime);
+ }
+}
+
+
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h 2008-05-07 21:11:21 UTC (rev 600)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h 2008-05-08 22:20:17 UTC (rev 601)
@@ -1,9 +1,25 @@
#ifndef VMBUILDER_UTIL_H_GUARD
#define VMBUILDER_UTIL_H_GUARD
+#include "vmbuilder-db.h"
#include <cmpidt.h>
+#include <cmpift.h>
+#include <cmpimacs.h>
CMPIArray* str2UInt16Array(const CMPIBroker* broker, const char* str);
CMPIArray* str2StringArray(const CMPIBroker* broker, const char* str);
+omcStrBuf* stringArray2Str(const CMPIBroker* broker, const CMPIArray* pra);
+void set_str_array_prop(const CMPIBroker* broker, VMBDBCtx dbctx,
+ int col_ndx, CMPIInstance* instance, const char* prop_name);
+void set_str_prop(VMBDBCtx dbctx, int col_ndx, CMPIInstance* instance,
+ const char* prop_name);
+void set_u16_prop(VMBDBCtx dbctx, int col_ndx, CMPIInstance* instance,
+ const char* prop_name);
+void set_u8_prop(VMBDBCtx dbctx, int col_ndx, CMPIInstance* instance,
+ const char* prop_name);
+void set_u32_prop(VMBDBCtx dbctx, int col_ndx, CMPIInstance* instance,
+ const char* prop_name);
+void set_dt_prop(const CMPIBroker* broker, VMBDBCtx dbctx, int col_ndx,
+ CMPIInstance* instance, const char* prop_name, CMPIBoolean isInterval);
#endif /* VMBUILDER_UTIL_H_GUARD */
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-07 21:11:21 UTC (rev 600)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-08 22:20:17 UTC (rev 601)
@@ -30,7 +30,6 @@
* Author: Jon Carey (jc...@no...)
******************************************************************************/
#include "config.h"
-#include "vmbuilder-db.h"
#include "vmbuilder-util.h"
#include <unistd.h>
@@ -68,90 +67,51 @@
#define DEBUGOUT(fmt, args...)
#endif
-const char* all_cd_fields_query_with_where = "SELECT "
- "InstanceID,"
- "AutoMaticRecoveryAction,"
- "AutoMaticShutdownAction,"
- "AutoMaticStartupAction,"
- "AutoMaticStartupActionDelay,"
- "AutoMaticStartupActionSequenceNumber,"
- "CPUArchitecture,"
- "Caption,"
- "ChangableType,"
- "ConfigurationDataRoot,"
- "ConfigurationFile,"
- "ConfigurationID,"
- "ConfigurationName,"
- "CreationTime,"
- "Description,"
- "Disks,"
- "ElementName,"
- "ExtraConfigInfo,"
- "ExtraInstallArgs,"
- "GraphicsType,"
- "GraphicsViewerType,"
- "LogDataRoot,"
- "MaxMemory,"
- "Memory,"
- "Nics,"
- "Notes,"
- "NumVCPUs,"
- "OSType,"
- "RecoveryFile,"
- "ResponseFile,"
- "SnapshotDataRoot,"
- "SourceURL,"
- "SuspendDataRoot,"
- "SwapFileDataRoot,"
- "UUID,"
- "VNCPort,"
- "VirtType,"
- "VirtualSystemIdentifier,"
- "VirtualSystemType "
- "FROM CreationData "
+#define CSV_FIELDS \
+ "InstanceID," \
+ "AutoMaticRecoveryAction," \
+ "AutoMaticShutdownAction," \
+ "AutoMaticStartupAction," \
+ "AutoMaticStartupActionDelay," \
+ "AutoMaticStartupActionSequenceNumber," \
+ "CPUArchitecture," \
+ "Caption," \
+ "ChangableType," \
+ "ConfigurationDataRoot," \
+ "ConfigurationFile," \
+ "ConfigurationID," \
+ "ConfigurationName," \
+ "CreationTime," \
+ "Description," \
+ "Disks," \
+ "ElementName," \
+ "ExtraConfigInfo," \
+ "ExtraInstallArgs," \
+ "GraphicsType," \
+ "GraphicsViewerType," \
+ "LogDataRoot," \
+ "MaxMemory," \
+ "Memory," \
+ "Nics," \
+ "Notes," \
+ "NumVCPUs," \
+ "OSType," \
+ "RecoveryFile," \
+ "ResponseFile," \
+ "SnapshotDataRoot," \
+ "SourceURL," \
+ "SuspendDataRoot," \
+ "SwapFileDataRoot," \
+ "UUID," \
+ "VNCPort," \
+ "VirtType," \
+ "VirtualSystemIdentifier," \
+ "VirtualSystemType"
+
+const char* all_cd_fields_query_with_where = "SELECT "CSV_FIELDS" FROM CreationData "
"WHERE InstanceID=%Q;";
-const char* all_cd_fields_query = "SELECT "
- "InstanceID,"
- "AutoMaticRecoveryAction,"
- "AutoMaticShutdownAction,"
- "AutoMaticStartupAction,"
- "AutoMaticStartupActionDelay,"
- "AutoMaticStartupActionSequenceNumber,"
- "CPUArchitecture,"
- "Caption,"
- "ChangableType,"
- "ConfigurationDataRoot,"
- "ConfigurationFile,"
- "ConfigurationID,"
- "ConfigurationName,"
- "CreationTime,"
- "Description,"
- "Disks,"
- "ElementName,"
- "ExtraConfigInfo,"
- "ExtraInstallArgs,"
- "GraphicsType,"
- "GraphicsViewerType,"
- "LogDataRoot,"
- "MaxMemory,"
- "Memory,"
- "Nics,"
- "Notes,"
- "NumVCPUs,"
- "OSType,"
- "RecoveryFile,"
- "ResponseFile,"
- "SnapshotDataRoot,"
- "SourceURL,"
- "SuspendDataRoot,"
- "SwapFileDataRoot,"
- "UUID,"
- "VNCPort,"
- "VirtType,"
- "VirtualSystemIdentifier,"
- "VirtualSystemType "
- "FROM CreationData;";
+const char* all_cd_fields_query = "SELECT "CSV_FIELDS" FROM CreationData;";
enum ALL_CD_FIELDS_NDX {
CDF_InstanceID,
@@ -201,6 +161,55 @@
*/
static const CMPIBroker* _broker;
+/*****************************************************************************/
+static void
+_fillInstance(
+ VMBDBCtx dbctx,
+ CMPIInstance* instance)
+{
+ set_str_prop(dbctx, CDF_InstanceID, instance, "InstanceID");
+ set_u16_prop(dbctx, CDF_AutoMaticRecoveryAction, instance, "AutoMaticRecoveryAction");
+ set_u16_prop(dbctx, CDF_AutoMaticShutdownAction, instance, "AutoMaticShutdownAction");
+ set_u16_prop(dbctx, CDF_AutoMaticStartupAction, instance, "AutoMaticStartupAction");
+ set_dt_prop(_broker, dbctx, CDF_AutoMaticStartupActionDelay, instance,
+ "AutoMaticStartupActionDelay", 1);
+ set_u16_prop(dbctx, CDF_AutoMaticStartupActionSequenceNumber, instance,
+ "AutoMaticStartupActionSequenceNumber");
+ set_str_prop(dbctx, CDF_CPUArchitecture, instance, "CPUArchitecture");
+ set_str_prop(dbctx, CDF_Caption, instance, "Caption");
+ set_u16_prop(dbctx, CDF_ChangableType, instance, "ChangableType");
+ set_str_prop(dbctx, CDF_ConfigurationDataRoot, instance, "ConfigurationDataRoot");
+ set_str_prop(dbctx, CDF_ConfigurationFile, instance, "ConfigurationFile");
+ set_str_prop(dbctx, CDF_ConfigurationID, instance, "ConfigurationID");
+ set_str_prop(dbctx, CDF_ConfigurationName, instance, "ConfigurationName");
+ set_dt_prop(_broker, dbctx, CDF_CreationTime, instance, "CreationTime", 0);
+ set_str_prop(dbctx, CDF_Description, instance, "Description");
+ set_str_array_prop(_broker, dbctx, CDF_Disks, instance, "Disks");
+ set_str_prop(dbctx, CDF_ElementName, instance, "ElementName");
+ set_str_array_prop(_broker, dbctx, CDF_ExtraConfigInfo, instance, "ExtraConfigInfo");
+ set_str_prop(dbctx, CDF_ExtraInstallArgs, instance, "ExtraInstallArgs");
+ set_u32_prop(dbctx, CDF_GraphicsType, instance, "GraphicsType");
+ set_u32_prop(dbctx, CDF_GraphicsViewerType, instance, "GraphicsViewerType");
+ set_str_prop(dbctx, CDF_LogDataRoot, instance, "LogDataRoot");
+ set_u32_prop(dbctx, CDF_MaxMemory, instance, "MaxMemory");
+ set_u32_prop(dbctx, CDF_Memory, instance, "Memory");
+ set_str_array_prop(_broker, dbctx, CDF_Nics, instance, "Nics");
+ set_str_array_prop(_broker, dbctx, CDF_Notes, instance, "Notes");
+ set_u8_prop(dbctx, CDF_NumVCPUs, instance, "NumVCPUs");
+ set_u32_prop(dbctx, CDF_OSType, instance, "OSType");
+ set_str_prop(dbctx, CDF_RecoveryFile, instance, "RecoveryFile");
+ set_str_prop(dbctx, CDF_ResponseFile, instance, "ResponseFile");
+ set_str_prop(dbctx, CDF_SnapshotDataRoot, instance, "SnapshotDataRoot");
+ set_str_prop(dbctx, CDF_SourceURL, instance, "SourceURL");
+ set_str_prop(dbctx, CDF_SuspendDataRoot, instance, "SuspendDataRoot");
+ set_str_prop(dbctx, CDF_SwapFileDataRoot, instance, "SwapFileDataRoot");
+ set_str_prop(dbctx, CDF_UUID, instance, "UUID");
+ set_u32_prop(dbctx, CDF_VNCPort, instance, "VNCPort");
+ set_u32_prop(dbctx, CDF_VirtType, instance, "VirtType");
+ set_str_prop(dbctx, CDF_VirtualSystemIdentifier, instance, "VirtualSystemIdentifier");
+ set_str_prop(dbctx, CDF_VirtualSystemType, instance, "VirtualSystemType");
+}
+
/******************************************************************************
CMPI INSTANCE PROVIDER FUNCTIONS
******************************************************************************/
@@ -258,151 +267,6 @@
return status;
}
-/******************************************************************************/
-static void
-set_str_array_prop(
- VMBDBCtx dbctx,
- int col_ndx,
- CMPIInstance* instance,
- const char* prop_name)
-{
- const unsigned char* txt = db_get_results_column_text(dbctx, col_ndx, NULL);
- if (txt) {
- CMPIArray* pra = str2StringArray(_broker, (const char*)txt);
- if (pra) {
- CMSetProperty(instance, prop_name, (CMPIValue*)&pra, CMPI_stringA);
- }
- }
-}
-
-/******************************************************************************/
-static void
-set_str_prop(
- VMBDBCtx dbctx,
- int col_ndx,
- CMPIInstance* instance,
- const char* prop_name)
-{
- const unsigned char* txt = db_get_results_column_text(dbctx, col_ndx, NULL);
- if (txt) {
- CMSetProperty(instance, prop_name, (CMPIValue*)txt, CMPI_chars);
- }
-}
-
-/******************************************************************************/
-static void
-set_u16_prop(
- VMBDBCtx dbctx,
- int col_ndx,
- CMPIInstance* instance,
- const char* prop_name)
-{
- if (!db_column_is_null(dbctx, col_ndx, NULL)) {
- CMPIUint16 wku16 = (CMPIUint16) db_get_results_column_int(dbctx,
- col_ndx, NULL);
- CMSetProperty(instance, prop_name, (CMPIValue*)&wku16, CMPI_uint16);
- }
-}
-
-/******************************************************************************/
-static void
-set_u8_prop(
- VMBDBCtx dbctx,
- int col_ndx,
- CMPIInstance* instance,
- const char* prop_name)
-{
- if (!db_column_is_null(dbctx, col_ndx, NULL)) {
- CMPIUint8 wku8 = (CMPIUint8) db_get_results_column_int(dbctx,
- col_ndx, NULL);
- CMSetProperty(instance, prop_name, (CMPIValue*)&wku8, CMPI_uint8);
- }
-}
-
-/******************************************************************************/
-static void
-set_u32_prop(
- VMBDBCtx dbctx,
- int col_ndx,
- CMPIInstance* instance,
- const char* prop_name)
-{
- if (!db_column_is_null(dbctx, col_ndx, NULL)) {
- CMPIUint32 wku32 = (CMPIUint32) db_get_results_column_int(dbctx,
- col_ndx, NULL);
- CMSetProperty(instance, prop_name, (CMPIValue*)&wku32, CMPI_uint32);
- }
-}
-
-/******************************************************************************/
-static void
-set_dt_prop(
- VMBDBCtx dbctx,
- int col_ndx,
- CMPIInstance* instance,
- const char* prop_name,
- CMPIBoolean isInterval)
-{
- if (!db_column_is_null(dbctx, col_ndx, NULL)) {
- CMPIDateTime* datetime;
- unsigned long long wku64;
-
- wku64 = (unsigned long long) db_get_results_column_int64(dbctx,
- col_ndx, NULL);
- datetime = CMNewDateTimeFromBinary(_broker, wku64, isInterval, NULL);
- CMSetProperty(instance, prop_name, (CMPIValue*)&datetime,
- CMPI_dateTime);
- }
-}
-
-static void
-_fillInstance(
- VMBDBCtx dbctx,
- CMPIInstance* instance)
-{
- set_str_prop(dbctx, CDF_InstanceID, instance, "InstanceID");
- set_u16_prop(dbctx, CDF_AutoMaticRecoveryAction, instance, "AutoMaticRecoveryAction");
- set_u16_prop(dbctx, CDF_AutoMaticShutdownAction, instance, "AutoMaticShutdownAction");
- set_u16_prop(dbctx, CDF_AutoMaticStartupAction, instance, "AutoMaticStartupAction");
- set_dt_prop(dbctx, CDF_AutoMaticStartupActionDelay, instance,
- "AutoMaticStartupActionDelay", 1);
- set_u16_prop(dbctx, CDF_AutoMaticStartupActionSequenceNumber, instance,
- "AutoMaticStartupActionSequenceNumber");
- set_str_prop(dbctx, CDF_CPUArchitecture, instance, "CPUArchitecture");
- set_str_prop(dbctx, CDF_Caption, instance, "Caption");
- set_u16_prop(dbctx, CDF_ChangableType, instance, "ChangableType");
- set_str_prop(dbctx, CDF_ConfigurationDataRoot, instance, "ConfigurationDataRoot");
- set_str_prop(dbctx, CDF_ConfigurationFile, instance, "ConfigurationFile");
- set_str_prop(dbctx, CDF_ConfigurationID, instance, "ConfigurationID");
- set_str_prop(dbctx, CDF_ConfigurationName, instance, "ConfigurationName");
- set_dt_prop(dbctx, CDF_CreationTime, instance, "CreationTime", 0);
- set_str_prop(dbctx, CDF_Description, instance, "Description");
- set_str_array_prop(dbctx, CDF_Disks, instance, "Disks");
- set_str_prop(dbctx, CDF_ElementName, instance, "ElementName");
- set_str_array_prop(dbctx, CDF_ExtraConfigInfo, instance, "ExtraConfigInfo");
- set_str_prop(dbctx, CDF_ExtraInstallArgs, instance, "ExtraInstallArgs");
- set_u32_prop(dbctx, CDF_GraphicsType, instance, "GraphicsType");
- set_u32_prop(dbctx, CDF_GraphicsViewerType, instance, "GraphicsViewerType");
- set_str_prop(dbctx, CDF_LogDataRoot, instance, "LogDataRoot");
- set_u32_prop(dbctx, CDF_MaxMemory, instance, "MaxMemory");
- set_u32_prop(dbctx, CDF_Memory, instance, "Memory");
- set_str_array_prop(dbctx, CDF_Nics, instance, "Nics");
- set_str_array_prop(dbctx, CDF_Notes, instance, "Notes");
- set_u8_prop(dbctx, CDF_NumVCPUs, instance, "NumVCPUs");
- set_u32_prop(dbctx, CDF_OSType, instance, "OSType");
- set_str_prop(dbctx, CDF_RecoveryFile, instance, "RecoveryFile");
- set_str_prop(dbctx, CDF_ResponseFile, instance, "ResponseFile");
- set_str_prop(dbctx, CDF_SnapshotDataRoot, instance, "SnapshotDataRoot");
- set_str_prop(dbctx, CDF_SourceURL, instance, "SourceURL");
- set_str_prop(dbctx, CDF_SuspendDataRoot, instance, "SuspendDataRoot");
- set_str_prop(dbctx, CDF_SwapFileDataRoot, instance, "SwapFileDataRoot");
- set_str_prop(dbctx, CDF_UUID, instance, "UUID");
- set_u32_prop(dbctx, CDF_VNCPort, instance, "VNCPort");
- set_u32_prop(dbctx, CDF_VirtType, instance, "VirtType");
- set_str_prop(dbctx, CDF_VirtualSystemIdentifier, instance, "VirtualSystemIdentifier");
- set_str_prop(dbctx, CDF_VirtualSystemType, instance, "VirtualSystemType");
-}
-
/******************************************************************************
EnumInstances()
params: CMPIInstanceMI* self: [in] Handle to this provider
@@ -492,7 +356,7 @@
}
iid = CMGetCharPtr(key.value.string);
- if (!iid || strlen(iid) == 0) {
+ if (!iid || !strlen(iid)) {
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty InstanceID property");
return status;
}
@@ -511,8 +375,7 @@
creation_data_keys, properties, &status);
_fillInstance(dbctx, instance);
CMReturnInstance(results, instance);
- }
- else {
+ } else {
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Instance Not Found");
}
db_destroy_select_results(dbctx);
@@ -543,6 +406,94 @@
}
+/*****************************************************************************/
+static void
+add_u8_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance,
+ const char* prop_name)
+{
+ CMPIData data = CMGetProperty(instance, prop_name, NULL);
+ if (!CMIsNullValue(data)) {
+ char wkbfr[32];
+ snprintf(wkbfr, sizeof(wkbfr), "%u,", data.value.uint8);
+ omcStrBuf_cat(pstrbuf, wkbfr, 0);
+ } else {
+ omcStrBuf_cat(pstrbuf, "NULL,", 0);
+ }
+}
+
+/********************...
[truncated message content] |
|
From: <jc...@us...> - 2008-05-14 21:27:10
|
Revision: 610
http://omc.svn.sourceforge.net/omc/?rev=610&view=rev
Author: jcarey
Date: 2008-05-14 14:27:14 -0700 (Wed, 14 May 2008)
Log Message:
-----------
Got CreateVM working
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-14 16:12:20 UTC (rev 609)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-14 21:27:14 UTC (rev 610)
@@ -325,19 +325,84 @@
const CMPIObjectPath* cop,
const char** properties)
{
- //CMPIInstance* instance;
+ CMPIInstance* instance;
//CMPIObjectPath *objectpath;
CMPIStatus status = {CMPI_RC_OK, NULL};
- //char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
const char *className;
+ CMPIData key;
+ int found = 0;
+ char** names = NULL;
DEBUGOUT("GetInstance() called\n");
className = CMGetCharPtr(CMGetClassName(cop, NULL));
if (strcasecmp(className, "XEN_VMBuilderJob") == 0)
{
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
- "Instance does not exists");
+ const char* job_name_key;
+ key = CMGetKey(cop, "Name", &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) {
+ DEBUGOUT("GetInstance(): CMGetKey(\"Name\") failed - %d\n", status.rc);
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ "Cannot get 'Name' property");
+ return status;
+ }
+
+ job_name_key = CMGetCharPtr(key.value.string);
+ if (!job_name_key || !strlen(job_name_key)) {
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty Name property");
+ return status;
+ }
+
+ names = get_job_names();
+ if (names) {
+ VMInstallInfo info;
+ const char* p;
+ int i;
+ for(i = 0; names[i]; i++) {
+ if (!strcasecmp(names[i], job_name_key)) {
+ if(get_job_info(names[i], &info) == 0) {
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderJob",
+ job_class_keys, properties, &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullObject(instance)) {
+ DEBUGOUT("EnumInstances(): CMNewInstance() failed - %d\n",
+ status.rc);
+ free(names);
+ return status;
+ }
+ CMSetProperty(instance, "Name", (CMPIValue*)names[i],
+ CMPI_chars);
+ CMSetProperty(instance, "VMName", (CMPIValue*)info.name,
+ CMPI_chars);
+ CMSetProperty(instance, "VncURL", (CMPIValue*)info.vnc,
+ CMPI_chars);
+ CMSetProperty(instance, "VM_UUID", (CMPIValue*)info.uuid,
+ CMPI_chars);
+ CMSetProperty(instance, "ExitCode",
+ (CMPIValue*)&info.exit_code, CMPI_uint32);
+ CMSetProperty(instance, "InstallLogFileLocation",
+ (CMPIValue*)info.log, CMPI_chars);
+ p = (info.state > 8) ? "UNKNOWN" : job_states[info.state];
+ CMSetProperty(instance, "JobStatus", (CMPIValue*)p,
+ CMPI_chars);
+ CMSetProperty(instance, "StatusFileName", (CMPIValue*)info.inotify,
+ CMPI_chars);
+ CMReturnInstance(results, instance);
+ found = 1;
+ break;
+ } else {
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ "Unable to get job info for job");
+ free(names);
+ return status;
+ }
+ }
+ }
+ free(names);
+ }
+ if (!found) {
+ CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
+ }
}
DEBUGOUT("Leaving GetInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-14 16:12:20 UTC (rev 609)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-14 21:27:14 UTC (rev 610)
@@ -617,8 +617,13 @@
/*****************************************************************************/
static CMPIObjectPath*
-start_create_vm(const char* vmname, const CMPIInstance* cdci,
- const char* uuid, const char* ns, CMPIValue *prv,
+start_create_vm(
+ const CMPIContext* context,
+ const char* vmname,
+ const CMPIInstance* cdci,
+ const char* uuid,
+ const char* ns,
+ CMPIValue *prv,
CMPIStatus *pstatus)
{
CMPIData data;
@@ -840,9 +845,38 @@
}
omcStrArray_destroy(pstra);
if (response_file) {
+ if (jobref) {
+ /*
+ * Wait until Job state reaches the 'INSTALL' and then delete
+ * the response file.
+ */
+ CMPIInstance *jobci;
+ CMPIStatus lstatus;
+ int fail_count = 0;
+ while(fail_count < 5) {
+ omcMilliSleep(500);
+ sleep(1);
+ jobci = CBGetInstance(_broker, context, jobref, NULL,
+ &lstatus);
+ if (jobci == NULL) {
+ fail_count++;
+ continue;
+ }
+ data = CMGetProperty(jobci, "JobStatus", NULL);
+ if (!CMIsNullValue(data)) {
+ const char *p = CMGetCharPtr(data.value.string);
+ if (strcasecmp(p, "SETTINGS") == 0
+ || strcasecmp(p, "PREP_INSTALL")) {
+ continue;
+ }
+ break;
+ } else {
+ fail_count++;
+ }
+ }
+ }
unlink(response_file);
}
-
DEBUGOUT("start_create_vm() returning\n");
return jobref;
}
@@ -923,7 +957,8 @@
DEBUGOUT("InvokeMethod(): UUID specified: %s\n", uuid);
}
- jobref = start_create_vm(vmname, cdci, uuid, ns, &rv, &status);
+ jobref = start_create_vm(context, vmname, cdci, uuid, ns, &rv,
+ &status);
if (!jobref) {
DEBUGOUT("start_create_vm returned a NULL ref. status: %d\n", status.rc);
return status;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jc...@us...> - 2008-05-15 00:05:15
|
Revision: 611
http://omc.svn.sourceforge.net/omc/?rev=611&view=rev
Author: jcarey
Date: 2008-05-14 17:05:21 -0700 (Wed, 14 May 2008)
Log Message:
-----------
Some cleanup/bug fix. more trace
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-14 21:27:14 UTC (rev 610)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-15 00:05:21 UTC (rev 611)
@@ -37,9 +37,10 @@
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
//#include <pwd.h>
-//#include <sys/types.h>
//#include <time.h>
//#include <signal.h>
#include <cmpidt.h>
@@ -633,7 +634,7 @@
char wkbfr[256];
char rspbfr[PATH_MAX];
char *response_file = NULL;
- int cc;
+ int cc, i;
size_t output_size;
char* output;
CMPIObjectPath *jobref = NULL;
@@ -763,9 +764,13 @@
CMPIData ndata = CMGetArrayElementAt(data.value.array, i, pstatus);
if (!CMIsNullValue(ndata)) {
const char* pd = (char*) CMGetCharPtr(ndata.value.string);
- if (pd && strlen(pd)) {
+ if (pd) {
omcStrArray_append(pstra, "--nic");
- omcStrArray_append(pstra, pd);
+ if (strcasecmp(pd, "default")) {
+ omcStrArray_append(pstra, pd);
+ } else {
+ omcStrArray_append(pstra, "''");
+ }
}
}
}
@@ -821,21 +826,39 @@
}
/* Execute vm-install with the constructed command line */
+#ifdef XEN_VMBUILDER_DEBUG
+ printf("Executing:\n");
+ for(i = 0; pstra->strs[i]; i++) {
+ printf("%s ", pstra->strs[i]);
+ }
+ printf("\n");
+#endif
+
output = NULL;
+ DEBUGOUT("Calling vm-install...\n");
if (omcExecuteProcessAndGatherOutputAndError((char* const*) pstra->strs,
NULL, &output, &output_size, -1, NULL, NULL, -1,
NULL, &cc, -1) == 0) {
+ DEBUGOUT("vm-install returned 0\n");
if (cc == 0 && output) {
+ DEBUGOUT("vm-install status is 0\n");
jobref = CMNewObjectPath(_broker, ns, "XEN_VMBUilderJob", pstatus);
CMAddKey(jobref, "Name", (CMPIValue*)output, CMPI_chars);
prv->uint32 = 0;
} else {
- prv->uint32 = (CMPIUint32)cc;
+ prv->uint32 = (CMPIUint32)WEXITSTATUS(cc);
+ DEBUGOUT("vm-install failed status: %u\n", prv->uint32);
+#ifdef XEN_VMBUILDER_DEBUG
+ if(output) {
+ printf("vm-install output: %s\n", output);
+ }
+#endif
}
} else {
strerror_r(errno, wkbfr, sizeof(wkbfr));
snprintf(rspbfr, sizeof(rspbfr),
"Failed to execute vm-install: %s\n", wkbfr);
+ DEBUGOUT("%s\n", rspbfr);
prv->uint32 = 1;
OMC_SETSTATUS(_broker, pstatus, CMPI_RC_ERR_FAILED, rspbfr);
}
@@ -844,8 +867,11 @@
free(output);
}
omcStrArray_destroy(pstra);
+ DEBUGOUT("checking for existence response file\n");
if (response_file) {
+ DEBUGOUT("Should have response file %s\n", response_file);
if (jobref) {
+ DEBUGOUT("There is a job reference, so waiting for right state\n");
/*
* Wait until Job state reaches the 'INSTALL' and then delete
* the response file.
@@ -853,28 +879,36 @@
CMPIInstance *jobci;
CMPIStatus lstatus;
int fail_count = 0;
- while(fail_count < 5) {
+ DEBUGOUT("Entering GetInstance loop for Job instance...\n");
+ while(fail_count < 10) {
omcMilliSleep(500);
- sleep(1);
jobci = CBGetInstance(_broker, context, jobref, NULL,
&lstatus);
if (jobci == NULL) {
+ DEBUGOUT("GetInstance for Job returned NULL. "
+ "Inc fail count\n");
fail_count++;
continue;
}
data = CMGetProperty(jobci, "JobStatus", NULL);
if (!CMIsNullValue(data)) {
const char *p = CMGetCharPtr(data.value.string);
- if (strcasecmp(p, "SETTINGS") == 0
- || strcasecmp(p, "PREP_INSTALL")) {
+ if (strcasecmp(p, "SETTINGS")
+ && strcasecmp(p, "PREP_INSTALL")) {
+ DEBUGOUT("Still to soon to delete Response file\n");
continue;
}
+ DEBUGOUT("Install state allows for response file "
+ "delete\n");
break;
} else {
+ DEBUGOUT("Job instance has NULL JobStatus property. "
+ "Inc Fail count\n");
fail_count++;
}
}
}
+ DEBUGOUT("Deleting response file: %s\n", response_file);
unlink(response_file);
}
DEBUGOUT("start_create_vm() returning\n");
@@ -959,13 +993,14 @@
jobref = start_create_vm(context, vmname, cdci, uuid, ns, &rv,
&status);
- if (!jobref) {
- DEBUGOUT("start_create_vm returned a NULL ref. status: %d\n", status.rc);
- return status;
+ if (jobref) {
+ DEBUGOUT("start_create_vm returned a valid ref. "
+ "rv.uint32: %u status: %d\n", rv.uint32, status.rc);
+ CMAddArg(out, "VMBuilderJob", (CMPIValue*)&jobref, CMPI_ref);
+ } else {
+ DEBUGOUT("start_create_vm returned a NULL ref. "
+ "rv.uint32: %u status: %d\n", rv.uint32, status.rc);
}
- DEBUGOUT("start_create_vm returned a valid ref. "
- "rv.uint32: %u status: %d\n", rv.uint32, status.rc);
- CMAddArg(out, "VMBuilderJob", (CMPIValue*)&jobref, CMPI_ref);
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
} else if (strcasecmp("RequestStateChange", methodName) == 0) {
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-14 21:27:14 UTC (rev 610)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-15 00:05:21 UTC (rev 611)
@@ -1099,11 +1099,11 @@
omcStrBuf_destroy(pstrbuf);
return status;
}
+ add_u32_prop_to_query(pstrbuf, newinstance, "GraphicsViewerType", &data);
if (valid_graphics_viewer_type(&data, &status) != CMPI_RC_OK) {
omcStrBuf_destroy(pstrbuf);
return status;
}
- add_u32_prop_to_query(pstrbuf, newinstance, "GraphicsViewerType", &data);
add_str_prop_to_query(pstrbuf, newinstance, "LogDataRoot", 0);
add_u32_prop_to_query(pstrbuf, newinstance, "MaxMemory", NULL);
add_u32_prop_to_query(pstrbuf, newinstance, "Memory", NULL);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jc...@us...> - 2008-05-27 17:38:50
|
Revision: 620
http://omc.svn.sourceforge.net/omc/?rev=620&view=rev
Author: jcarey
Date: 2008-05-27 10:37:39 -0700 (Tue, 27 May 2008)
Log Message:
-----------
Implemented OwningJobElement association
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
Added Paths:
-----------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.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-05-23 22:42:32 UTC (rev 619)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-05-27 17:37:39 UTC (rev 620)
@@ -3,7 +3,8 @@
provider_LTLIBRARIES = \
libomc_xenvmbuilder.la \
libomc_xenvmbuilderjob.la \
- libomc_xencreationdata.la
+ libomc_xencreationdata.la \
+ libomc_xenowningjob.la
lib_LTLIBRARIES = \
libomc_xenvmbuilder_common.la
@@ -53,6 +54,20 @@
$(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
###
+# libomc_xenowningjob
+###
+libomc_xenowningjob_la_SOURCES = \
+ owning-job.c
+
+libomc_xenowningjob_la_LDFLAGS = \
+ -lpthread \
+ -lomc_cmpi \
+ -version-info 1
+
+libomc_xenowningjob_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+
+###
# libomc_xenvmbuilder_common
###
libomc_xenvmbuilder_common_la_SOURCES = \
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-23 22:42:32 UTC (rev 619)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-27 17:37:39 UTC (rev 620)
@@ -1091,100 +1091,99 @@
DEBUGOUT("doReferences called\n");
- if (strcasecmp(assocClass, "XEN_VMBuilderHostedService") == 0) {
- char *objsClassName = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+ char *objsClassName = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
- /* Is target an OS object? */
- if(strcasecmp(objsClassName, "OMC_UnitaryComputerSystem") == 0) {
- if (role && *role && strcasecmp(role, "Antecedent") != 0) {
- /* Unknown role */
+ /* Is target an OS object? */
+ if(strcasecmp(objsClassName, "OMC_UnitaryComputerSystem") == 0) {
+ if (role && *role && strcasecmp(role, "Antecedent") != 0) {
+ /* Unknown role */
+ return status;
+ }
+ if (resultRole && *resultRole && strcasecmp(resultRole,
+ "Dependent") != 0) {
+ /* Unknown resultRole */
+ return status;
+ }
+ if (resultClass && *resultClass) {
+ if (!omccmpiClassIsDerivedFrom("XEN_VMBuilderService",
+ resultClass, _broker, ns, &status)) {
return status;
}
- if (resultRole && *resultRole && strcasecmp(resultRole,
- "Dependent") != 0) {
- /* Unknown resultRole */
- return status;
- }
- if (resultClass && *resultClass) {
- if (!omccmpiClassIsDerivedFrom("XEN_VMBuilderService",
- resultClass, _broker, ns, &status)) {
- return status;
- }
- }
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
- hosted_service_class_keys, properties, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
- DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
- CMGetCharPtr(status.msg));
- return status;
- }
+ }
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
+ hosted_service_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
+ DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
+ CMGetCharPtr(status.msg));
+ return status;
+ }
- csOp = omccmpiCreateCSObjectPath(_broker, ns, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(csOp)) {
- DEBUGOUT("doReferences(): omccmpiCreateCSObjectPath failed - %s\n",
- CMGetCharPtr(status.msg));
- return status;
- }
+ csOp = omccmpiCreateCSObjectPath(_broker, ns, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(csOp)) {
+ DEBUGOUT("doReferences(): omccmpiCreateCSObjectPath failed - %s\n",
+ CMGetCharPtr(status.msg));
+ return status;
+ }
- CMSetProperty(instance, "Antecedent", (CMPIValue*)&csOp, CMPI_ref);
+ CMSetProperty(instance, "Antecedent", (CMPIValue*)&csOp, CMPI_ref);
- objectpath = get_service_ref(ns, &status);
- if ((status.rc != CMPI_RC_OK) || objectpath == NULL) {
- DEBUGOUT("doReferences(): get_service_ref() failed - %s\n",
- CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
- "Failed creating new object path");
+ objectpath = get_service_ref(ns, &status);
+ if ((status.rc != CMPI_RC_OK) || objectpath == NULL) {
+ DEBUGOUT("doReferences(): get_service_ref() failed - %s\n",
+ CMGetCharPtr(status.msg));
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ "Failed creating new object path");
+ return status;
+ }
+ CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, CMPI_ref);
+ omccmpiSimpleAssocResults(ctx, instance, &status);
+ } else if(strcasecmp(objsClassName, "XEN_VMBuilderService") == 0) {
+ if (role && *role && strcasecmp(role, "Dependent") != 0) {
+ /* Unknown role */
+ return status;
+ }
+ if (resultRole && *resultRole && strcasecmp(resultRole,
+ "Antecedent") != 0) {
+ /* Unknown resultRole */
+ return status;
+ }
+ if (resultClass && *resultClass) {
+ if (!omccmpiClassIsDerivedFrom("OMC_UnitaryComputerSystem",
+ resultClass, _broker, ns, &status)) {
return status;
}
- CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, CMPI_ref);
- omccmpiSimpleAssocResults(ctx, instance, &status);
- } else if(strcasecmp(objsClassName, "XEN_VMBuilderService") == 0) {
- if (role && *role && strcasecmp(role, "Dependent") != 0) {
- /* Unknown role */
- return status;
- }
- if (resultRole && *resultRole && strcasecmp(resultRole,
- "Antecedent") != 0) {
- /* Unknown resultRole */
- return status;
- }
- if (resultClass && *resultClass) {
- if (!omccmpiClassIsDerivedFrom("OMC_UnitaryComputerSystem",
- resultClass, _broker, ns, &status)) {
- return status;
- }
- }
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
- hosted_service_class_keys, properties, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
- DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
- CMGetCharPtr(status.msg));
- return status;
- }
+ }
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
+ hosted_service_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
+ DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
+ CMGetCharPtr(status.msg));
+ return status;
+ }
- csOp = omccmpiCreateCSObjectPath(_broker, ns, &status);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(csOp)) {
- DEBUGOUT("doReferences(): omccmpiCreateCSObjectPath failed - %s\n",
- CMGetCharPtr(status.msg));
- return status;
- }
+ csOp = omccmpiCreateCSObjectPath(_broker, ns, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(csOp)) {
+ DEBUGOUT("doReferences(): omccmpiCreateCSObjectPath failed - %s\n",
+ CMGetCharPtr(status.msg));
+ return status;
+ }
- CMSetProperty(instance, "Antecedent", (CMPIValue*)&csOp, CMPI_ref);
- objectpath = get_service_ref(ns, &status);
- if ((status.rc != CMPI_RC_OK) || objectpath == NULL) {
- DEBUGOUT("doReferences(): get_service_ref() failed - %s\n",
- CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
- "Failed creating new object path");
- return status;
- }
- CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, CMPI_ref);
- omccmpiSimpleAssocResults(ctx, instance, &status);
- } else {
- DEBUGOUT("!!! Object type unknown: %s\n", objsClassName);
+ CMSetProperty(instance, "Antecedent", (CMPIValue*)&csOp, CMPI_ref);
+ objectpath = get_service_ref(ns, &status);
+ if ((status.rc != CMPI_RC_OK) || objectpath == NULL) {
+ DEBUGOUT("doReferences(): get_service_ref() failed - %s\n",
+ CMGetCharPtr(status.msg));
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ "Failed creating new object path");
return status;
}
+ CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, CMPI_ref);
+ omccmpiSimpleAssocResults(ctx, instance, &status);
+ } else {
+ DEBUGOUT("!!! Object type unknown: %s\n", objsClassName);
+ return status;
}
+
DEBUGOUT("Leaving doReferences\n");
return status;
}
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c 2008-05-27 17:37:39 UTC (rev 620)
@@ -0,0 +1,765 @@
+/*******************************************************************************
+* 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 "vmbuilder-util.h"
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <cmpidt.h>
+#include <cmpift.h>
+#include <cmpimacs.h>
+#include <omc/string.h>
+#include <omc/exec.h>
+#include <omc/base.h>
+#include <omc/ioUtils.h>
+#include <omc/cmpiUtils.h>
+#include <omc/cmpiSimpleAssoc.h>
+
+static const char* owning_job_class_keys[] =
+{
+ "OwningElement",
+ "OwnedElement",
+ NULL
+};
+
+/* If built for debug, enable tracing */
+#ifdef XEN_VMBUILDER_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 CMPIObjectPath*
+get_service_ref(
+ const CMPIContext* context,
+ const char* ns)
+{
+ CMPIStatus lstatus = {CMPI_RC_OK, NULL};
+ CMPIObjectPath* objectpath;
+ CMPIEnumeration *en;
+ CMPIData data;
+
+ objectpath = CMNewObjectPath(_broker, ns, "XEN_VMBuilderService", &lstatus);
+ en = CBEnumInstanceNames(_broker, context, objectpath, &lstatus);
+ if (en == NULL) {
+ return NULL;
+ }
+
+ /* Should only be 1 instance name of service */
+ if (CMHasNext(en, &lstatus)) {
+ data = CMGetNext(en, &lstatus);
+ return data.value.ref;
+ }
+
+ return NULL;
+}
+
+/******************************************************************************
+ 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};
+ CMPIStatus lstatus = {CMPI_RC_OK, NULL};
+ CMPIObjectPath *objectpath, *serviceref, *jobref;
+ char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ char *className;
+ CMPIEnumeration *en;
+ CMPIData data;
+
+ DEBUGOUT("EnumInstanceNames() called\n");
+
+ className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_VMBuilderOwningJobElement") == 0) {
+ objectpath = CMNewObjectPath(_broker, ns, "XEN_VMBuilderOwningJobElement", &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;
+ }
+
+ serviceref = get_service_ref(context, ns);
+ if (!serviceref) {
+ return status;
+ }
+
+ CMAddKey(objectpath, "OwningElement", (CMPIValue*)&serviceref,
+ CMPI_ref);
+
+ /* Get the instance names for all jobs */
+ jobref = CMNewObjectPath(_broker, ns, "XEN_VMBuilderJob", &lstatus);
+ en = CBEnumInstanceNames(_broker, context, jobref, &lstatus);
+ if (en == NULL) {
+ /* No jobs, so no references */
+ return status;
+ }
+
+ while(CMHasNext(en, &lstatus)) {
+ data = CMGetNext(en, &lstatus);
+ if (data.value.ref == NULL) {
+ DEBUGOUT("EnumInstanceNames: CMGetNext returned NULL "
+ "reference\n");
+ } else {
+ CMAddKey(objectpath, "OwnedElement",
+ (CMPIValue*)&data.value.ref, CMPI_ref);
+ 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};
+ CMPIStatus lstatus = {CMPI_RC_OK, NULL};
+ char * ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ CMPIInstance* instance;
+ char *className;
+ CMPIEnumeration *en;
+ CMPIData data;
+
+ DEBUGOUT("EnumInstances() called\n");
+
+ className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_VMBuilderOwningJobElement") == 0) {
+ CMPIObjectPath *jobref, *serviceref;
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderOwningJobElement",
+ owning_job_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
+ DEBUGOUT("EnumInstances(): failed to create new instance: %s\n",
+ CMGetCharPtr(status.msg));
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ "Failed to create new instance");
+ return status;
+ }
+ serviceref = get_service_ref(context, ns);
+ if (!serviceref) {
+ return status;
+ }
+
+ CMSetProperty(instance, "OwningElement",
+ (CMPIValue*)&serviceref, CMPI_ref);
+
+ /* Get the instance names for all jobs */
+ jobref = CMNewObjectPath(_broker, ns, "XEN_VMBuilderJob", &lstatus);
+ en = CBEnumInstanceNames(_broker, context, jobref, &lstatus);
+ if (en == NULL) {
+ /* No jobs, so no references */
+ return status;
+ }
+
+ while(CMHasNext(en, &lstatus)) {
+ data = CMGetNext(en, &lstatus);
+ if (data.value.ref == NULL) {
+ DEBUGOUT("EnumInstances: CMGetNext returned NULL "
+ "reference\n");
+ } else {
+ CMSetProperty(instance, "OwnedElement",
+ (CMPIValue*)&data.value.ref, CMPI_ref);
+ 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, *ci;
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ CMPIStatus lstatus = {CMPI_RC_OK, NULL};
+ char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ const char *className;
+
+ DEBUGOUT("GetInstance() called\n");
+
+ className = CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_VMBuilderOwningJobElement") == 0) {
+ CMPIData job, service;
+ service = CMGetKey(cop, "OwningElement", &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(service)) {
+ DEBUGOUT("GetInstance(): CMGetKey(\"OwningElement\") "
+ "failed - %s\n", CMGetCharPtr(status.msg));
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_NO_SUCH_PROPERTY,
+ "OwningElement missing");
+ return status;
+ }
+ if (service.type != CMPI_ref) {
+ DEBUGOUT("GetInstance(): Invalid 'OwningElement' key "
+ "property type\n");
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER,
+ "OwningElement key invalid");
+ return status;
+ }
+
+ ci = CBGetInstance(_broker, context, service.value.ref, NULL, &lstatus);
+ if (ci == NULL) {
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ "Instance does not exists");
+ return status;
+ }
+
+ job = CMGetKey(cop, "OwnedElement", &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(job)) {
+ DEBUGOUT("GetInstance(): CMGetKey(\"OwnedElement\") "
+ "failed - %s\n", CMGetCharPtr(status.msg));
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_NO_SUCH_PROPERTY,
+ "OwnedElement missing");
+ return status;
+ }
+ if (job.type != CMPI_ref) {
+ DEBUGOUT("GetInstance(): Invalid 'OwnedElement' key "
+ "property type\n");
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER,
+ "OwnedElement key invalid");
+ return status;
+ }
+
+ ci = CBGetInstance(_broker, context, job.value.ref, NULL, &lstatus);
+ if (ci == NULL) {
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ "Instance does not exists");
+ return status;
+ }
+
+ instance = omccmpiNewInstance(_broker, ns,
+ "XEN_VMBuilderOwningJobElement",
+ owning_job_class_keys, properties, &status);
+ CMSetProperty(instance, "OwningElement",
+ (CMPIValue*)&service.value.ref, CMPI_ref);
+ CMSetProperty(instance, "OwnedElement",
+ (CMPIValue*)&job.value.ref, CMPI_ref);
+ 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;
+}
+
+/******************************************************************************
+CMPI ASSOCIATION PROVIDER FUNCTIONS
+******************************************************************************/
+
+/******************************************************************************
+AssocInit() - init
+ params: CMPIAssociationMI* self: [in] Handle to this provider
+******************************************************************************/
+static void
+AssocInit(
+ CMPIAssociationMI* self)
+{
+ DEBUGOUT("AssocInit() called");
+
+ DEBUGOUT("Leaving AssocInit()\n");
+}
+
+/******************************************************************************
+AssociationCleanup() - pre unload
+ params: CMPIAssociationMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIBoolean terminating
+******************************************************************************/
+static CMPIStatus
+AssociationCleanup(
+ CMPIAssociationMI* self,
+ const CMPIContext* context,
+ CMPIBoolean terminating)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+
+ DEBUGOUT("AssociationCleanup() called");
+
+ DEBUGOUT("Leaving AssociationCleanup(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ return status;
+}
+
+/*****************************************************************************/
+static CMPIStatus
+doReferences(
+ omccmpiSimpleAssocCtx ctx,
+ CMPIAssociationMI *self,
+ const CMPIBroker *broker,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *cop,
+ const char *assocClass,
+ const char *resultClass,
+ const char *role,
+ const char *resultRole,
+ const char **properties)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ CMPIStatus lstatus = {CMPI_RC_OK, NULL};
+ char * ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ CMPIObjectPath *objectpath;
+ CMPIInstance *instance, *jobci, *serviceci;
+ CMPIEnumeration *en;
+ CMPIData data;
+
+ DEBUGOUT("doReferences called\n");
+
+ char *objsClassName = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+
+ /* Is target an VM Builder Service object? */
+ if(strcasecmp(objsClassName, "XEN_VMBuilderService") == 0) {
+ if (role && *role && strcasecmp(role, "OwningElement") != 0) {
+ /* Unknown role */
+ return status;
+ }
+ if (resultRole && *resultRole && strcasecmp(resultRole,
+ "OwnedElement") != 0) {
+ /* Unknown resultRole */
+ return status;
+ }
+ if (resultClass && *resultClass) {
+ if (!omccmpiClassIsDerivedFrom("XEN_VMBuilderJob",
+ resultClass, _broker, ns, &status)) {
+ return status;
+ }
+ }
+
+ /* Get the service instance to verify existence */
+ serviceci = CBGetInstance(_broker, context, cop, NULL, &lstatus);
+ if (serviceci == NULL) {
+ /* No hit on service. No references */
+ return status;
+ }
+
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderOwningJobElement",
+ owning_job_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
+ DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
+ CMGetCharPtr(status.msg));
+ return status;
+ }
+ CMSetProperty(instance, "OwningElement", (CMPIValue*)&cop, CMPI_ref);
+
+ /* Get the instance names for all jobs */
+ objectpath = CMNewObjectPath(_broker, ns, "XEN_VMBuilderJob", &lstatus);
+ en = CBEnumInstanceNames(_broker, context, objectpath, &lstatus);
+ if (en == NULL) {
+ /* No jobs, so no references */
+ return status;
+ }
+
+ while(CMHasNext(en, &lstatus)) {
+ data = CMGetNext(en, &lstatus);
+ if (data.value.ref == NULL) {
+ DEBUGOUT("CMGetNext returned NULL reference\n");
+ } else {
+ CMSetProperty(instance, "OwnedElement",
+ (CMPIValue*)&data.value.ref, CMPI_ref);
+ omccmpiSimpleAssocResults(ctx, instance, &status);
+ }
+ }
+ } else if(strcasecmp(objsClassName, "XEN_VMBuilderJob") == 0) {
+ if (role && *role && strcasecmp(role, "OwnedElement") != 0) {
+ /* Unknown role */
+ return status;
+ }
+ if (resultRole && *resultRole && strcasecmp(resultRole,
+ "OwingElement") != 0) {
+ /* Unknown resultRole */
+ return status;
+ }
+ if (resultClass && *resultClass) {
+ if (!omccmpiClassIsDerivedFrom("XEN_VMBuilderService",
+ resultClass, _broker, ns, &status)) {
+ return status;
+ }
+ }
+
+ /* Get the job instance to verify existence */
+ jobci = CBGetInstance(_broker, context, cop, NULL, &lstatus);
+ if (jobci == NULL) {
+ /* No hit on job. No references */
+ return status;
+ }
+
+ instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderOwningJobElement",
+ owning_job_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
+ DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
+ CMGetCharPtr(status.msg));
+ return status;
+ }
+
+ CMSetProperty(instance, "OwnedElement", (CMPIValue*)&cop, CMPI_ref);
+ objectpath = get_service_ref(context, ns);
+ if (objectpath) {
+ CMSetProperty(instance, "OwningElement",
+ (CMPIValue*)&data.value.ref, CMPI_ref);
+ omccmpiSimpleAssocResults(ctx, instance, &status);
+ }
+ } else {
+ DEBUGOUT("!!! Object type unknown: %s\n", objsClassName);
+ return ...
[truncated message content] |
|
From: <jc...@us...> - 2008-05-27 23:58:57
|
Revision: 622
http://omc.svn.sourceforge.net/omc/?rev=622&view=rev
Author: jcarey
Date: 2008-05-27 16:59:04 -0700 (Tue, 27 May 2008)
Log Message:
-----------
Added code to maintain creationdata/job xrefs
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-27 19:40:18 UTC (rev 621)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-27 23:59:04 UTC (rev 622)
@@ -30,6 +30,7 @@
* Author: Jon Carey (jc...@no...)
******************************************************************************/
#include "config.h"
+#include "vmbuilder-util.h"
#include <unistd.h>
#include <stdio.h>
@@ -102,13 +103,6 @@
char inotify[256];
} VMInstallInfo;
-/* If built for debug, enable tracing */
-#ifdef XEN_VMBUILDER_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
@@ -251,36 +245,6 @@
}
/*****************************************************************************/
-static char**
-get_job_names()
-{
- int status;
- char *output = NULL;
- char** names = NULL;
- unsigned int output_size;
- char* const cmd[] = {
- "/usr/bin/vm-install-jobs",
- "-l",
- NULL
- };
-
- if (omcExecuteProcessAndGatherOutputAndError(cmd, NULL, &output,
- &output_size, -1, NULL, NULL, -1, NULL, &status, -1) == 0) {
- //DEBUGOUT("vm-install-jobs returned %d - %s\n", status, output);
- if(omcStrTrim(output)) {
- unsigned int num_elements;
- names = omcStrTokenize(output, "\r\n", &num_elements);
- }
- } else {
- DEBUGOUT("exec & gather errno: %d-%s\n", errno, strerror(errno));
- }
- if (output) {
- free(output);
- }
- return names;
-}
-
-/*****************************************************************************/
static CMPIInstance*
_getJobInstance(const char* job_name_key, const char* ns,
const char** properties, CMPIStatus* pstatus)
@@ -762,6 +726,9 @@
{
DEBUGOUT("Initialize() called\n");
+ DEBUGOUT("Deleting job xref recs that no longer exist\n");
+ db_delete_dead_job_recs();
+
DEBUGOUT("Leaving Initialize()\n");
}
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-27 19:40:18 UTC (rev 621)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-27 23:59:04 UTC (rev 622)
@@ -105,13 +105,6 @@
#define RPM_NAME "omc-xenvm-builder"
-/* If built for debug, enable tracing */
-#ifdef XEN_VMBUILDER_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
@@ -841,6 +834,8 @@
jobref = CMNewObjectPath(_broker, ns, "XEN_VMBUilderJob", pstatus);
CMAddKey(jobref, "Name", (CMPIValue*)output, CMPI_chars);
prv->uint32 = 0;
+ /* Create createdata/job xref record */
+ db_add_job_to_creation_data(iid, output);
} else {
prv->uint32 = (CMPIUint32)WEXITSTATUS(cc);
DEBUGOUT("vm-install failed status: %u\n", prv->uint32);
@@ -877,7 +872,7 @@
int fail_count = 0;
DEBUGOUT("Entering GetInstance loop for Job instance...\n");
while(fail_count < 10) {
- omcMilliSleep(500);
+ omcMilliSleep(1000);
jobci = CBGetInstance(_broker, context, jobref, NULL,
&lstatus);
if (jobci == NULL) {
@@ -947,6 +942,7 @@
const char *vmname = NULL;
const char *uuid = NULL;
+ db_delete_dead_job_recs();
param = CMGetArg(in, "VMName", &status);
if (!CMIsNullValue(param)) {
vmname = CMGetCharPtr(param.value.string);
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c 2008-05-27 19:40:18 UTC (rev 621)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c 2008-05-27 23:59:04 UTC (rev 622)
@@ -57,13 +57,6 @@
NULL
};
-/* If built for debug, enable tracing */
-#ifdef XEN_VMBUILDER_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
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-27 19:40:18 UTC (rev 621)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-27 23:59:04 UTC (rev 622)
@@ -1,4 +1,4 @@
-#include "vmbuilder-db.h"
+#include "vmbuilder-util.h"
#include <sqlite3.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -89,7 +89,8 @@
"CREATE TABLE Job("
"JobName TEXT NOT NULL,"
"CreationDataInstanceID TEXT NOT NULL COLLATE NOCASE,"
- "PRIMARY KEY(JobName, CreationDataInstanceID COLLATE NOCASE));";
+ "PRIMARY KEY(JobName, CreationDataInstanceID COLLATE NOCASE));"
+"CREATE INDEX JobCDNdx ON Job(CreationDataInstanceID);";
typedef struct
{
@@ -482,6 +483,96 @@
sqlite3_close(db);
return insert_row_id;
}
+
+/*
+ * Delete all job/creationdata xref records for jobs
+ * that no longer exist.
+ */
+int
+db_delete_dead_job_recs()
+{
+ char** job_names = NULL;
+ omcStrBuf* pstrbuf = NULL;
+ int i, cc = 0;
+ char err_msg[256];
+
+ job_names = get_job_names();
+ if (!job_names) {
+ return 0;
+ }
+
+ pstrbuf = omcStrBuf_create();
+ if (!pstrbuf) {
+ free(job_names);
+ return -1;
+ }
+
+ omcStrBuf_cat(pstrbuf, "DELETE FROM Job WHERE JobName NOT IN (", 0);
+
+ for (i = 0; job_names[i]; i++) {
+ if (!i) {
+ db_sql_insert(pstrbuf, "%Q", job_names[i]);
+ } else {
+ db_sql_insert(pstrbuf, ",%Q", job_names[i]);
+ }
+ }
+ free(job_names);
+ omcStrBuf_cat(pstrbuf, ");", 0);
+ if (db_exec(pstrbuf->bfr, err_msg, sizeof(err_msg)) == -1LL) {
+ DEBUGOUT("Error: delete dead job recs: %s\n", err_msg);
+ cc = -1;
+ }
+ omcStrBuf_destroy(pstrbuf);
+ return cc;
+}
+
+int
+db_delete_creation_data_job_recs(const char* cdid)
+{
+ int cc = 0;
+ char err_msg[256];
+
+ char* sql = db_create_formatted_sql(
+ "DELETE FROM Job WHERE CreationDataInstanceID=%Q;", cdid);
+ if (!sql) {
+ return -1;
+ }
+
+ if (db_exec(sql, err_msg, sizeof(err_msg)) == -1LL) {
+ DEBUGOUT("Error: delete job for creationdata: %s\n", err_msg);
+ cc = -1;
+ }
+ db_destroy_formatted_sql(sql);
+ return cc;
+}
+
+int
+db_add_job_to_creation_data(const char* cdid, const char* job_name)
+{
+ int cc = 0;
+ char err_msg[256];
+
+ char* sql = db_create_formatted_sql(
+ "INSERT INTO Job VALUES(%Q,%Q);", job_name, cdid);
+ if (!sql) {
+ return -1;
+ }
+
+ if (db_exec(sql, err_msg, sizeof(err_msg)) == -1LL) {
+ DEBUGOUT("Error: creating job xref rec for creationdata: %s\n",
+ err_msg);
+ cc = -1;
+ }
+ db_destroy_formatted_sql(sql);
+ return cc;
+}
+
+
+
+
+
+
+
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-05-27 19:40:18 UTC (rev 621)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-05-27 23:59:04 UTC (rev 622)
@@ -25,5 +25,8 @@
char* db_create_formatted_sql(const char* format, ...);
void db_destroy_formatted_sql(char* formatted_sql);
char* db_sql_insert(omcStrBuf* pstrbuf, const char* format, ...);
+int db_delete_dead_job_recs();
+int db_add_job_to_creation_data(const char* cdid, const char* job_name);
+int db_delete_creation_data_job_recs(const char* cdid);
#endif // VMBGUILDER_DB_H_GUARD_
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c 2008-05-27 19:40:18 UTC (rev 621)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c 2008-05-27 23:59:04 UTC (rev 622)
@@ -1,9 +1,12 @@
#include "vmbuilder-util.h"
+
#include <stdio.h>
+#include <errno.h>
#include <cmpidt.h>
#include <cmpift.h>
#include <cmpimacs.h>
#include <omc/string.h>
+#include <omc/exec.h>
/******************************************************************************/
CMPIArray*
@@ -220,4 +223,33 @@
}
}
+/*****************************************************************************/
+char**
+get_job_names()
+{
+ int status;
+ char *output = NULL;
+ char** names = NULL;
+ unsigned int output_size;
+ char* const cmd[] = {
+ "/usr/bin/vm-install-jobs",
+ "-l",
+ NULL
+ };
+ if (omcExecuteProcessAndGatherOutputAndError(cmd, NULL, &output,
+ &output_size, -1, NULL, NULL, -1, NULL, &status, -1) == 0) {
+ if(omcStrTrim(output)) {
+ unsigned int num_elements;
+ names = omcStrTokenize(output, "\r\n", &num_elements);
+ }
+ } else {
+ DEBUGOUT("exec & gather errno: %d-%s\n", errno, strerror(errno));
+ }
+ if (output) {
+ free(output);
+ }
+ return names;
+}
+
+
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h 2008-05-27 19:40:18 UTC (rev 621)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h 2008-05-27 23:59:04 UTC (rev 622)
@@ -1,10 +1,12 @@
#ifndef VMBUILDER_UTIL_H_GUARD
#define VMBUILDER_UTIL_H_GUARD
+#include "config.h"
#include "vmbuilder-db.h"
#include <cmpidt.h>
#include <cmpift.h>
#include <cmpimacs.h>
+#include <stdio.h>
CMPIArray* str2UInt16Array(const CMPIBroker* broker, const char* str);
CMPIArray* str2StringArray(const CMPIBroker* broker, const char* str);
@@ -21,5 +23,13 @@
const char* prop_name);
void set_dt_prop(const CMPIBroker* broker, VMBDBCtx dbctx, int col_ndx,
CMPIInstance* instance, const char* prop_name, CMPIBoolean isInterval);
+char** get_job_names();
+/* If built for debug, enable tracing */
+#ifdef XEN_VMBUILDER_DEBUG
+#define DEBUGOUT(fmt, args...) printf(fmt,## args)
+#else
+#define DEBUGOUT(fmt, args...)
+#endif
+
#endif /* VMBUILDER_UTIL_H_GUARD */
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-27 19:40:18 UTC (rev 621)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-27 23:59:04 UTC (rev 622)
@@ -60,13 +60,6 @@
NULL
};
-/* If built for debug, enable tracing */
-#ifdef XEN_VMBUILDER_DEBUG
-#define DEBUGOUT(fmt, args...) printf(fmt,## args)
-#else
-#define DEBUGOUT(fmt, args...)
-#endif
-
#define CSV_FIELDS \
"InstanceID," \
"AutoMaticRecoveryAction," \
@@ -1198,6 +1191,8 @@
DEBUGOUT("DeleteInstance(): failed deleting record from "
"database: %s", err_msg);
OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
+ } else {
+ db_delete_creation_data_job_recs(iid);
}
db_destroy_formatted_sql(query);
}
@@ -1238,6 +1233,9 @@
{
DEBUGOUT("Initialize() called\n");
+ /* Delete jobs xref recs for jobs that no longer exist */
+ db_delete_dead_job_recs();
+
DEBUGOUT("Leaving Initialize()\n");
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jc...@us...> - 2008-05-28 22:30:07
|
Revision: 624
http://omc.svn.sourceforge.net/omc/?rev=624&view=rev
Author: jcarey
Date: 2008-05-28 15:30:03 -0700 (Wed, 28 May 2008)
Log Message:
-----------
Bug fixes and implementation of the settingsdefinebuild association
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c
Added Paths:
-----------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/setting-define-build.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-05-28 17:46:24 UTC (rev 623)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-05-28 22:30:03 UTC (rev 624)
@@ -4,7 +4,8 @@
libomc_xenvmbuilder.la \
libomc_xenvmbuilderjob.la \
libomc_xencreationdata.la \
- libomc_xenowningjob.la
+ libomc_xenowningjob.la \
+ libomc_xensettingsdefinebuild.la
lib_LTLIBRARIES = \
libomc_xenvmbuilder_common.la
@@ -12,6 +13,20 @@
INCLUDES = -I$(top_builddir)
###
+# libomc_xenvmbuilder_common
+###
+libomc_xenvmbuilder_common_la_SOURCES = \
+ vmbuilder-util.c \
+ vmbuilder-db.c \
+ vmbuilder-db.h
+
+libomc_xenvmbuilder_common_la_LDFLAGS = \
+ -lpthread \
+ -lomc_cmpi \
+ -lsqlite3 \
+ -version-info 1
+
+###
# libomc_xenvmbuilder
###
libomc_xenvmbuilder_la_SOURCES = \
@@ -68,19 +83,16 @@
$(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
###
-# libomc_xenvmbuilder_common
+# libomc_xensettingsdefinebuild
###
-libomc_xenvmbuilder_common_la_SOURCES = \
- vmbuilder-util.c \
- vmbuilder-db.c \
- vmbuilder-db.h
+libomc_xensettingsdefinebuild_la_SOURCES = \
+ setting-define-build.c
-libomc_xenvmbuilder_common_la_LDFLAGS = \
+libomc_xensettingsdefinebuild_la_LDFLAGS = \
-lpthread \
-lomc_cmpi \
- -lsqlite3 \
-version-info 1
+libomc_xensettingsdefinebuild_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
-
-
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-28 17:46:24 UTC (rev 623)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-28 22:30:03 UTC (rev 624)
@@ -317,7 +317,7 @@
DEBUGOUT("EnumInstanceNames() called class:%s\n", className);
if (strcasecmp(className, "XEN_VMBuilderJob") == 0) {
CMPIObjectPath* ref = CMNewObjectPath(_broker, ns,
- "XEN_VMBUilderJob", &status);
+ "XEN_VMBuilderJob", &status);
if (status.rc != CMPI_RC_OK || CMIsNullObject(ref)) {
DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() "
"failed - %s\n", CMGetCharPtr(status.msg));
@@ -346,7 +346,7 @@
return status;
}
CMPIObjectPath* jobref = CMNewObjectPath(_broker, ns,
- "XEN_VMBUilderJob", &status);
+ "XEN_VMBuilderJob", &status);
if (status.rc != CMPI_RC_OK || CMIsNullObject(jobref)) {
DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() "
"failed creating job ref - %s\n",
@@ -432,7 +432,7 @@
return status;
}
CMPIObjectPath* jobref = CMNewObjectPath(_broker, ns,
- "XEN_VMBUilderJob", &status);
+ "XEN_VMBuilderJob", &status);
if (status.rc != CMPI_RC_OK || CMIsNullObject(jobref)) {
DEBUGOUT("EnumInstances(): CMNewObjectPath() "
"failed creating job ref - %s\n",
@@ -727,7 +727,7 @@
DEBUGOUT("Initialize() called\n");
DEBUGOUT("Deleting job xref recs that no longer exist\n");
- db_delete_dead_job_recs();
+ db_delete_dead_job_recs(NULL);
DEBUGOUT("Leaving Initialize()\n");
}
@@ -991,7 +991,7 @@
if(get_job_info(names[i], &info) == 0) {
if (info.pid == pid) {
jobref = CMNewObjectPath(_broker, ns,
- "XEN_VMBUilderJob", &status);
+ "XEN_VMBuilderJob", &status);
if (status.rc != CMPI_RC_OK || CMIsNullObject(jobref)) {
DEBUGOUT("doReferences(): CMNewObjectPath() "
"failed - %d\n", status.rc);
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-28 17:46:24 UTC (rev 623)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-28 22:30:03 UTC (rev 624)
@@ -830,12 +830,13 @@
NULL, &cc, -1) == 0) {
DEBUGOUT("vm-install returned 0\n");
if (cc == 0 && output) {
+ const char* job_name = omcStrTrim(output); /* remove \n */
DEBUGOUT("vm-install status is 0\n");
jobref = CMNewObjectPath(_broker, ns, "XEN_VMBUilderJob", pstatus);
- CMAddKey(jobref, "Name", (CMPIValue*)output, CMPI_chars);
+ CMAddKey(jobref, "Name", (CMPIValue*)job_name, CMPI_chars);
prv->uint32 = 0;
/* Create createdata/job xref record */
- db_add_job_to_creation_data(iid, output);
+ db_add_job_to_creation_data(iid, job_name);
} else {
prv->uint32 = (CMPIUint32)WEXITSTATUS(cc);
DEBUGOUT("vm-install failed status: %u\n", prv->uint32);
@@ -884,8 +885,7 @@
data = CMGetProperty(jobci, "JobStatus", NULL);
if (!CMIsNullValue(data)) {
const char *p = CMGetCharPtr(data.value.string);
- if (strcasecmp(p, "SETTINGS")
- && strcasecmp(p, "PREP_INSTALL")) {
+ if (strcasecmp(p, "SETTINGS") == 0) {
DEBUGOUT("Still to soon to delete Response file\n");
continue;
}
@@ -942,7 +942,7 @@
const char *vmname = NULL;
const char *uuid = NULL;
- db_delete_dead_job_recs();
+ db_delete_dead_job_recs(NULL);
param = CMGetArg(in, "VMName", &status);
if (!CMIsNullValue(param)) {
vmname = CMGetCharPtr(param.value.string);
@@ -1175,9 +1175,6 @@
}
CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, CMPI_ref);
omccmpiSimpleAssocResults(ctx, instance, &status);
- } else {
- DEBUGOUT("!!! Object type unknown: %s\n", objsClassName);
- return status;
}
DEBUGOUT("Leaving doReferences\n");
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c 2008-05-28 17:46:24 UTC (rev 623)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c 2008-05-28 22:30:03 UTC (rev 624)
@@ -416,6 +416,8 @@
{
DEBUGOUT("Initialize() called\n");
+ db_delete_dead_job_recs(NULL);
+
DEBUGOUT("Leaving Initialize()\n");
}
@@ -591,12 +593,9 @@
objectpath = get_service_ref(context, ns);
if (objectpath) {
CMSetProperty(instance, "OwningElement",
- (CMPIValue*)&data.value.ref, CMPI_ref);
+ (CMPIValue*)&objectpath, CMPI_ref);
omccmpiSimpleAssocResults(ctx, instance, &status);
}
- } else {
- DEBUGOUT("!!! Object type unknown: %s\n", objsClassName);
- return status;
}
DEBUGOUT("Leaving doReferences\n");
Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/setting-define-build.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/setting-define-build.c (rev 0)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/setting-define-build.c 2008-05-28 22:30:03 UTC (rev 624)
@@ -0,0 +1,803 @@
+/*******************************************************************************
+* 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 "vmbuilder-util.h"
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <cmpidt.h>
+#include <cmpift.h>
+#include <cmpimacs.h>
+#include <omc/string.h>
+#include <omc/exec.h>
+#include <omc/base.h>
+#include <omc/ioUtils.h>
+#include <omc/cmpiUtils.h>
+#include <omc/cmpiSimpleAssoc.h>
+
+static const char* the_class_keys[] =
+{
+ "ManagedElement",
+ "SettingData",
+ NULL
+};
+
+/*
+ * Global handle to the CIM broker
+ * This is initialized by the CIMOM when the provider is loaded
+ */
+static const CMPIBroker* _broker;
+
+/******************************************************************************
+ 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};
+ CMPIStatus lstatus = {CMPI_RC_OK, NULL};
+ CMPIObjectPath *objectpath, *wkref;
+ char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ char *className, err_msg[256];
+ VMBDBCtx dbctx;
+ int cc;
+
+ DEBUGOUT("EnumInstanceNames() called\n");
+
+ className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_SettingsDefineBuild") == 0) {
+ objectpath = CMNewObjectPath(_broker, ns, "XEN_SettingsDefineBuild", &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;
+ }
+
+ db_delete_dead_job_recs(NULL);
+ cc = db_create_select_results(&dbctx,
+ "SELECT JobName,CreationDataInstanceID FROM Job",
+ err_msg, sizeof(err_msg));
+ if (cc != 0) {
+ DEBUGOUT("EnumInstanceNames(): Failed to connect to "
+ "database: %s\n", err_msg);
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
+ return status;
+ }
+
+ while (db_results_have_more_rows(dbctx)) {
+ const unsigned char* job_name = db_get_results_column_text(dbctx, 0, NULL);
+ const unsigned char* cdid = db_get_results_column_text(dbctx, 1, NULL);
+ if (job_name && cdid) {
+ wkref = CMNewObjectPath(_broker, ns,
+ "XEN_VMBuilderVirtualSystemCreationData",
+ &lstatus);
+ CMAddKey(wkref, "InstanceID", (CMPIValue*)cdid, CMPI_chars);
+ CMAddKey(objectpath, "SettingData", (CMPIValue*)&wkref, CMPI_ref);
+ wkref = CMNewObjectPath(_broker, ns, "XEN_VMBuilderJob",
+ &lstatus);
+ CMAddKey(wkref, "Name", (CMPIValue*)job_name, CMPI_chars);
+ CMAddKey(objectpath, "ManagedElement", (CMPIValue*)&wkref, CMPI_ref);
+ CMReturnObjectPath(results, objectpath);
+ }
+ db_results_next_row(dbctx);
+ }
+ db_destroy_select_results(dbctx);
+ 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};
+ CMPIStatus lstatus = {CMPI_RC_OK, NULL};
+ char * ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ CMPIInstance* instance;
+ CMPIObjectPath *wkref;
+ char *className, err_msg[256];
+ VMBDBCtx dbctx;
+ int cc;
+
+ DEBUGOUT("EnumInstances() called\n");
+
+ className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_SettingsDefineBuild") == 0) {
+ instance = omccmpiNewInstance(_broker, ns, "XEN_SettingsDefineBuild",
+ the_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
+ DEBUGOUT("EnumInstances(): failed to create new instance: %s\n",
+ CMGetCharPtr(status.msg));
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ "Failed to create new instance");
+ return status;
+ }
+
+ db_delete_dead_job_recs(NULL);
+ cc = db_create_select_results(&dbctx,
+ "SELECT JobName,CreationDataInstanceID FROM Job",
+ err_msg, sizeof(err_msg));
+ if (cc != 0) {
+ DEBUGOUT("EnumInstances(): Failed to connect to "
+ "database: %s\n", err_msg);
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
+ return status;
+ }
+
+ while (db_results_have_more_rows(dbctx)) {
+ const unsigned char* job_name = db_get_results_column_text(dbctx, 0, NULL);
+ const unsigned char* cdid = db_get_results_column_text(dbctx, 1, NULL);
+ if (job_name && cdid) {
+ wkref = CMNewObjectPath(_broker, ns,
+ "XEN_VMBuilderVirtualSystemCreationData",
+ &lstatus);
+ CMAddKey(wkref, "InstanceID", (CMPIValue*)cdid, CMPI_chars);
+ CMSetProperty(instance, "SettingData",
+ (CMPIValue*)&wkref, CMPI_ref);
+ wkref = CMNewObjectPath(_broker, ns, "XEN_VMBuilderJob",
+ &lstatus);
+ CMAddKey(wkref, "Name", (CMPIValue*)job_name, CMPI_chars);
+ CMSetProperty(instance, "ManagedElement",
+ (CMPIValue*)&wkref, CMPI_ref);
+ CMReturnInstance(results, instance);
+ }
+ db_results_next_row(dbctx);
+ }
+ db_destroy_select_results(dbctx);
+ 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));
+ char *sql, err_msg[256];
+ const char *className;
+ VMBDBCtx dbctx;
+ int cc;
+
+ DEBUGOUT("GetInstance() called\n");
+
+ className = CMGetCharPtr(CMGetClassName(cop, NULL));
+ if (strcasecmp(className, "XEN_SettingsDefineBuild") == 0) {
+ CMPIData key;
+ CMPIData jobrefdata, cdrefdata;
+ const char *job_name_key, *cdiid;
+
+ /* Get the Job reference for the given REF */
+
+ jobrefdata = CMGetKey(cop, "ManagedElement", &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(jobrefdata)) {
+ DEBUGOUT("GetInstance(): CMGetKey(\"ManagedElement\") "
+ "failed - %s\n", CMGetCharPtr(status.msg));
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_NO_SUCH_PROPERTY,
+ "ManagedElement missing");
+ return status;
+ }
+ if (jobrefdata.type != CMPI_ref) {
+ DEBUGOUT("GetInstance(): Invalid 'ManagedElement' key "
+ "property type\n");
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER,
+ "ManagedElement key invalid");
+ return status;
+ }
+
+ key = CMGetKey(jobrefdata.value.ref, "Name", &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) {
+ DEBUGOUT("GetInstance. 'Name' prop missing from ManagedElement REF\n");
+ CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
+ return status;
+ }
+
+ job_name_key = CMGetCharPtr(key.value.string);
+ if (!job_name_key || !strlen(job_name_key)) {
+ DEBUGOUT("GetInstance. Empty 'Name' prop on ManagedElement REF\n");
+ CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
+ return status;
+ }
+
+ /* Get the CreationData reference for the given REF */
+
+ cdrefdata = CMGetKey(cop, "SettingData", &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(cdrefdata)) {
+ DEBUGOUT("GetInstance(): CMGetKey(\"SettingData\") "
+ "failed - %s\n", CMGetCharPtr(status.msg));
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_NO_SUCH_PROPERTY,
+ "SettingData missing");
+ return status;
+ }
+ if (cdrefdata.type != CMPI_ref) {
+ DEBUGOUT("GetInstance(): Invalid 'SettingData' key "
+ "property type\n");
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER,
+ "SettingData key invalid");
+ return status;
+ }
+
+ key = CMGetKey(cdrefdata.value.ref, "InstanceID", &status);
+ if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) {
+ DEBUGOUT("GetInstance. 'InstanceID' prop missing from SettingData REF\n");
+ CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
+ return status;
+ }
+
+ cdiid = CMGetCharPtr(key.value.string);
+ if (!cdiid || !strlen(cdiid)) {
+ DEBUGOUT("GetInstance. Empty 'InstanceID' prop on SettingData REF\n");
+ CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
+ return status;
+ }
+
+ sql = db_create_formatted_sql("SELECT CreationDataInstanceID FROM "
+ "Job WHERE JobName=%Q AND CreationDataInstanceID=%Q;",
+ job_name_key, cdiid);
+
+ cc = db_create_select_results(&dbctx, sql, err_msg, sizeof(err_msg));
+ db_destroy_formatted_sql(sql);
+ if (cc != 0) {
+ DEBUGOUT("GetInstance(): Failed to connect to database: %s\n",
+ err_msg);
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
+ return status;
+ }
+
+ if (db_results_have_more_rows(dbctx)) {
+ instance = omccmpiNewInstance(_broker, ns,
+ "XEN_SettingsDefineBuild",
+ the_class_keys, properties, &status);
+ CMSetProperty(instance, "ManagedElement",
+ (CMPIValue*)&jobrefdata.value.ref, CMPI_ref);
+ CMSetProperty(instance, "SettingData",
+ (CMPIValue*)&cdrefdata.value.ref, CMPI_ref);
+ CMReturnInstance(results, instance);
+ } else {
+ DEBUGOUT("GetInstance(): Not found. Job: %s CreationData: %s\n",
+ job_name_key, cdiid);
+ CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
+ }
+ db_destroy_select_results(dbctx);
+ }
+ 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");
+
+ db_delete_dead_job_recs(NULL);
+
+ 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;
+}
+
+/******************************************************************************
+CMPI ASSOCIATION PROVIDER FUNCTIONS
+******************************************************************************/
+
+/******************************************************************************
+AssocInit() - init
+ params: CMPIAssociationMI* self: [in] Handle to this provider
+******************************************************************************/
+static void
+AssocInit(
+ CMPIAssociationMI* self)
+{
+ DEBUGOUT("AssocInit() called");
+
+ DEBUGOUT("Leaving AssocInit()\n");
+}
+
+/******************************************************************************
+AssociationCleanup() - pre unload
+ params: CMPIAssociationMI* self: [in] Handle to this provider
+ CMPIContext* context: [in] any additional context info
+ CMPIBoolean terminating
+******************************************************************************/
+static CMPIStatus
+AssociationCleanup(
+ CMPIAssociationMI* self,
+ const CMPIContext* context,
+ CMPIBoolean terminating)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+
+ DEBUGOUT("AssociationCleanup() called");
+
+ DEBUGOUT("Leaving AssociationCleanup(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ return status;
+}
+
+/*****************************************************************************/
+static CMPIStatus
+doReferences(
+ omccmpiSimpleAssocCtx ctx,
+ CMPIAssociationMI *self,
+ const CMPIBroker *broker,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *cop,
+ const char *assocClass,
+ const char *resultClass,
+ const char *role,
+ const char *resultRole,
+ const char **properties)
+{
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ CMPIStatus lstatus = {CMPI_RC_OK, NULL};
+ char * ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ CMPIObjectPath *objectpath;
+ CMPIInstance *instance;
+ VMBDBCtx dbctx;
+ char err_msg[256];
+
+ CMPIData key;
+ char* sql;
+ const char* job_name_key;
+ const char* iid;
+ int cc;
+
+ DEBUGOUT("doReferences called\n");
+
+ char *objsClassName = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
+
+ /* Is target an VM Builder Job object? */
+ if(strcasecmp(objsClassName, "XEN_VMBuilderJob") == 0) {
+ if (role && *role && strcasecmp(role, "ManagedElement") != 0) {
+ /* Unknown role */
+ return status;
+ }
+ if (resultRole && *resultRole && strcasecmp(resultRole,
+ "SettingData") != 0) {
+ /* Unknown resultRole */
+ return status;
+ }
+ if (resultClass && *resultClass) {
+ if (!omccmpiClassIsDerivedFrom("XEN_VMBuilderVirtualSystemCreationData",
+ resultClass, _broker, ns, &status)) {
+ return status;
+ }
+ }
+
+ key = CMGetKey(cop, "Name", &lstatus);
+ if (lstatus.rc != CMPI_RC_OK || CMIsNullValue(key)) {
+ return status;
+ }
+ job_name_key = CMGetCharPtr(key.value.string);
+ if (!job_name_key || !strlen(job_name_key)) {
+ return status;
+ }
+
+ instance = omccmpiNewInstance(_broker, ns, "XEN_SettingsDefineBuild",
+ the_class_keys, properties, &status);
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
+ DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
+ CMGetCharPtr(status.msg));
+ return status;
+ }
+ CMSetProperty(instance, "ManagedElement", (CMPIValue*)&cop, CMPI_ref);
+
+ sql = db_create_formatted_sql("SELECT CreationDataInstanceID FROM "
+ "Job WHERE JobName=%Q;", job_name_key);
+ cc = db_create_select_results(&dbctx, sql, err_msg, sizeof(err_msg));
+ db_destroy_formatted_sql(sql);
+ if (cc != 0) {
+ DEBUGOUT("doReferences(): Failed to connect to database: %s\n",
+ err_msg);
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg);
+ return status;
+ }
+
+ if (db_results_have_more_rows(dbctx)) {
+ const unsigned char* txt = db_get_results_column_text(dbctx, 0, NULL);
+ if (txt) {
+ objectpath = CMNewObjectPath(_broker, ns,
+ "XEN_VMBuilderVirtualSystemCreationData",
+ &lstatus);
+ CMAddKey(objectpath, "InstanceID", (CMPIValue*)txt, CMPI_chars);
+ CMSetProperty(instance, "SettingData",
+ (CMPIValue*)&objectpath, CMPI_ref);
+ omccmpiSimpleAssocResults(ctx, instance, &status);
+ }
+ }
+ db_destroy_select_results(dbctx);
+
+ } else if(strcasecmp(objsClassName,
+ "XEN_VMBuilderVirtualSystemCreationData") == 0) {
+ if (role && *role && strcasecmp(role, "SettingData") != 0) {
+ /* Unknown role */
+ return status;
+ }
+ if (resultRole && *resultRole && strcasecmp(resultRole,
+ "ManagedElement") != 0) {
+ /* Unknown resultRole */
+ return status;
+ }
+ if (resultClass && *resultClass) {
+ if (!omccmpiClassIsDerivedFrom("XEN_VMBuilderJob",
+ resultClass, _broker, ns, &status)) {
+ return status;
+ }
+ }
+
+ key = CMGetKey(cop, "InstanceID", &lstatus);
+ if (lstatus.rc != CMPI_RC_OK || CMIsNullValue(key)) {
+ return status;
+ }
+ iid = CMGetCharPtr(key.value.string);
+ if (!iid || !strlen(iid)) {
+ return status;
+ }
+
+ instance = omccmpiNewInstance(_broker, ns, "XEN_SettingsDefineBuild",
+ the_class_keys, properties, &status);
+ i...
[truncated message content] |
|
From: <jc...@us...> - 2008-05-30 17:31:26
|
Revision: 629
http://omc.svn.sourceforge.net/omc/?rev=629&view=rev
Author: jcarey
Date: 2008-05-30 10:31:13 -0700 (Fri, 30 May 2008)
Log Message:
-----------
Moving over to sblim...
Modified Paths:
--------------
contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/owning-job.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/setting-define-build.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.c
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-util.h
contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.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-05-29 18:31:09 UTC (rev 628)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-05-30 17:31:13 UTC (rev 629)
@@ -1,98 +1,98 @@
include $(top_srcdir)/Makefile.incl.am
provider_LTLIBRARIES = \
- libomc_xenvmbuilder.la \
- libomc_xenvmbuilderjob.la \
- libomc_xencreationdata.la \
- libomc_xenowningjob.la \
- libomc_xensettingsdefinebuild.la
+ libsblim_xenvmbuilder.la \
+ libsblim_xenvmbuilderjob.la \
+ libsblim_xencreationdata.la \
+ libsblim_xenowningjob.la \
+ libsblim_xensettingsdefinebuild.la
lib_LTLIBRARIES = \
- libomc_xenvmbuilder_common.la
+ libsblim_xenvmbuilder_common.la
INCLUDES = -I$(top_builddir)
###
-# libomc_xenvmbuilder_common
+# libsblim_xenvmbuilder_common
###
-libomc_xenvmbuilder_common_la_SOURCES = \
+libsblim_xenvmbuilder_common_la_SOURCES = \
vmbuilder-util.c \
vmbuilder-db.c \
vmbuilder-db.h
-libomc_xenvmbuilder_common_la_LDFLAGS = \
+libsblim_xenvmbuilder_common_la_LDFLAGS = \
-lpthread \
- -lomc_cmpi \
+ -lsblim_cmpiutil \
-lsqlite3 \
-version-info 1
###
-# libomc_xenvmbuilder
+# libsblim_xenvmbuilder
###
-libomc_xenvmbuilder_la_SOURCES = \
+libsblim_xenvmbuilder_la_SOURCES = \
builder-service.c
-libomc_xenvmbuilder_la_LDFLAGS = \
+libsblim_xenvmbuilder_la_LDFLAGS = \
-lpthread \
- -lomc_cmpi \
+ -lsblim_cmpiutil \
-version-info 1
-libomc_xenvmbuilder_la_LIBADD = \
- $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+libsblim_xenvmbuilder_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libsblim_xenvmbuilder_common.la
###
-# libomc_xenvmbuilderjob
+# libsblim_xenvmbuilderjob
###
-libomc_xenvmbuilderjob_la_SOURCES = \
+libsblim_xenvmbuilderjob_la_SOURCES = \
builder-job.c
-libomc_xenvmbuilderjob_la_LDFLAGS = \
+libsblim_xenvmbuilderjob_la_LDFLAGS = \
-lpthread \
- -lomc_cmpi \
+ -lsblim_cmpiutil \
-version-info 1
-libomc_xenvmbuilderjob_la_LIBADD = \
- $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+libsblim_xenvmbuilderjob_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libsblim_xenvmbuilder_common.la
###
-# libomc_xencreationdata
+# libsblim_xencreationdata
###
-libomc_xencreationdata_la_SOURCES = \
+libsblim_xencreationdata_la_SOURCES = \
vmcreation-data.c
-libomc_xencreationdata_la_LDFLAGS = \
+libsblim_xencreationdata_la_LDFLAGS = \
-lpthread \
- -lomc_cmpi \
+ -lsblim_cmpiutil \
-version-info 1
-libomc_xencreationdata_la_LIBADD = \
- $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+libsblim_xencreationdata_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libsblim_xenvmbuilder_common.la
###
-# libomc_xenowningjob
+# libsblim_xenowningjob
###
-libomc_xenowningjob_la_SOURCES = \
+libsblim_xenowningjob_la_SOURCES = \
owning-job.c
-libomc_xenowningjob_la_LDFLAGS = \
+libsblim_xenowningjob_la_LDFLAGS = \
-lpthread \
- -lomc_cmpi \
+ -lsblim_cmpiutil \
-version-info 1
-libomc_xenowningjob_la_LIBADD = \
- $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+libsblim_xenowningjob_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libsblim_xenvmbuilder_common.la
###
-# libomc_xensettingsdefinebuild
+# libsblim_xensettingsdefinebuild
###
-libomc_xensettingsdefinebuild_la_SOURCES = \
+libsblim_xensettingsdefinebuild_la_SOURCES = \
setting-define-build.c
-libomc_xensettingsdefinebuild_la_LDFLAGS = \
+libsblim_xensettingsdefinebuild_la_LDFLAGS = \
-lpthread \
- -lomc_cmpi \
+ -lsblim_cmpiutil \
-version-info 1
-libomc_xensettingsdefinebuild_la_LIBADD = \
- $(top_builddir)/src/providers/vm-builder/libomc_xenvmbuilder_common.la
+libsblim_xensettingsdefinebuild_la_LIBADD = \
+ $(top_builddir)/src/providers/vm-builder/libsblim_xenvmbuilder_common.la
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-29 18:31:09 UTC (rev 628)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-05-30 17:31:13 UTC (rev 629)
@@ -45,12 +45,12 @@
#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>
+#include <cmpiutil/linuxProcUtils.h>
+#include <cmpiutil/string.h>
+#include <cmpiutil/exec.h>
+#include <cmpiutil/base.h>
+#include <cmpiutil/cmpiUtils.h>
+#include <cmpiutil/cmpiSimpleAssoc.h>
/* NULL terminated list of key property names for this class */
@@ -117,21 +117,21 @@
char wkbfr[128];
char hname[256];
- ref = CMNewObjectPath(_broker, ns, "OMC_UnixProcess",
+ ref = CMNewObjectPath(_broker, ns, "Linux_UnixProcess",
pstatus);
if (pstatus->rc != CMPI_RC_OK || CMIsNullObject(ref)) {
- OMC_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM,
"Failed creating new object path for process");
return NULL;
}
- if (!omcGetComputerSystemName(hname, sizeof(hname))) {
- omcStrNCpy(hname, "localhost", sizeof(hname));
+ if (!cmpiutilGetComputerSystemName(hname, sizeof(hname))) {
+ cmpiutilStrNCpy(hname, "localhost", sizeof(hname));
}
- CMAddKey(ref, "CSCreationClassName", (CMPIValue*)omcGetComputerSystemClassName(), CMPI_chars);
+ CMAddKey(ref, "CSCreationClassName", (CMPIValue*)cmpiutilGetComputerSystemClassName(), CMPI_chars);
CMAddKey(ref, "CSName", (CMPIValue*)hname, CMPI_chars);
- CMAddKey(ref, "OSCreationClassName", (CMPIValue*)omcGetOperatingSystemClassName(), CMPI_chars);
+ CMAddKey(ref, "OSCreationClassName", (CMPIValue*)cmpiutilGetOperatingSystemClassName(), CMPI_chars);
CMAddKey(ref, "OSName", (CMPIValue*)"Linux", CMPI_chars);
- CMAddKey(ref, "CreationClassName", (CMPIValue*)"OMC_UnixProcess", CMPI_chars);
+ CMAddKey(ref, "CreationClassName", (CMPIValue*)"Linux_UnixProcess", CMPI_chars);
snprintf(wkbfr, sizeof(wkbfr), "%d", pid);
CMAddKey(ref, "Handle", (CMPIValue*)wkbfr, CMPI_chars);
return ref;
@@ -155,38 +155,38 @@
DEBUGOUT("get_job_info called with %s\n", id);
memset(pinfo, 0, sizeof(*pinfo));
- if (omcExecuteProcessAndGatherOutputAndError((char* const*)cmd, NULL, &output,
+ if (cmpiutilExecuteProcessAndGatherOutputAndError((char* const*)cmd, NULL, &output,
&output_size, -1, NULL, NULL, -1, NULL, &status, -1) == 0) {
//DEBUGOUT("vm-install-jobs -s returned %d - %s\n", status, output);
unsigned int num_elements;
- lines = omcStrTokenize(output, "\r\n", &num_elements);
+ lines = cmpiutilStrTokenize(output, "\r\n", &num_elements);
if (lines) {
int i;
for (i = 0; lines[i]; i++) {
- if (omcStrStartsWith(lines[i], "vnc ")) {
- omcStrNCpy(pinfo->vnc, lines[i]+4, sizeof(pinfo->vnc));
- omcStrTrim(pinfo->vnc);
- } else if (omcStrStartsWith(lines[i], "uuid ")) {
- omcStrNCpy(pinfo->uuid, lines[i]+5, sizeof(pinfo->uuid));
- omcStrTrim(pinfo->uuid);
- } else if (omcStrStartsWith(lines[i], "name ")) {
- omcStrNCpy(pinfo->name, lines[i]+5, sizeof(pinfo->name));
- omcStrTrim(pinfo->name);
- } else if (omcStrStartsWith(lines[i], "exit ")) {
+ if (cmpiutilStrStartsWith(lines[i], "vnc ")) {
+ cmpiutilStrNCpy(pinfo->vnc, lines[i]+4, sizeof(pinfo->vnc));
+ cmpiutilStrTrim(pinfo->vnc);
+ } else if (cmpiutilStrStartsWith(lines[i], "uuid ")) {
+ cmpiutilStrNCpy(pinfo->uuid, lines[i]+5, sizeof(pinfo->uuid));
+ cmpiutilStrTrim(pinfo->uuid);
+ } else if (cmpiutilStrStartsWith(lines[i], "name ")) {
+ cmpiutilStrNCpy(pinfo->name, lines[i]+5, sizeof(pinfo->name));
+ cmpiutilStrTrim(pinfo->name);
+ } else if (cmpiutilStrStartsWith(lines[i], "exit ")) {
pinfo->exit_code = atoi(lines[i]+5);
- } else if (omcStrStartsWith(lines[i], "id ")) {
- omcStrNCpy(pinfo->id, lines[i]+3, sizeof(pinfo->id));
- omcStrTrim(pinfo->id);
- } else if (omcStrStartsWith(lines[i], "log ")) {
- omcStrNCpy(pinfo->log, lines[i]+4, sizeof(pinfo->log));
- omcStrTrim(pinfo->log);
- } else if (omcStrStartsWith(lines[i], "state ")) {
+ } else if (cmpiutilStrStartsWith(lines[i], "id ")) {
+ cmpiutilStrNCpy(pinfo->id, lines[i]+3, sizeof(pinfo->id));
+ cmpiutilStrTrim(pinfo->id);
+ } else if (cmpiutilStrStartsWith(lines[i], "log ")) {
+ cmpiutilStrNCpy(pinfo->log, lines[i]+4, sizeof(pinfo->log));
+ cmpiutilStrTrim(pinfo->log);
+ } else if (cmpiutilStrStartsWith(lines[i], "state ")) {
pinfo->state = atoi(lines[i]+6);
- } else if (omcStrStartsWith(lines[i], "pid ")) {
+ } else if (cmpiutilStrStartsWith(lines[i], "pid ")) {
pinfo->pid = atoi(lines[i]+4);
- } else if (omcStrStartsWith(lines[i], "inotify ")) {
- omcStrNCpy(pinfo->inotify, lines[i]+8, sizeof(pinfo->inotify));
- omcStrTrim(pinfo->inotify);
+ } else if (cmpiutilStrStartsWith(lines[i], "inotify ")) {
+ cmpiutilStrNCpy(pinfo->inotify, lines[i]+8, sizeof(pinfo->inotify));
+ cmpiutilStrTrim(pinfo->inotify);
}
}
free(lines);
@@ -213,7 +213,7 @@
NULL
};
- return omcSafeSystem((char* const*)cmd, NULL);
+ return cmpiutilSafeSystem((char* const*)cmd, NULL);
}
/*****************************************************************************/
@@ -227,7 +227,7 @@
NULL
};
- return omcSafeSystem((char* const*)cmd, NULL);
+ return cmpiutilSafeSystem((char* const*)cmd, NULL);
}
/*****************************************************************************/
@@ -241,7 +241,7 @@
NULL
};
- return omcSafeSystem((char* const*)cmd, NULL);
+ return cmpiutilSafeSystem((char* const*)cmd, NULL);
}
/*****************************************************************************/
@@ -252,7 +252,7 @@
VMInstallInfo info;
CMPIInstance *instance = NULL;
if(get_job_info(job_name_key, &info) == 0) {
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderJob",
+ instance = cmpiutilNewInstance(_broker, ns, "XEN_VMBuilderJob",
job_class_keys, properties, pstatus);
if (pstatus->rc != CMPI_RC_OK || CMIsNullObject(instance)) {
DEBUGOUT("_getJobInstance(): CMNewInstance() failed - %d\n",
@@ -282,7 +282,7 @@
CMPI_chars);
}
} else {
- OMC_SETSTATUS(_broker, pstatus, CMPI_RC_ERR_NOT_FOUND,
+ CMPIUTIL_SETSTATUS(_broker, pstatus, CMPI_RC_ERR_NOT_FOUND,
"Unable to get job info for job");
}
return instance;
@@ -321,7 +321,7 @@
if (status.rc != CMPI_RC_OK || CMIsNullObject(ref)) {
DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() "
"failed - %s\n", CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed creating object path");
return status;
}
@@ -341,7 +341,7 @@
if (status.rc != CMPI_RC_OK || CMIsNullObject(ref)) {
DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() "
"failed - %s\n", CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed creating object path");
return status;
}
@@ -351,7 +351,7 @@
DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() "
"failed creating job ref - %s\n",
CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed creating job reference");
return status;
}
@@ -422,12 +422,12 @@
}
CMReturnDone(results);
} else if (strcasecmp(className, "XEN_VMBuilderProcessOfJob") == 0) {
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderProcessOfJob",
+ instance = cmpiutilNewInstance(_broker, ns, "XEN_VMBuilderProcessOfJob",
proc_of_job_class_keys, properties, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
DEBUGOUT("EnumInstances(): failed to create new instance: %s\n",
CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed to create new instance");
return status;
}
@@ -437,7 +437,7 @@
DEBUGOUT("EnumInstances(): CMNewObjectPath() "
"failed creating job ref - %s\n",
CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed creating job reference");
return status;
}
@@ -502,14 +502,14 @@
key = CMGetKey(cop, "Name", &status);
if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) {
DEBUGOUT("GetInstance(): CMGetKey(\"Name\") failed - %d\n", status.rc);
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Cannot get 'Name' property");
return status;
}
job_name_key = CMGetCharPtr(key.value.string);
if (!job_name_key || !strlen(job_name_key)) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty Name property");
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty Name property");
return status;
}
@@ -539,7 +539,7 @@
ci = CBGetInstance(_broker, context, job.value.ref, NULL, &lstatus);
if (ci == NULL) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Instance does not exists");
return status;
}
@@ -562,12 +562,12 @@
ci = CBGetInstance(_broker, context, proc.value.ref, NULL, &lstatus);
if (ci == NULL) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Instance does not exists");
return status;
}
- instance = omccmpiNewInstance(_broker, ns,
+ instance = cmpiutilNewInstance(_broker, ns,
"XEN_VMBuilderProcessOfJob",
proc_of_job_class_keys, properties, &status);
@@ -651,7 +651,7 @@
if (strcasecmp(CMGetCharPtr(class), "XEN_VMBuilderJob") != 0)
{
DEBUGOUT("DeleteInstance() INVALID class name %s\n", CMGetCharPtr(class));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_CLASS,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_CLASS,
CMGetCharPtr(class));
return status;
}
@@ -659,19 +659,19 @@
key = CMGetKey(cop, "Name", &status);
if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) {
DEBUGOUT("DeleteInstance(): CMGetKey(\"Name\") failed - %d\n", status.rc);
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Cannot get 'Name' property from specified object name");
return status;
}
job_name_key = CMGetCharPtr(key.value.string);
if (!job_name_key || !strlen(job_name_key)) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty Name property");
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty Name property");
return status;
}
if(get_job_info(job_name_key, &info) != 0) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Unable to get job information");
return status;
}
@@ -679,14 +679,14 @@
if (info.state != JOBSTATE_FINISHED
&& info.state != JOBSTATE_FAILED
&& info.state != JOBSTATE_CANCELED) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_SUPPORTED,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_SUPPORTED,
"Job must be in the FINISHED, FAILED or CANCELED states "
"to be deleted");
return status;
}
if (delete_job(job_name_key) != 0) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_FAILED,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_FAILED,
"Unabled to delete job");
return status;
}
@@ -822,7 +822,7 @@
if (strcasecmp(CMGetCharPtr(class), "XEN_VMBuilderJob") != 0)
{
DEBUGOUT("InvokeMethod() INVALID class name %s\n", CMGetCharPtr(class));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_CLASS,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_CLASS,
CMGetCharPtr(class));
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
@@ -832,7 +832,7 @@
key = CMGetKey(cop, "Name", &status);
if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) {
DEBUGOUT("InvokeMethod(): CMGetKey(\"Name\") failed - %d\n", status.rc);
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Cannot get 'Name' property from specified object name");
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
@@ -841,14 +841,14 @@
job_name_key = CMGetCharPtr(key.value.string);
if (!job_name_key || !strlen(job_name_key)) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty Name property");
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty Name property");
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
return status;
}
if(get_job_info(job_name_key, &info) != 0) {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND,
"Unable to get job information");
CMReturnData(results, &rv, CMPI_uint32);
CMReturnDone(results);
@@ -877,14 +877,14 @@
}
}
} else if (strcasecmp("KillJob", methodName) == 0) {
- OMC_SETSTATUS(_broker, &status,
+ CMPIUTIL_SETSTATUS(_broker, &status,
CMPI_RC_ERR_NOT_SUPPORTED,
"KillJob called, but not supported - Deprecated");
CMLogMessage(_broker, 1, "VMBuilderService provider",
"KillJob called, but not supported - Deprecated", NULL);
rv.uint32 = 1; // Not supported
} else {
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, methodName);
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, methodName);
rv.uint32 = 1; // Not supported
}
CMReturnData(results, &rv, CMPI_uint32);
@@ -929,7 +929,7 @@
/*****************************************************************************/
static CMPIStatus
doReferences(
- omccmpiSimpleAssocCtx ctx,
+ cmpiutilSimpleAssocCtx ctx,
CMPIAssociationMI *self,
const CMPIBroker *broker,
const CMPIContext *context,
@@ -955,7 +955,7 @@
DEBUGOUT("doReferences called\n");
object_class_name = CMGetCharPtr(CMGetClassName(cop, NULL));
- if(strcasecmp(object_class_name, "OMC_UnixProcess") == 0) {
+ if(strcasecmp(object_class_name, "Linux_UnixProcess") == 0) {
if (role && *role && strcasecmp(role, "PartComponent") != 0) {
/* Unknown role */
return okstatus;
@@ -966,7 +966,7 @@
return okstatus;
}
if (resultClass && *resultClass) {
- if (!omccmpiClassIsDerivedFrom("XEN_VMBuilderJob",
+ if (!cmpiutilClassIsDerivedFrom("XEN_VMBuilderJob",
resultClass, _broker, ns, &status)) {
return okstatus;
}
@@ -993,7 +993,7 @@
if (status.rc != CMPI_RC_OK || CMIsNullObject(jobref)) {
DEBUGOUT("doReferences(): CMNewObjectPath() "
"failed - %d\n", status.rc);
- OMC_SETSTATUS(_broker, &status,
+ CMPIUTIL_SETSTATUS(_broker, &status,
CMPI_RC_ERROR_SYSTEM,
"Failed creating object path");
jobref = NULL;
@@ -1007,17 +1007,17 @@
free(names);
}
if (jobref) {
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderProcessOfJob",
+ instance = cmpiutilNewInstance(_broker, ns, "XEN_VMBuilderProcessOfJob",
proc_of_job_class_keys, properties, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
- DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
+ DEBUGOUT("doReferences(): cmpiutilNewInstance() failed - %s\n",
CMGetCharPtr(status.msg));
return status;
}
CMSetProperty(instance, "GroupComponent", (CMPIValue*)&jobref, CMPI_ref);
CMSetProperty(instance, "PartComponent", (CMPIValue*)&cop, CMPI_ref);
- omccmpiSimpleAssocResults(ctx, instance, &status);
+ cmpiutilSimpleAssocResults(ctx, instance, &status);
}
} else if(strcasecmp(object_class_name, "XEN_VMBuilderJob") == 0) {
if (role && *role && strcasecmp(role, "GroupComponent") != 0) {
@@ -1030,7 +1030,7 @@
return okstatus;
}
if (resultClass && *resultClass) {
- if (!omccmpiClassIsDerivedFrom("OMC_UnixProcess",
+ if (!cmpiutilClassIsDerivedFrom("Linux_UnixProcess",
resultClass, _broker, ns, &status)) {
return okstatus;
}
@@ -1051,16 +1051,16 @@
if (!procref) {
return status;
}
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderProcessOfJob",
+ instance = cmpiutilNewInstance(_broker, ns, "XEN_VMBuilderProcessOfJob",
proc_of_job_class_keys, properties, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
- DEBUGOUT("doReferences(): omccmpiNewInstance() failed - %s\n",
+ DEBUGOUT("doReferences(): cmpiutilNewInstance() failed - %s\n",
CMGetCharPtr(status.msg));
return status;
}
CMSetProperty(instance, "GroupComponent", (CMPIValue*)&cop, CMPI_ref);
CMSetProperty(instance, "PartComponent", (CMPIValue*)&procref, CMPI_ref);
- omccmpiSimpleAssocResults(ctx, instance, &status);
+ cmpiutilSimpleAssocResults(ctx, instance, &status);
}
DEBUGOUT("Leaving doReferences\n");
return okstatus;
@@ -1094,7 +1094,7 @@
DEBUGOUT("Associators() called");
- status = omccmpiSimpleAssociators(doReferences, self,
+ status = cmpiutilSimpleAssociators(doReferences, self,
_broker, context, results, cop, assocClass,
resultClass, role, resultRole, properties);
@@ -1129,7 +1129,7 @@
DEBUGOUT("AssociatorNames() called");
- status = omccmpiSimpleAssociatorNames(doReferences, self, _broker,
+ status = cmpiutilSimpleAssociatorNames(doReferences, self, _broker,
context, results, cop, assocClass, resultClass, role,
resultRole);
@@ -1160,7 +1160,7 @@
DEBUGOUT("References() called");
- status = omccmpiSimpleReferences( doReferences, self, _broker, context,
+ status = cmpiutilSimpleReferences( doReferences, self, _broker, context,
results, cop, resultClass, role, properties);
DEBUGOUT("Leaving References(): %s", (status.rc == CMPI_RC_OK)?"succeeded":"failed");
@@ -1190,16 +1190,16 @@
DEBUGOUT("ReferenceNames() called");
- status = omccmpiSimpleReferenceNames( doReferences, self, _broker,
+ status = cmpiutilSimpleReferenceNames( doReferences, self, _broker,
context, results, cop, resultClass, role);
DEBUGOUT("Leaving ReferenceNames(): %s", (status.rc == CMPI_RC_OK)?"succeeded":"failed");
return status;
}
-CMInstanceMIStub( , omc_xenvmbuilderjob, _broker, Init(&mi));
-CMMethodMIStub( , omc_xenvmbuilderjob, _broker, MethodInit(&mi));
-CMAssociationMIStub( , omc_xenvmbuilderjob, _broker, AssocInit(&mi));
+CMInstanceMIStub( , sblim_xenvmbuilderjob, _broker, Init(&mi));
+CMMethodMIStub( , sblim_xenvmbuilderjob, _broker, MethodInit(&mi));
+CMAssociationMIStub( , sblim_xenvmbuilderjob, _broker, AssocInit(&mi));
Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c
===================================================================
--- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-29 18:31:09 UTC (rev 628)
+++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-30 17:31:13 UTC (rev 629)
@@ -40,19 +40,15 @@
#include <sys/types.h>
#include <sys/wait.h>
-//#include <pwd.h>
-//#include <time.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/ioUtils.h>
-#include <omc/cmpiUtils.h>
-#include <omc/cmpiSimpleAssoc.h>
+#include <cmpiutil/string.h>
+#include <cmpiutil/exec.h>
+#include <cmpiutil/base.h>
+#include <cmpiutil/ioUtils.h>
+#include <cmpiutil/cmpiUtils.h>
+#include <cmpiutil/cmpiSimpleAssoc.h>
/* NULL terminated list of key property names for this class */
@@ -102,7 +98,7 @@
size_t NumOsTypes = sizeof(OSTypes) / sizeof(char*);
#define SERVICE_NAME "xen-vmbuilder"
-#define RPM_NAME "omc-xenvm-builder"
+#define RPM_NAME "sblim-xenvm-builder"
/*
@@ -125,15 +121,15 @@
return NULL;
}
- if (!omcGetComputerSystemName(hname, sizeof(hname))) {
- omcStrNCpy(hname, "localhost", sizeof(hname));
+ if (!cmpiutilGetComputerSystemName(hname, sizeof(hname))) {
+ cmpiutilStrNCpy(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);
+ (CMPIValue*)cmpiutilGetComputerSystemClassName(), CMPI_chars);
CMAddKey(objectpath, "SystemName", (CMPIValue*)hname, CMPI_chars);
return objectpath;
}
@@ -148,15 +144,15 @@
CMPIArray *pra;
char hostName[256];
- if (!omcGetComputerSystemName(hostName, sizeof(hostName))) {
- omcStrNCpy(hostName, "localhost", sizeof(hostName));
+ if (!cmpiutilGetComputerSystemName(hostName, sizeof(hostName))) {
+ cmpiutilStrNCpy(hostName, "localhost", sizeof(hostName));
}
CMSetProperty(instance, "CreationClassName",
(CMPIValue*)"XEN_VMBuilderService", CMPI_chars);
CMSetProperty(instance, "Name", (CMPIValue*)SERVICE_NAME, CMPI_chars);
CMSetProperty(instance, "SystemCreationClassName",
- (CMPIValue*)omcGetComputerSystemClassName(), CMPI_chars);
+ (CMPIValue*)cmpiutilGetComputerSystemClassName(), CMPI_chars);
CMSetProperty(instance, "SystemName", (CMPIValue*)hostName, CMPI_chars);
pra = CMNewArray(_broker, 1, CMPI_uint16, NULL);
wku16 = 2;
@@ -172,7 +168,7 @@
CMSetProperty(instance, "EnabledState", (CMPIValue*)&wku16, CMPI_uint16);
wku16 = 5;
CMSetProperty(instance, "HealthState", (CMPIValue*)&wku16, CMPI_uint16);
- datetime = CMNewDateTimeFromBinary(_broker, omcGetRPMInstallDate(RPM_NAME), 0, NULL);
+ datetime = CMNewDateTimeFromBinary(_broker, cmpiutilGetRPMInstallDate(RPM_NAME), 0, NULL);
CMSetProperty(instance, "InstallDate", (CMPIValue*)&datetime, CMPI_dateTime);
pra = CMNewArray(_broker, 1, CMPI_uint16, NULL);
wku16 = 2;
@@ -218,7 +214,7 @@
if ((status.rc != CMPI_RC_OK) || objectpath == NULL) {
DEBUGOUT("EnumInstanceNames(): get_service_ref() failed - %s\n",
CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed creating new object path");
return status;
}
@@ -230,7 +226,7 @@
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,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed creating new object path");
return status;
}
@@ -238,14 +234,14 @@
if ((status.rc != CMPI_RC_OK) || depref == NULL) {
DEBUGOUT("EnumInstanceNames(): get_service_ref() failed - %s\n",
CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed creating new object path");
return status;
}
CMAddKey(objectpath, "Dependent", (CMPIValue*)&depref, CMPI_ref);
- antref = omccmpiCreateCSObjectPath(_broker, ns, &status);
+ antref = cmpiutilCreateCSObjectPath(_broker, ns, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(antref)) {
- DEBUGOUT("EnumInstanceNames(): omccmpiCreateCSObjectPath failed - %s\n",
+ DEBUGOUT("EnumInstanceNames(): cmpiutilcmpiCreateCSObjectPath failed - %s\n",
CMGetCharPtr(status.msg));
return status;
}
@@ -283,7 +279,7 @@
className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL));
if (strcasecmp(className, "XEN_VMBuilderService") == 0) {
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderService",
+ instance = cmpiutilNewInstance(_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));
@@ -295,12 +291,12 @@
CMReturnDone(results);
} else if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) {
CMPIObjectPath *antref, *depref;
- instance = omccmpiNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
+ instance = cmpiutilNewInstance(_broker, ns, "XEN_VMBuilderHostedService",
hosted_service_class_keys, properties, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
DEBUGOUT("EnumInstances(): failed to create new instance: %s\n",
CMGetCharPtr(status.msg));
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
+ CMPIUTIL_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM,
"Failed to create new instance");
return status;
}
@@ -308,14 +304,14 @@
if ((status.rc != CMPI_RC_OK) || depref == NULL) {
DEBUGOUT("EnumInstances(): get_service_ref() failed - %s\n",
CMGetCharPtr(status.msg));
- OM...
[truncated message content] |