You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(26) |
Dec
(13) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(5) |
Feb
(16) |
Mar
(5) |
Apr
(5) |
May
(13) |
Jun
(12) |
Jul
(1) |
Aug
(2) |
Sep
(13) |
Oct
(6) |
Nov
(1) |
Dec
(29) |
2008 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
(57) |
May
(35) |
Jun
(45) |
Jul
(132) |
Aug
(87) |
Sep
(141) |
Oct
(86) |
Nov
(17) |
Dec
(2) |
2009 |
Jan
(3) |
Feb
(2) |
Mar
(3) |
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2010 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <jc...@us...> - 2008-05-13 23:32:45
|
Revision: 607 http://omc.svn.sourceforge.net/omc/?rev=607&view=rev Author: jcarey Date: 2008-05-13 16:32:49 -0700 (Tue, 13 May 2008) Log Message: ----------- Dev check pnt. CreateVM... Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 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/mof/XEN_VMBuilderVirtualSystemCreationData.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-05-12 17:30:12 UTC (rev 606) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-05-13 23:32:49 UTC (rev 607) @@ -104,12 +104,14 @@ [Description("Type of guest (vm) OS. This defines many defaults and " " provides bootstrap capability. "), ValueMap { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"}, + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", + "22", "23", "24"}, Values { "other", "suse", "sles8", "sles9", "sles10", "sled10", "oes2l", "oes2nw", "netware", "redhat", "rhel3", "rhel4", "rhel5", "solaris9", "solaris10", "windows", "windowsx64", "windowsnt", "windowsxp", "windowsxpx64", "windowsvista", - "windowsvistax64" }] + "windowsvistax64", "opensuse", "winserver2008", + "winserver2008x64" }] uint32 OSType; }; 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-12 17:30:12 UTC (rev 606) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-05-13 23:32:49 UTC (rev 607) @@ -30,23 +30,26 @@ * Author: Jon Carey (jc...@no...) ******************************************************************************/ #include "config.h" +#include "vmbuilder-util.h" #include <unistd.h> #include <stdio.h> #include <stdlib.h> -#include <pwd.h> -#include <sys/types.h> -#include <time.h> + +//#include <pwd.h> +//#include <sys/types.h> +//#include <time.h> #include <limits.h> -#include <errno.h> -#include <signal.h> +//#include <errno.h> +//#include <signal.h> #include <cmpidt.h> #include <cmpift.h> #include <cmpimacs.h> -#include <omc/linuxProcUtils.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> @@ -68,6 +71,35 @@ NULL }; +const char* OSTypes[] = { + "other", + "suse", + "sles8", + "sles9", + "sles10", + "sled10", + "oes2l", + "oes2nw", + "netware", + "redhat", + "rhel3", + "rhel4", + "rhel5", + "solaris9", + "solaris10", + "windows", + "windowsx64", + "windowsnt", + "windowsxp", + "windowsxpx64", + "windowsvista", + "windowsvistax64", + "opensuse", + "winserver2008", + "winserver2008x64" +}; +size_t NumOsTypes = sizeof(OSTypes) / sizeof(char*); + #define SERVICE_NAME "xen-vmbuilder" #define RPM_NAME "omc-xenvm-builder" @@ -565,6 +597,244 @@ return status; } +/*****************************************************************************/ +omcStrBuf* +create_response_file(const char* rf, char *filename, size_t filename_length, + CMPIStatus* pstatus) +{ + FILE* fd = omcCreateTempFile(filename, filename_length); + size_t rflen = strlen(rf); + if (fwrite(rf, sizeof(char), rflen, fd) != rflen) { + fclose(fd); + unlink(filename); + OMC_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM, + "Failed to create temp file for response file"); + return NULL; + } + fclose(fd); + return filename; +} + +/*****************************************************************************/ +static CMPIObjectPath* +start_create_vm(const char* vmname, const CMPIInstance* cdci, + const char* uuid, const char* ns, CMPIValue *prv, + CMPIStatus *pstatus) +{ + CMPIData data; + omcStrArray *pstra; + const char* iid = NULL; + const char *os_type; + char wkbfr[256]; + CMPIObjectPath *jobref = NULL; + + DEBUGOUT("start_create_vm() called...\n"); + + data = CMGetProperty(cdci, "InstanceID", NULL); + if (!CMIsNullValue(data)) { + iid = CMGetCharPtr(data.value.string); + } + if (!iid || !strlen(iid)) { + OMC_SETSTATUS(_broker, pstatus, CMPI_RC_ERR_INVALID_PARAMETER, + "'InstanceID' is not set on instance"); + return NULL; + } + + /**** OSType ****/ + data = CMGetProperty(cdci, "OSType", NULL); + if (!CMIsNullValue(data)) { + if (data.value.uint32 >= NumOsTypes) { + OMC_SETSTATUS(_broker, pstatus, CMPI_RC_ERR_INVALID_PARAMETER, + "CreationData has invalid OS type specification"); + return NULL; + } + os_type = OSTypes[data.value.uint32]; + } else { + os_type = "other"; + } + + pstra = omcStrArray_create(); + if (!pstra) { + OMC_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM, + "Failed to create string array object"); + return NULL; + } + omcStrArray_append(pstra, "/usr/bin/vm-install"); + omcStrArray_append(pstra, "--background"); + omcStrArray_append(pstra, "-n"); + omcStrArray_append(pstra, vmname); + omcStrArray_append(pstra, "--os-type"); + omcStrArray_append(pstra, os_type); + if (uuid && strlen(uuid)) { + omcStrArray_append(pstra, "--uuid"); + omcStrArray_append(pstra, uuid); + } + + /**** NumVCPUs ****/ + data = CMGetProperty(cdci, "NumVCPUs", NULL); + if (!CMIsNullValue(data)) { + if (data.value.uint8) { + snprintf(wkbfr, sizeof(wkbfr), "%u", data.value.uint8); + omcStrArray_append(pstra, "-c"); + omcStrArray_append(pstra, wkbfr); + } + } + /**** Disks ****/ + data = CMGetProperty(cdci, "Disks", NULL); + if (!CMIsNullValue(data)) { + size_t i, size = CMGetArrayCount(data.value.array, pstatus); + if (size) { + for (i = 0; i < size; i++) { + data = CMGetArrayElementAt(data.value.array, i, pstatus); + if (!CMIsNullValue(data)) { + const char* pd = (char*) CMGetCharPtr(data.value.string); + if (pd && strlen(pd)) { + omcStrArray_append(pstra, "-d"); + omcStrArray_append(pstra, pd); + } + } + } + } + } + /**** GraphicsType ****/ + data = CMGetProperty(cdci, "GraphicsType", NULL); + omcStrArray_append(pstra, "--graphics"); + if (!CMIsNullValue(data)) { + switch(data.value.uint32) { + case 1: // cirrus + omcStrArray_append(pstra, "cirrus"); + break; + case 3: // para + omcStrArray_append(pstra, "para"); + break; + case 4: // vesa + omcStrArray_append(pstra, "vesa"); + break; + case 2: // none + case 0: // Unknown + default: // unknown + omcStrArray_append(pstra, "none"); + break; + } + } else { + omcStrArray_append(pstra, "none"); + } + /**** GraphicsViewerType ****/ + data = CMGetProperty(cdci, "GraphicsViewerType", NULL); + if (!CMIsNullValue(data)) { + if (data.value.uint32 == 1) { + omcStrArray_append(pstra, "--graphics-viewer"); + omcStrArray_append(pstra, "sdl"); + } else if (data.value.uint32 == 2) { + omcStrArray_append(pstra, "--graphics-viewer"); + omcStrArray_append(pstra, "vnc"); + } + } + /**** Memory ****/ + data = CMGetProperty(cdci, "Memory", NULL); + if (!CMIsNullValue(data)) { + if (data.value.uint32) { + snprintf(wkbfr, sizeof(wkbfr), "%u", data.value.uint32); + omcStrArray_append(pstra, "--memory"); + omcStrArray_append(pstra, wkbfr); + } + } + /**** MaxMemory ****/ + data = CMGetProperty(cdci, "MaxMemory", NULL); + if (!CMIsNullValue(data)) { + if (data.value.uint32) { + snprintf(wkbfr, sizeof(wkbfr), "%u", data.value.uint32); + omcStrArray_append(pstra, "--max-memory"); + omcStrArray_append(pstra, wkbfr); + } + } + + /**** Nics ****/ + data = CMGetProperty(cdci, "Nics", NULL); + if (!CMIsNullValue(data)) { + size_t i, size = CMGetArrayCount(data.value.array, pstatus); + if (size) { + for (i = 0; i < size; i++) { + data = CMGetArrayElementAt(data.value.array, i, pstatus); + if (!CMIsNullValue(data)) { + const char* pd = (char*) CMGetCharPtr(data.value.string); + if (pd && strlen(pd)) { + omcStrArray_append(pstra, "--nic"); + omcStrArray_append(pstra, pd); + } + } + } + } + } + /**** VirtType ****/ + data = CMGetProperty(cdci, "VirtType", NULL); + if (!CMIsNullValue(data) && data.value.uint32 == 2) { + omcStrArray_append(pstra, "--full-virt"); + } else { + omcStrArray_append(pstra, "--para-virt"); + } + /**** VNCPort ****/ + data = CMGetProperty(cdci, "VNCPort", NULL); + if (!CMIsNullValue(data)) { + if (data.value.uint32) { + snprintf(wkbfr, sizeof(wkbfr), "%u", data.value.uint32); + omcStrArray_append(pstra, "--vnc-port"); + omcStrArray_append(pstra, wkbfr); + } + } + /**** SourceURL ****/ + data = CMGetProperty(cdci, "SourceURL", NULL); + if (!CMIsNullValue(data)) { + const char *su = CMGetCharPtr(data.value.string); + if (su && strlen(su)) { + omcStrArray_append(pstra, "-s"); + omcStrArray_append(pstra, su); + } + } + /**** ExtraInstallArgs ****/ + data = CMGetProperty(cdci, "ExtraInstallArgs", NULL); + if (!CMIsNullValue(data)) { + const char *xa = CMGetCharPtr(data.value.string); + if (xa && strlen(xa)) { + omcStrArray_append(pstra, "-x"); + omcStrArray_append(pstra, xa); + } + } + + /**** ResponseFile ****/ + data = CMGetProperty(cdci, "ResponseFile", NULL); + if (!CMIsNullValue(data)) { + char wkbfr[PATH_MAX]; + const char *rf = CMGetCharPtr(data.value.string); + if (rf && strlen(rf)) { + char *rrsp = create_response_file(rf, wkbfr, sizeof(wkbfr), pstatus); + if (!rrsp) { + omcStrArray_destroy(pstra); + return NULL; + } + omsStrArray_append(pstra, "--os-settings"); + omsStrArray_append(pstra, rrsp); + } + } + + // TODO Execute process and gather output + + + + + + omcStrArray_destroy(pstra); + + // TEST + jobref = CMNewObjectPath(_broker, ns, + "XEN_VMBUilderJob", pstatus); + CMAddKey(jobref, "Name", (CMPIValue*)"Bogus", CMPI_chars); + prv->uint32 = 0; + + DEBUGOUT("start_create_vm() returning\n"); + return jobref; +} + // **************************************************************************** // InvokeMethod() // params: CMPIMethodMI* self: [in] Handle to this provider @@ -585,55 +855,149 @@ const CMPIArgs* in, CMPIArgs* out) { + CMPIData param; CMPIStatus status = {CMPI_RC_OK, NULL}; CMPIString *class = NULL; CMPIValue rv; - /* char *ns = CMGetCharPtr(CMGetNameSpace(cop, NULL)); */ + const 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; +printf("class name: %s\n", CMGetCharPtr(class)); + if (strcasecmp(CMGetCharPtr(class), "XEN_VMBuilderService") == 0) { +printf("class name is XEN_VMBuilderService\n"); + if (strcasecmp("CreateVM", methodName) == 0) { + CMPIObjectPath *jobref; + CMPIInstance* cdci; + const char *vmname = NULL; + const char *uuid = NULL; + +printf("In CreateVM method block\n"); +printf("Getting VMName arg\n"); + + param = CMGetArg(in, "VMName", &status); + if (!CMIsNullValue(param)) { + vmname = CMGetCharPtr(param.value.string); +printf("VMName arg: %s\n", vmname); + } + if (!vmname || !strlen(vmname)) { + rv.uint32 = 80; // Param is invalid/missing + DEBUGOUT("InvokeMethod: Missing parameter: VMName\n"); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, + "'VMName' is a required parameter"); + return status; + } +printf("Getting NewSystemCreationData arg\n"); + param = CMGetArg(in, "NewSystemCreationData", &status); + if (CMIsNullValue(param)) { + rv.uint32 = 80; // Param is invalid/missing + DEBUGOUT("InvokeMethod: Missing parameter: NewSystemCreationData\n"); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, + "'NewSystemCreationData' is a required parameter"); + return status; + } +printf("Got NewSystemCreationData ref arg\n"); + +printf("Getting CreationData instance...\n"); + cdci = CBGetInstance(_broker, context, param.value.ref, NULL, &status); + if (cdci == NULL) { + if (status.rc == CMPI_RC_ERR_NOT_FOUND) { + DEBUGOUT("Failed to get creation data instance\n"); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, + "'NewSystemCreationData' does not refer to a valid object"); + } else { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_FAILED, + "Failed to get XEN_VMBuilderVirtualSystemCreationData " + "instance"); + } + return status; + } + +/* +printf("Getting InstanceID from NewSystemCreationData\n"); + key = CMGetKey(param.value.ref, "InstanceID", &status); + if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) { + DEBUGOUT("InvokeMethod(): CMGetKey(\"InstanceID\") failed - %d " + "for NewSystemCreationData param\n", status.rc); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, + "'NewSystemCreationData' does not refer to a valid object"); + return status; + } + + iid = CMGetCharPtr(key.value.string); + if (!iid || !strlen(iid)) { + DEBUGOUT("InvokeMethod(): Empty InstanceID on CreationData\n"); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, + "'NewSystemCreationData' does not refer to a valid object"); + return status; + } + DEBUGOUT("InvokeMethod(): CreationData InstanceID: %s\n", iid); + query = db_create_formatted_sql("SELECT InstanceID from CreationData " + "where InstanceID=%Q", iid); + cc = db_create_select_results(&dbctx, query, err_msg, sizeof(err_msg)); + db_destroy_formatted_sql(query); + if (cc != 0) { + DEBUGOUT("InvokeMethod(): Failed to connect to database: %s", + err_msg); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg); + return status; + } + cc = db_results_have_more_rows(dbctx); + db_destroy_select_results(dbctx); + if (!cc) { + DEBUGOUT("InvokeMethod(): Failed to find instanceid %s in " + "database\n", iid); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, + "'NewSystemCreationData' does not refer to a valid object"); + return status; + } +*/ + param = CMGetArg(in, "UUID", &status); + if (!CMIsNullValue(param)) { + uuid = CMGetCharPtr(param.value.string); + DEBUGOUT("InvokeMethod(): UUID specified: %s\n", uuid); + } + + jobref = start_create_vm(vmname, cdci, uuid, ns, &rv, &status); + if (!jobref) { + DEBUGOUT("start_create_vm returned a NULL ref. status: %d\n", status.rc); + return status; + } + 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) { + 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); + } } - 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; } 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-12 17:30:12 UTC (rev 606) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-13 23:32:49 UTC (rev 607) @@ -180,7 +180,7 @@ { CMSetStatus(pstatus, CMPI_RC_OK); if (!CMIsNullValue((*pdata))) { - if (pdata->value.uint32 > 21) { + if (pdata->value.uint32 > 24) { CMSetStatusWithChars(_broker, pstatus, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid 'OSType' property"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-05-12 17:30:29
|
Revision: 606 http://omc.svn.sourceforge.net/omc/?rev=606&view=rev Author: jcarey Date: 2008-05-12 10:30:12 -0700 (Mon, 12 May 2008) Log Message: ----------- Removed UUID from creation data. Added to CreateVM method. Add validation for creation data value maps Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c Modified: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-05-12 16:09:06 UTC (rev 605) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-05-12 17:30:12 UTC (rev 606) @@ -71,6 +71,11 @@ "for the build")] XEN_VMBuilderVirtualSystemCreationData REF NewSystemCreationData, + [IN, Description("The UUID that will be used for the new VM. This is " + "an optional parameter. If not specified, the UUID will be " + "automatically generated")] + string UUID, + [IN(false), OUT, Description ("REF to the new " "XEN_VMBuilderJob instance.")] XEN_VMBuilderJob REF VMBuilderJob); Modified: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-05-12 16:09:06 UTC (rev 605) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-05-12 17:30:12 UTC (rev 606) @@ -11,11 +11,6 @@ "method on XEN_VMBuilderService.")] class XEN_VMBuilderVirtualSystemCreationData : CIM_VirtualSystemSettingData { - [Description( - "UUID contains the universal unique identifier for the virtual machine. " - "If none is given, a random UUID will be generated.")] - string UUID; - [Description("type of virtualization. Values: " " Unknown: undefined behavior - maybe try to determine best? " " Para: Para Virtualization: OS Must support para virtualization. " 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-12 16:09:06 UTC (rev 605) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-12 17:30:12 UTC (rev 606) @@ -78,7 +78,6 @@ "SourceURL TEXT," "SuspendDataRoot TEXT," "SwapFileDataRoot TEXT," - "UUID TEXT," "VNCPort INTEGER," //-- 0: Unknown //-- 1: Para 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-12 16:09:06 UTC (rev 605) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-12 17:30:12 UTC (rev 606) @@ -102,7 +102,6 @@ "SourceURL," \ "SuspendDataRoot," \ "SwapFileDataRoot," \ - "UUID," \ "VNCPort," \ "VirtType," \ "VirtualSystemIdentifier," \ @@ -148,7 +147,6 @@ CDF_SourceURL, CDF_SuspendDataRoot, CDF_SwapFileDataRoot, - CDF_UUID, CDF_VNCPort, CDF_VirtType, CDF_VirtualSystemIdentifier, @@ -162,6 +160,126 @@ static const CMPIBroker* _broker; /*****************************************************************************/ +static CMPIrc +valid_virt_type(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint32 > 2) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'VirtType' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_os_type(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint32 > 21) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'OSType' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_graphics_viewer_type(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint32 > 2) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'GraphicsViewerType' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_graphics_type(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint32 > 4) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'GraphicsType' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_changeable_type(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint16 > 3) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'ChangeableType' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_automatic_recovery_action(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint16 < 2 || pdata->value.uint16 > 4) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'AutomaticRecoveryAction' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_automatic_shutdown_action(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint16 < 2 || pdata->value.uint16 > 4) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'AutomaticShutdownAction' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_automatic_startup_action(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint16 < 2 || pdata->value.uint16 > 4) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'AutomaticStartupAction' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ static void add_u8_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, const char* prop_name) @@ -179,12 +297,16 @@ /*****************************************************************************/ static void add_u16_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, - const char* prop_name) + const char* prop_name, CMPIData *pdata) { - CMPIData data = CMGetProperty(instance, prop_name, NULL); - if (!CMIsNullValue(data)) { + CMPIData data; + if (!pdata) { + pdata = &data; + } + *pdata = CMGetProperty(instance, prop_name, NULL); + if (!CMIsNullValue((*pdata))) { char wkbfr[32]; - snprintf(wkbfr, sizeof(wkbfr), "%u,", data.value.uint16); + snprintf(wkbfr, sizeof(wkbfr), "%u,", pdata->value.uint16); omcStrBuf_cat(pstrbuf, wkbfr, 0); } else { omcStrBuf_cat(pstrbuf, "NULL,", 0); @@ -194,12 +316,17 @@ /*****************************************************************************/ static void add_u32_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, - const char* prop_name) + const char* prop_name, CMPIData* pdata) { - CMPIData data = CMGetProperty(instance, prop_name, NULL); - if (!CMIsNullValue(data)) { + CMPIData data; + if (!pdata) { + pdata = &data; + } + *pdata = CMGetProperty(instance, prop_name, NULL); + + if (!CMIsNullValue((*pdata))) { char wkbfr[32]; - snprintf(wkbfr, sizeof(wkbfr), "%u,", data.value.uint32); + snprintf(wkbfr, sizeof(wkbfr), "%u,", pdata->value.uint32); omcStrBuf_cat(pstrbuf, wkbfr, 0); } else { omcStrBuf_cat(pstrbuf, "NULL,", 0); @@ -317,7 +444,6 @@ 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"); @@ -524,15 +650,19 @@ /*****************************************************************************/ void mod_add_u16_prop(omcStrArray* pstra, const CMPIInstance* modified_instance, - const char* prop_name, const char** properties) + const char* prop_name, const char** properties, CMPIData* pdata) { char wkbfr[256]; CMPIData data; - if (!get_mod_property(modified_instance, prop_name, properties, &data)) { + + if (!pdata) { + pdata = &data; + } + if (!get_mod_property(modified_instance, prop_name, properties, pdata)) { return; } - if (!CMIsNullValue(data)) { - snprintf(wkbfr, sizeof(wkbfr), "%s=%u", prop_name, data.value.uint16); + if (!CMIsNullValue((*pdata))) { + snprintf(wkbfr, sizeof(wkbfr), "%s=%u", prop_name, pdata->value.uint16); } else { snprintf(wkbfr, sizeof(wkbfr), "%s=NULL", prop_name); } @@ -609,15 +739,19 @@ /*****************************************************************************/ void mod_add_u32_prop(omcStrArray* pstra, const CMPIInstance* modified_instance, - const char* prop_name, const char** properties) + const char* prop_name, const char** properties, CMPIData* pdata) { char wkbfr[256]; CMPIData data; - if (!get_mod_property(modified_instance, prop_name, properties, &data)) { + + if (!pdata) { + pdata = &data; + } + if (!get_mod_property(modified_instance, prop_name, properties, pdata)) { return; } - if (!CMIsNullValue(data)) { - snprintf(wkbfr, sizeof(wkbfr), "%s=%u", prop_name, data.value.uint32); + if (!CMIsNullValue((*pdata))) { + snprintf(wkbfr, sizeof(wkbfr), "%s=%u", prop_name, pdata->value.uint32); } else { snprintf(wkbfr, sizeof(wkbfr), "%s=NULL", prop_name); } @@ -703,24 +837,27 @@ return status; } - pstrbuf = omcStrBuf_create(); - if (!pstrbuf) { - CMSetStatusWithChars(_broker, &status, CMPI_RC_ERROR_SYSTEM, - "Failed to create string buffer"); + mod_add_u16_prop(pstra, modified_instance, "AutoMaticRecoveryAction", properties, &data); + if (valid_automatic_recovery_action(&data, &status) != CMPI_RC_OK) { omcStrArray_destroy(pstra); return status; } - - mod_add_u16_prop(pstra, modified_instance, "AutoMaticRecoveryAction", properties); - mod_add_u16_prop(pstra, modified_instance, "AutoMaticShutdownAction", properties); - mod_add_u16_prop(pstra, modified_instance, "AutoMaticStartupAction", properties); + mod_add_u16_prop(pstra, modified_instance, "AutoMaticShutdownAction", properties, &data); + if (valid_automatic_shutdown_action(&data, &status) != CMPI_RC_OK) { + omcStrArray_destroy(pstra); + return status; + } + mod_add_u16_prop(pstra, modified_instance, "AutoMaticStartupAction", properties, &data); + if (valid_automatic_startup_action(&data, &status) != CMPI_RC_OK) { + omcStrArray_destroy(pstra); + return status; + } if (get_mod_property(modified_instance, "AutoMaticStartupActionDelay", properties, &data)) { if (!CMIsNullValue(data)) { if (!CMIsInterval(data.value.dateTime, &status)) { CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, "'AutoMaticStartupActionDelay' must be an interval"); - omcStrBuf_destroy(pstrbuf); omcStrArray_destroy(pstra); return status; } @@ -732,10 +869,14 @@ } } mod_add_u16_prop(pstra, modified_instance, - "AutomaticStartupActionSequenceNumber", properties); + "AutomaticStartupActionSequenceNumber", properties, NULL); mod_add_str_prop(pstra, modified_instance, "CPUArchitecture", properties); mod_add_str_prop(pstra, modified_instance, "Caption", properties); - mod_add_u16_prop(pstra, modified_instance, "ChangeableType", properties); + mod_add_u16_prop(pstra, modified_instance, "ChangeableType", properties, &data); + if (valid_changeable_type(&data, &status) != CMPI_RC_OK) { + omcStrArray_destroy(pstra); + return status; + } mod_add_str_prop(pstra, modified_instance, "ConfigurationDataRoot", properties); mod_add_str_prop(pstra, modified_instance, "ConfigurationFile", properties); mod_add_str_prop(pstra, modified_instance, "ConfigurationID", properties); @@ -746,7 +887,6 @@ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, "'CreationTime' cannot be an interval"); - omcStrBuf_destroy(pstrbuf); omcStrArray_destroy(pstra); return status; } @@ -762,27 +902,50 @@ mod_add_str_prop(pstra, modified_instance, "ElementName", properties); mod_add_stra_prop(pstra, modified_instance, "ExtraConfigInfo", properties); mod_add_str_prop(pstra, modified_instance, "ExtraInstallArgs", properties); - mod_add_u32_prop(pstra, modified_instance, "GraphicsType", properties); - mod_add_u32_prop(pstra, modified_instance, "GraphicsViewerType", properties); + mod_add_u32_prop(pstra, modified_instance, "GraphicsType", properties, &data); + if (valid_graphics_type(&data, &status) != CMPI_RC_OK) { + omcStrArray_destroy(pstra); + return status; + } + mod_add_u32_prop(pstra, modified_instance, "GraphicsViewerType", properties, &data); + if (valid_graphics_viewer_type(&data, &status) != CMPI_RC_OK) { + omcStrArray_destroy(pstra); + return status; + } mod_add_str_prop(pstra, modified_instance, "LogDataRoot", properties); - mod_add_u32_prop(pstra, modified_instance, "MaxMemory", properties); - mod_add_u32_prop(pstra, modified_instance, "Memory", properties); + mod_add_u32_prop(pstra, modified_instance, "MaxMemory", properties, NULL); + mod_add_u32_prop(pstra, modified_instance, "Memory", properties, NULL); mod_add_stra_prop(pstra, modified_instance, "Nics", properties); mod_add_stra_prop(pstra, modified_instance, "Notes", properties); mod_add_u8_prop(pstra, modified_instance, "NumVCPUs", properties); - mod_add_u32_prop(pstra, modified_instance, "OSType", properties); + mod_add_u32_prop(pstra, modified_instance, "OSType", properties, &data); + if (valid_os_type(&data, &status) != CMPI_RC_OK) { + omcStrArray_destroy(pstra); + return status; + } mod_add_str_prop(pstra, modified_instance, "RecoveryFile", properties); mod_add_str_prop(pstra, modified_instance, "ResponseFile", properties); mod_add_str_prop(pstra, modified_instance, "SnapshotDataRoot", properties); mod_add_str_prop(pstra, modified_instance, "SourceURL", properties); mod_add_str_prop(pstra, modified_instance, "SuspendDataRoot", properties); mod_add_str_prop(pstra, modified_instance, "SwapFileDataRoot", properties); - mod_add_str_prop(pstra, modified_instance, "UUID", properties); - mod_add_u32_prop(pstra, modified_instance, "VNCPort", properties); - mod_add_u32_prop(pstra, modified_instance, "VirtType", properties); + mod_add_u32_prop(pstra, modified_instance, "VNCPort", properties, NULL); + mod_add_u32_prop(pstra, modified_instance, "VirtType", properties, &data); + if (valid_virt_type(&data, &status) != CMPI_RC_OK) { + omcStrArray_destroy(pstra); + return status; + } mod_add_str_prop(pstra, modified_instance, "VirtualSystemIdentifier", properties); mod_add_str_prop(pstra, modified_instance, "VirtualSystemType", properties); + pstrbuf = omcStrBuf_create(); + if (!pstrbuf) { + CMSetStatusWithChars(_broker, &status, CMPI_RC_ERROR_SYSTEM, + "Failed to create string buffer"); + omcStrArray_destroy(pstra); + return status; + } + omcStrBuf_cat(pstrbuf, "UPDATE CreationData SET ", 0); size = omcStrArray_size(pstra); omcStrBuf_cat(pstrbuf, omcStrArray_get_element(pstra, (size_t)0), 0); @@ -864,10 +1027,21 @@ omcStrBuf_cat(pstrbuf, ") VALUES (", 0); db_sql_insert(pstrbuf, "%Q,", iid); - add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticRecoveryAction"); - add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticShutdownAction"); - add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupAction"); - + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticRecoveryAction", &data); + if (valid_automatic_recovery_action(&data, &status) != CMPI_RC_OK) { + omcStrBuf_destroy(pstrbuf); + return status; + } + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticShutdownAction", &data); + if (valid_automatic_shutdown_action(&data, &status) != CMPI_RC_OK) { + omcStrBuf_destroy(pstrbuf); + return status; + } + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupAction", &data); + if (valid_automatic_startup_action(&data, &status) != CMPI_RC_OK) { + omcStrBuf_destroy(pstrbuf); + return status; + } data = CMGetProperty(newinstance, "AutoMaticStartupActionDelay", NULL); if (!CMIsNullValue(data)) { if (!CMIsInterval(data.value.dateTime, &status)) { @@ -885,10 +1059,14 @@ omcStrBuf_cat(pstrbuf, "NULL,", 0); } - add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupActionSequenceNumber"); + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupActionSequenceNumber", NULL); add_str_prop_to_query(pstrbuf, newinstance, "CPUArchitecture", 0); add_str_prop_to_query(pstrbuf, newinstance, "Caption", 0); - add_u16_prop_to_query(pstrbuf, newinstance, "ChangeableType"); + add_u16_prop_to_query(pstrbuf, newinstance, "ChangeableType", &data); + if (valid_changeable_type(&data, &status) != CMPI_RC_OK) { + omcStrBuf_destroy(pstrbuf); + return status; + } add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationDataRoot", 0); add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationFile", 0); add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationID", 0); @@ -916,24 +1094,39 @@ add_str_prop_to_query(pstrbuf, newinstance, "ElementName", 0); add_stra_prop_to_query(pstrbuf, newinstance, "ExtraConfigInfo"); add_str_prop_to_query(pstrbuf, newinstance, "ExtraInstallArgs", 0); - add_u32_prop_to_query(pstrbuf, newinstance, "GraphicsType"); - add_u32_prop_to_query(pstrbuf, newinstance, "GraphicsViewerType"); + add_u32_prop_to_query(pstrbuf, newinstance, "GraphicsType", &data); + if (valid_graphics_type(&data, &status) != CMPI_RC_OK) { + omcStrBuf_destroy(pstrbuf); + return status; + } + 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"); - add_u32_prop_to_query(pstrbuf, newinstance, "Memory"); + add_u32_prop_to_query(pstrbuf, newinstance, "MaxMemory", NULL); + add_u32_prop_to_query(pstrbuf, newinstance, "Memory", NULL); add_stra_prop_to_query(pstrbuf, newinstance, "Nics"); add_stra_prop_to_query(pstrbuf, newinstance, "Notes"); add_u8_prop_to_query(pstrbuf, newinstance, "NumVCPUs"); - add_u32_prop_to_query(pstrbuf, newinstance, "OSType"); + add_u32_prop_to_query(pstrbuf, newinstance, "OSType", &data); + if (valid_os_type(&data, &status) != CMPI_RC_OK) { + omcStrBuf_destroy(pstrbuf); + return status; + } add_str_prop_to_query(pstrbuf, newinstance, "RecoveryFile", 0); add_str_prop_to_query(pstrbuf, newinstance, "ResponseFile", 0); add_str_prop_to_query(pstrbuf, newinstance, "SnapshotDataRoot", 0); add_str_prop_to_query(pstrbuf, newinstance, "SourceURL", 0); add_str_prop_to_query(pstrbuf, newinstance, "SuspendDataRoot", 0); add_str_prop_to_query(pstrbuf, newinstance, "SwapFileDataRoot", 0); - add_str_prop_to_query(pstrbuf, newinstance, "UUID", 0); - add_u32_prop_to_query(pstrbuf, newinstance, "VNCPort"); - add_u32_prop_to_query(pstrbuf, newinstance, "VirtType"); + add_u32_prop_to_query(pstrbuf, newinstance, "VNCPort", NULL); + add_u32_prop_to_query(pstrbuf, newinstance, "VirtType", &data); + if (valid_virt_type(&data, &status) != CMPI_RC_OK) { + omcStrBuf_destroy(pstrbuf); + return status; + } add_str_prop_to_query(pstrbuf, newinstance, "VirtualSystemIdentifier", 0); add_str_prop_to_query(pstrbuf, newinstance, "VirtualSystemType", 1); omcStrBuf_cat(pstrbuf, ");", 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-05-12 16:10:17
|
Revision: 605 http://omc.svn.sourceforge.net/omc/?rev=605&view=rev Author: jcarey Date: 2008-05-12 09:09:06 -0700 (Mon, 12 May 2008) Log Message: ----------- implemented modify instance Modified Paths: -------------- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 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-09 22:41:26 UTC (rev 604) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-12 16:09:06 UTC (rev 605) @@ -541,6 +541,24 @@ /*****************************************************************************/ void +mod_add_u8_prop(omcStrArray* pstra, const CMPIInstance* modified_instance, + const char* prop_name, const char** properties) +{ + char wkbfr[256]; + CMPIData data; + if (!get_mod_property(modified_instance, prop_name, properties, &data)) { + return; + } + if (!CMIsNullValue(data)) { + snprintf(wkbfr, sizeof(wkbfr), "%s=%u", prop_name, data.value.uint8); + } else { + snprintf(wkbfr, sizeof(wkbfr), "%s=NULL", prop_name); + } + omcStrArray_append(pstra, wkbfr); +} + +/*****************************************************************************/ +void mod_add_str_prop(omcStrArray* pstra, const CMPIInstance* modified_instance, const char* prop_name, const char** properties) { @@ -627,8 +645,7 @@ const char *className, *iid; char *query, wkbfr[256]; CMPIData key, data; - int cc, prop_cnt, cur_prop_cnt = 0; - VMBDBCtx dbctx; + int i, size, cc, prop_cnt; omcStrBuf *pstrbuf; omcStrArray *pstra; @@ -714,7 +731,8 @@ omcStrArray_append(pstra, "AutoMaticStartupActionDelay=NULL"); } } - mod_add_u16_prop(pstra, modified_instance, "AutoMaticStartupAction", properties); + mod_add_u16_prop(pstra, modified_instance, + "AutomaticStartupActionSequenceNumber", properties); mod_add_str_prop(pstra, modified_instance, "CPUArchitecture", properties); mod_add_str_prop(pstra, modified_instance, "Caption", properties); mod_add_u16_prop(pstra, modified_instance, "ChangeableType", properties); @@ -747,48 +765,41 @@ mod_add_u32_prop(pstra, modified_instance, "GraphicsType", properties); mod_add_u32_prop(pstra, modified_instance, "GraphicsViewerType", properties); mod_add_str_prop(pstra, modified_instance, "LogDataRoot", properties); - mod_add_u32_prop(pstra, modified_instance, "MaxMemory", properties); mod_add_u32_prop(pstra, modified_instance, "Memory", properties); + mod_add_stra_prop(pstra, modified_instance, "Nics", properties); + mod_add_stra_prop(pstra, modified_instance, "Notes", properties); + mod_add_u8_prop(pstra, modified_instance, "NumVCPUs", properties); + mod_add_u32_prop(pstra, modified_instance, "OSType", properties); + mod_add_str_prop(pstra, modified_instance, "RecoveryFile", properties); + mod_add_str_prop(pstra, modified_instance, "ResponseFile", properties); + mod_add_str_prop(pstra, modified_instance, "SnapshotDataRoot", properties); + mod_add_str_prop(pstra, modified_instance, "SourceURL", properties); + mod_add_str_prop(pstra, modified_instance, "SuspendDataRoot", properties); + mod_add_str_prop(pstra, modified_instance, "SwapFileDataRoot", properties); + mod_add_str_prop(pstra, modified_instance, "UUID", properties); + mod_add_u32_prop(pstra, modified_instance, "VNCPort", properties); + mod_add_u32_prop(pstra, modified_instance, "VirtType", properties); + mod_add_str_prop(pstra, modified_instance, "VirtualSystemIdentifier", properties); + mod_add_str_prop(pstra, modified_instance, "VirtualSystemType", properties); -/* - - omcStrBuf_cat(pstrbuf, "UPDATE CreationData SET ", 0); - - - - get_mod_property(modified_instance, "Nics", properties, &data) - get_mod_property(modified_instance, "Notes", properties, &data) - get_mod_property(modified_instance, "NumVCPUs", properties, &data) - get_mod_property(modified_instance, "OSType", properties, &data) - get_mod_property(modified_instance, "RecoveryFile", properties, &data) - get_mod_property(modified_instance, "ResponseFile", properties, &data) - get_mod_property(modified_instance, "SnapshotDataRoot", properties, &data) - get_mod_property(modified_instance, "SourceURL", properties, &data) - get_mod_property(modified_instance, "SuspendDataRoot", properties, &data) - get_mod_property(modified_instance, "SwapFileDataRoot", properties, &data) - get_mod_property(modified_instance, "UUID", properties, &data) - get_mod_property(modified_instance, "VNCPort", properties, &data) - get_mod_property(modified_instance, "VirtType", properties, &data) - get_mod_property(modified_instance, "VirtualSystemIdentifier", properties, &data) - get_mod_property(modified_instance, "VirtualSystemType", properties, &data) - - -*/ - - - - - - - - - - - - - + size = omcStrArray_size(pstra); + omcStrBuf_cat(pstrbuf, omcStrArray_get_element(pstra, (size_t)0), 0); + for(i = 1; i < size; i++) { + omcStrBuf_cat(pstrbuf, ",", 0); + omcStrBuf_cat(pstrbuf, omcStrArray_get_element(pstra, (size_t)i), 0); + } + omcStrArray_destroy(pstra); + query = db_create_formatted_sql(" WHERE InstanceID=%Q;", iid); + omcStrBuf_cat(pstrbuf, query, 0); + db_destroy_formatted_sql(query); + if (db_exec(pstrbuf->bfr, wkbfr, sizeof(wkbfr)) < 0LL) { + DEBUGOUT("ModifyInstance(): failed updating database record: %s\n", + wkbfr); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, wkbfr); + } + omcStrBuf_destroy(pstrbuf); } DEBUGOUT("ModifyInstance() returning\n"); @@ -815,9 +826,7 @@ CMPIStatus status = {CMPI_RC_OK, NULL}; char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL)); const char *className, *iid; - char *query; int cc; - VMBDBCtx dbctx; char wkbfr[256]; omcStrBuf *pstrbuf; @@ -966,7 +975,6 @@ char *query, err_msg[256]; CMPIData key; int cc; - VMBDBCtx dbctx; DEBUGOUT("DeleteInstance() called...\n"); className = CMGetCharPtr(CMGetClassName(cop, NULL)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-05-09 22:41:33
|
Revision: 604 http://omc.svn.sourceforge.net/omc/?rev=604&view=rev Author: jcarey Date: 2008-05-09 15:41:26 -0700 (Fri, 09 May 2008) Log Message: ----------- dev chk pnt Modified Paths: -------------- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 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-09 16:35:47 UTC (rev 603) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-09 22:41:26 UTC (rev 604) @@ -163,6 +163,120 @@ /*****************************************************************************/ 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); + } +} + +/*****************************************************************************/ +static void +add_u16_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.uint16); + omcStrBuf_cat(pstrbuf, wkbfr, 0); + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } +} + +/*****************************************************************************/ +static void +add_u32_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.uint32); + omcStrBuf_cat(pstrbuf, wkbfr, 0); + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } +} + +/*****************************************************************************/ +static void +add_str_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, + const char* prop_name, int endstmt) +{ + CMPIData data; + const char* pnnfmt; + const char* pnullfmt; + if (endstmt) { + pnnfmt = "%Q"; + pnullfmt = "NULL"; + } else { + pnnfmt = "%Q,"; + pnullfmt = "NULL,"; + } + data = CMGetProperty(instance, prop_name, NULL); + if (!CMIsNullValue(data)) { + char *p = (char*) CMGetCharPtr(data.value.string); + db_sql_insert(pstrbuf, pnnfmt, p); + } else { + omcStrBuf_cat(pstrbuf, pnullfmt, 0); + } +} + +/*****************************************************************************/ +static void +add_stra_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, + const char* prop_name) +{ + CMPIData data = CMGetProperty(instance, prop_name, NULL); + if (!CMIsNullValue(data)) { + omcStrBuf* lstrbuf = stringArray2Str(_broker, data.value.array); + if (lstrbuf) { + db_sql_insert(pstrbuf, "%Q,", lstrbuf->bfr); + omcStrBuf_destroy(lstrbuf); + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } +} + + +/*****************************************************************************/ +static int +instance_on_file(const char* iid, CMPIStatus *pstatus) +{ + int cc; + char *query, err_msg[256]; + VMBDBCtx dbctx; + + OMC_SETSTATUS(_broker, pstatus, CMPI_RC_OK, "No Error"); + query = db_create_formatted_sql("SELECT InstanceID FROM CreationData " + "WHERE InstanceID=%Q", iid); + cc = db_create_select_results(&dbctx, query, err_msg, sizeof(err_msg)); + db_destroy_formatted_sql(query); + if (cc != 0) { + DEBUGOUT("instance_on_file(): Failed to connect to database: %s", + err_msg); + OMC_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM, err_msg); + return -1; + } + cc = db_results_have_more_rows(dbctx); + db_destroy_select_results(dbctx); + return cc; +} + + +/*****************************************************************************/ +static void _fillInstance( VMBDBCtx dbctx, CMPIInstance* instance) @@ -384,114 +498,301 @@ 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) + +/*****************************************************************************/ +static int +get_mod_property(const CMPIInstance* ci, const char* prop_name, const char** properties, + CMPIData* pdata) { - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - return status; + if (properties) { + int i, found = 0; + for (i = 0; properties[i]; i++) { + if (strcasecmp(prop_name, properties[i]) == 0) { + found = 1; + break; + } + } + if (!found) { + return 0; + } + } + *pdata = CMGetProperty(ci, prop_name, NULL); + return 1; } /*****************************************************************************/ -static void -add_u8_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, - const char* prop_name) +void +mod_add_u16_prop(omcStrArray* pstra, const CMPIInstance* modified_instance, + const char* prop_name, const char** properties) { - CMPIData data = CMGetProperty(instance, prop_name, NULL); + char wkbfr[256]; + CMPIData data; + if (!get_mod_property(modified_instance, prop_name, properties, &data)) { + return; + } if (!CMIsNullValue(data)) { - char wkbfr[32]; - snprintf(wkbfr, sizeof(wkbfr), "%u,", data.value.uint8); - omcStrBuf_cat(pstrbuf, wkbfr, 0); + snprintf(wkbfr, sizeof(wkbfr), "%s=%u", prop_name, data.value.uint16); } else { - omcStrBuf_cat(pstrbuf, "NULL,", 0); + snprintf(wkbfr, sizeof(wkbfr), "%s=NULL", prop_name); } + omcStrArray_append(pstra, wkbfr); } /*****************************************************************************/ -static void -add_u16_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, - const char* prop_name) +void +mod_add_str_prop(omcStrArray* pstra, const CMPIInstance* modified_instance, + const char* prop_name, const char** properties) { - CMPIData data = CMGetProperty(instance, prop_name, NULL); + CMPIData data; + if (!get_mod_property(modified_instance, prop_name, properties, &data)) { + return; + } if (!CMIsNullValue(data)) { - char wkbfr[32]; - snprintf(wkbfr, sizeof(wkbfr), "%u,", data.value.uint16); - omcStrBuf_cat(pstrbuf, wkbfr, 0); + char *p = (char*) CMGetCharPtr(data.value.string); + char* sql = db_create_formatted_sql("%s=%Q", prop_name, p); + omcStrArray_append(pstra, sql); + db_destroy_formatted_sql(sql); } else { - omcStrBuf_cat(pstrbuf, "NULL,", 0); + char wkbfr[256]; + snprintf(wkbfr, sizeof(wkbfr), "%s=NULL", prop_name); + omcStrArray_append(pstra, wkbfr); } } /*****************************************************************************/ -static void -add_u32_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, - const char* prop_name) +void +mod_add_stra_prop(omcStrArray* pstra, const CMPIInstance* modified_instance, + const char* prop_name, const char** properties) { - CMPIData data = CMGetProperty(instance, prop_name, NULL); + CMPIData data; + if (!get_mod_property(modified_instance, prop_name, properties, &data)) { + return; + } if (!CMIsNullValue(data)) { - char wkbfr[32]; - snprintf(wkbfr, sizeof(wkbfr), "%u,", data.value.uint32); - omcStrBuf_cat(pstrbuf, wkbfr, 0); + omcStrBuf* lstrbuf = stringArray2Str(_broker, data.value.array); + if (lstrbuf) { + char* sql = db_create_formatted_sql("%s=%Q", prop_name, lstrbuf->bfr); + omcStrBuf_destroy(lstrbuf); + omcStrArray_append(pstra, sql); + db_destroy_formatted_sql(sql); + } else { + char wkbfr[256]; + snprintf(wkbfr, sizeof(wkbfr), "%s=NULL", prop_name); + omcStrArray_append(pstra, wkbfr); + } } else { - omcStrBuf_cat(pstrbuf, "NULL,", 0); + char wkbfr[256]; + snprintf(wkbfr, sizeof(wkbfr), "%s=NULL", prop_name); + omcStrArray_append(pstra, wkbfr); } } /*****************************************************************************/ -static void -add_str_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, - const char* prop_name, int endstmt) +void +mod_add_u32_prop(omcStrArray* pstra, const CMPIInstance* modified_instance, + const char* prop_name, const char** properties) { + char wkbfr[256]; CMPIData data; - const char* pnnfmt; - const char* pnullfmt; - if (endstmt) { - pnnfmt = "%Q"; - pnullfmt = "NULL"; - } else { - pnnfmt = "%Q,"; - pnullfmt = "NULL,"; + if (!get_mod_property(modified_instance, prop_name, properties, &data)) { + return; } - data = CMGetProperty(instance, prop_name, NULL); if (!CMIsNullValue(data)) { - char *p = (char*) CMGetCharPtr(data.value.string); - db_sql_insert(pstrbuf, pnnfmt, p); + snprintf(wkbfr, sizeof(wkbfr), "%s=%u", prop_name, data.value.uint32); } else { - omcStrBuf_cat(pstrbuf, pnullfmt, 0); + snprintf(wkbfr, sizeof(wkbfr), "%s=NULL", prop_name); } + omcStrArray_append(pstra, wkbfr); } -/*****************************************************************************/ -static void -add_stra_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, - const char* prop_name) +/****************************************************************************** +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* modified_instance, + const char** properties) { - CMPIData data = CMGetProperty(instance, prop_name, NULL); - if (!CMIsNullValue(data)) { - omcStrBuf* lstrbuf = stringArray2Str(_broker, data.value.array); - if (lstrbuf) { - db_sql_insert(pstrbuf, "%Q,", lstrbuf->bfr); - omcStrBuf_destroy(lstrbuf); - } else { - omcStrBuf_cat(pstrbuf, "NULL,", 0); + CMPIStatus status = {CMPI_RC_OK, NULL}; + const char *className, *iid; + char *query, wkbfr[256]; + CMPIData key, data; + int cc, prop_cnt, cur_prop_cnt = 0; + VMBDBCtx dbctx; + omcStrBuf *pstrbuf; + omcStrArray *pstra; + + DEBUGOUT("ModifyInstance() called...\n"); + if (properties) { + for (prop_cnt = 0; properties[prop_cnt]; prop_cnt++) { + /* empty */ } + if (!prop_cnt) { + DEBUGOUT("ModifyInstance() empty prop list. Did Nothing\n"); + return status; + } } else { - omcStrBuf_cat(pstrbuf, "NULL,", 0); + prop_cnt = CMGetPropertyCount(modified_instance, &status); + if (status.rc != CMPI_RC_OK) { + DEBUGOUT("ModifyInstance(): Get Property Count return %d\n", status.rc); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, + "CMGetPropertyCount failed"); + return status; + } } + + if (properties && !properties[0]) { + DEBUGOUT("ModifyInstance() empty prop list. Did Nothing\n"); + return status; + } + + className = CMGetCharPtr(CMGetClassName(cop, NULL)); + if (strcasecmp(className, "XEN_VMBuilderVirtualSystemCreationData") == 0) + { + key = CMGetKey(cop, "InstanceID", &status); + if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) { + DEBUGOUT("ModifyInstance(): CMGetKey(\"InstanceID\") failed - %d\n", status.rc); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Cannot get InstanceID property"); + return status; + } + + iid = CMGetCharPtr(key.value.string); + if (!iid || !strlen(iid)) { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty InstanceID property"); + return status; + } + if ((cc = instance_on_file(iid, &status)) < 0) { + return status; + } + if (!cc) { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Instance Not Found"); + return status; + } + + pstra = omcStrArray_create(); + if (!pstra) { + CMSetStatusWithChars(_broker, &status, CMPI_RC_ERROR_SYSTEM, + "Failed to create string array"); + return status; + } + + pstrbuf = omcStrBuf_create(); + if (!pstrbuf) { + CMSetStatusWithChars(_broker, &status, CMPI_RC_ERROR_SYSTEM, + "Failed to create string buffer"); + omcStrArray_destroy(pstra); + return status; + } + + mod_add_u16_prop(pstra, modified_instance, "AutoMaticRecoveryAction", properties); + mod_add_u16_prop(pstra, modified_instance, "AutoMaticShutdownAction", properties); + mod_add_u16_prop(pstra, modified_instance, "AutoMaticStartupAction", properties); + if (get_mod_property(modified_instance, "AutoMaticStartupActionDelay", properties, &data)) { + if (!CMIsNullValue(data)) { + if (!CMIsInterval(data.value.dateTime, &status)) { + CMSetStatusWithChars(_broker, &status, + CMPI_RC_ERR_INVALID_PARAMETER, + "'AutoMaticStartupActionDelay' must be an interval"); + omcStrBuf_destroy(pstrbuf); + omcStrArray_destroy(pstra); + return status; + } + CMPIUint64 wku64 = CMGetBinaryFormat(data.value.dateTime, &status); + snprintf(wkbfr, sizeof(wkbfr), "AutoMaticStartupActionDelay=%llu", wku64); + omcStrArray_append(pstra, wkbfr); + } else { + omcStrArray_append(pstra, "AutoMaticStartupActionDelay=NULL"); + } + } + mod_add_u16_prop(pstra, modified_instance, "AutoMaticStartupAction", properties); + mod_add_str_prop(pstra, modified_instance, "CPUArchitecture", properties); + mod_add_str_prop(pstra, modified_instance, "Caption", properties); + mod_add_u16_prop(pstra, modified_instance, "ChangeableType", properties); + mod_add_str_prop(pstra, modified_instance, "ConfigurationDataRoot", properties); + mod_add_str_prop(pstra, modified_instance, "ConfigurationFile", properties); + mod_add_str_prop(pstra, modified_instance, "ConfigurationID", properties); + mod_add_str_prop(pstra, modified_instance, "ConfigurationName", properties); + if (get_mod_property(modified_instance, "CreationTime", properties, &data)) { + if (!CMIsNullValue(data)) { + if (CMIsInterval(data.value.dateTime, &status)) { + CMSetStatusWithChars(_broker, &status, + CMPI_RC_ERR_INVALID_PARAMETER, + "'CreationTime' cannot be an interval"); + omcStrBuf_destroy(pstrbuf); + omcStrArray_destroy(pstra); + return status; + } + CMPIUint64 wku64 = CMGetBinaryFormat(data.value.dateTime, &status); + snprintf(wkbfr, sizeof(wkbfr), "CreationTime=%llu", wku64); + omcStrArray_append(pstra, wkbfr); + } else { + omcStrArray_append(pstra, "CreationTime=NULL"); + } + } + mod_add_str_prop(pstra, modified_instance, "Description", properties); + mod_add_stra_prop(pstra, modified_instance, "Disks", properties); + mod_add_str_prop(pstra, modified_instance, "ElementName", properties); + mod_add_stra_prop(pstra, modified_instance, "ExtraConfigInfo", properties); + mod_add_str_prop(pstra, modified_instance, "ExtraInstallArgs", properties); + mod_add_u32_prop(pstra, modified_instance, "GraphicsType", properties); + mod_add_u32_prop(pstra, modified_instance, "GraphicsViewerType", properties); + mod_add_str_prop(pstra, modified_instance, "LogDataRoot", properties); + + mod_add_u32_prop(pstra, modified_instance, "MaxMemory", properties); + mod_add_u32_prop(pstra, modified_instance, "Memory", properties); + +/* + + + omcStrBuf_cat(pstrbuf, "UPDATE CreationData SET ", 0); + + + + get_mod_property(modified_instance, "Nics", properties, &data) + get_mod_property(modified_instance, "Notes", properties, &data) + get_mod_property(modified_instance, "NumVCPUs", properties, &data) + get_mod_property(modified_instance, "OSType", properties, &data) + get_mod_property(modified_instance, "RecoveryFile", properties, &data) + get_mod_property(modified_instance, "ResponseFile", properties, &data) + get_mod_property(modified_instance, "SnapshotDataRoot", properties, &data) + get_mod_property(modified_instance, "SourceURL", properties, &data) + get_mod_property(modified_instance, "SuspendDataRoot", properties, &data) + get_mod_property(modified_instance, "SwapFileDataRoot", properties, &data) + get_mod_property(modified_instance, "UUID", properties, &data) + get_mod_property(modified_instance, "VNCPort", properties, &data) + get_mod_property(modified_instance, "VirtType", properties, &data) + get_mod_property(modified_instance, "VirtualSystemIdentifier", properties, &data) + get_mod_property(modified_instance, "VirtualSystemType", properties, &data) + + +*/ + + + + + + + + + + + + + + } + + DEBUGOUT("ModifyInstance() returning\n"); + return status; } /****************************************************************************** @@ -535,18 +836,9 @@ return status; } - query = db_create_formatted_sql("SELECT InstanceID FROM CreationData " - "WHERE InstanceID=%Q;", iid); - cc = db_create_select_results(&dbctx, query, wkbfr, sizeof(wkbfr)); - db_destroy_formatted_sql(query); - if (cc != 0) { - DEBUGOUT("CreateInstance(): Failed to connect to database: %s", - wkbfr); - OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, wkbfr); + if ((cc = instance_on_file(iid, &status)) < 0) { return status; } - cc = db_results_have_more_rows(dbctx); - db_destroy_select_results(dbctx); if (cc) { /* Got hit on InstanceID - Already on file */ CMSetStatus(&status, CMPI_RC_ERR_ALREADY_EXISTS); @@ -692,29 +984,21 @@ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty InstanceID property"); return status; } - - query = db_create_formatted_sql("SELECT InstanceID FROM CreationData " - "WHERE InstanceID=%Q", iid); - cc = db_create_select_results(&dbctx, query, err_msg, sizeof(err_msg)); - db_destroy_formatted_sql(query); - if (cc != 0) { - DEBUGOUT("DeleteInstance(): Failed to connect to database: %s", - err_msg); - OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg); + if ((cc = instance_on_file(iid, &status)) < 0) { return status; } - cc = db_results_have_more_rows(dbctx); - db_destroy_select_results(dbctx); if (!cc) { OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Instance Not Found"); return status; } + query = db_create_formatted_sql("DELETE FROM CreationData WHERE InstanceID=%Q", iid); if (db_exec(query, err_msg, sizeof(err_msg)) < 0LL) { DEBUGOUT("DeleteInstance(): failed deleting record from " "database: %s", err_msg); OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg); } + db_destroy_formatted_sql(query); } DEBUGOUT("DeleteInstance() returning\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-05-09 16:35:50
|
Revision: 603 http://omc.svn.sourceforge.net/omc/?rev=603&view=rev Author: jcarey Date: 2008-05-09 09:35:47 -0700 (Fri, 09 May 2008) Log Message: ----------- Implemented delete instance Modified Paths: -------------- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 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-08 23:36:59 UTC (rev 602) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-09 16:35:47 UTC (rev 603) @@ -243,7 +243,7 @@ char err_msg[256]; char* iid; - cc = db_create_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", @@ -535,7 +535,7 @@ return status; } - query = db_create_formatted_sql("Select InstanceID from CreationData " + query = db_create_formatted_sql("SELECT InstanceID FROM CreationData " "WHERE InstanceID=%Q;", iid); cc = db_create_select_results(&dbctx, query, wkbfr, sizeof(wkbfr)); db_destroy_formatted_sql(query); @@ -650,6 +650,7 @@ omcStrBuf_destroy(pstrbuf); } + DEBUGOUT("CreateInstance() returning\n"); return status; } @@ -668,7 +669,55 @@ const CMPIResult* results, const CMPIObjectPath* cop) { - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; + CMPIStatus status = {CMPI_RC_OK, NULL}; + const char *className, *iid; + char *query, err_msg[256]; + CMPIData key; + int cc; + VMBDBCtx dbctx; + + DEBUGOUT("DeleteInstance() called...\n"); + className = CMGetCharPtr(CMGetClassName(cop, NULL)); + if (strcasecmp(className, "XEN_VMBuilderVirtualSystemCreationData") == 0) + { + key = CMGetKey(cop, "InstanceID", &status); + if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) { + DEBUGOUT("DeleteInstance(): CMGetKey(\"InstanceID\") failed - %d\n", status.rc); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Cannot get InstanceID property"); + return status; + } + + iid = CMGetCharPtr(key.value.string); + if (!iid || !strlen(iid)) { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty InstanceID property"); + return status; + } + + query = db_create_formatted_sql("SELECT InstanceID FROM CreationData " + "WHERE InstanceID=%Q", iid); + cc = db_create_select_results(&dbctx, query, err_msg, sizeof(err_msg)); + db_destroy_formatted_sql(query); + if (cc != 0) { + DEBUGOUT("DeleteInstance(): Failed to connect to database: %s", + err_msg); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg); + return status; + } + cc = db_results_have_more_rows(dbctx); + db_destroy_select_results(dbctx); + if (!cc) { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Instance Not Found"); + return status; + } + query = db_create_formatted_sql("DELETE FROM CreationData WHERE InstanceID=%Q", iid); + if (db_exec(query, err_msg, sizeof(err_msg)) < 0LL) { + DEBUGOUT("DeleteInstance(): failed deleting record from " + "database: %s", err_msg); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, err_msg); + } + } + + DEBUGOUT("DeleteInstance() returning\n"); 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-08 23:36:54
|
Revision: 602 http://omc.svn.sourceforge.net/omc/?rev=602&view=rev Author: jcarey Date: 2008-05-08 16:36:59 -0700 (Thu, 08 May 2008) Log Message: ----------- Prog reg and CreateInstance working Modified Paths: -------------- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c Added Paths: ----------- contrib/xen-vm-builder/trunk/mof/vmcreation-data-peg.reg Added: contrib/xen-vm-builder/trunk/mof/vmcreation-data-peg.reg =================================================================== --- contrib/xen-vm-builder/trunk/mof/vmcreation-data-peg.reg (rev 0) +++ contrib/xen-vm-builder/trunk/mof/vmcreation-data-peg.reg 2008-05-08 23:36:59 UTC (rev 602) @@ -0,0 +1,29 @@ +instance of PG_ProviderModule +{ + Name = "XEN_VMBuilderVirtualSystemCreationData_Module"; + Location = "omc_xencreationdata"; + Vendor = "OMC"; + Version = "1.0.0"; + InterfaceType = "CMPI"; + InterfaceVersion = "2.0.0"; +}; + +instance of PG_Provider +{ + ProviderModuleName = "XEN_VMBuilderVirtualSystemCreationData_Module"; + Name = "omc_xencreationdata"; +}; + +instance of PG_ProviderCapabilities +{ + ProviderModuleName = "XEN_VMBuilderVirtualSystemCreationData_Module"; + ProviderName = "omc_xencreationdata"; + CapabilityID = "XEN_VMBuilderVirtualSystemCreationData0001"; + ClassName = "XEN_VMBuilderVirtualSystemCreationData"; + Namespaces = {"root/cimv2"}; + ProviderType = { 2 }; // Instance + SupportedProperties = NULL; // All properties + SupportedMethods = NULL; // All methods +}; + + 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-08 22:20:17 UTC (rev 601) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-05-08 23:36:59 UTC (rev 602) @@ -39,7 +39,7 @@ //-- 1: Changable (transient) //-- 2: Changable (persistent) //-- 3: Not changable (transient) - "ChangableType INTEGER," + "ChangeableType INTEGER," "ConfigurationDataRoot TEXT," "ConfigurationFile TEXT," "ConfigurationID TEXT," 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-08 22:20:17 UTC (rev 601) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-08 23:36:59 UTC (rev 602) @@ -76,7 +76,7 @@ "AutoMaticStartupActionSequenceNumber," \ "CPUArchitecture," \ "Caption," \ - "ChangableType," \ + "ChangeableType," \ "ConfigurationDataRoot," \ "ConfigurationFile," \ "ConfigurationID," \ @@ -177,7 +177,7 @@ "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_u16_prop(dbctx, CDF_ChangableType, instance, "ChangeableType"); set_str_prop(dbctx, CDF_ConfigurationDataRoot, instance, "ConfigurationDataRoot"); set_str_prop(dbctx, CDF_ConfigurationFile, instance, "ConfigurationFile"); set_str_prop(dbctx, CDF_ConfigurationID, instance, "ConfigurationID"); @@ -348,9 +348,9 @@ className = CMGetCharPtr(CMGetClassName(cop, NULL)); if (strcasecmp(className, "XEN_VMBuilderVirtualSystemCreationData") == 0) { - key = CMGetKey(cop, "InstancdID", &status); + key = CMGetKey(cop, "InstanceID", &status); if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) { - DEBUGOUT("GetInstance(): CMGetKey(\"InstanceID\") failed - %s\n", CMGetCharPtr(status.msg)); + DEBUGOUT("GetInstance(): CMGetKey(\"InstanceID\") failed - %d\n", status.rc); OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Cannot get InstanceID property"); return status; } @@ -558,7 +558,7 @@ "Failed to create string buffer"); return status; } - omcStrBuf_cat(pstrbuf, "INSERT INFO CreationData (", 0); + omcStrBuf_cat(pstrbuf, "INSERT INTO CreationData (", 0); omcStrBuf_cat(pstrbuf, CSV_FIELDS, 0); omcStrBuf_cat(pstrbuf, ") VALUES (", 0); db_sql_insert(pstrbuf, "%Q,", iid); @@ -587,7 +587,7 @@ add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupActionSequenceNumber"); add_str_prop_to_query(pstrbuf, newinstance, "CPUArchitecture", 0); add_str_prop_to_query(pstrbuf, newinstance, "Caption", 0); - add_u16_prop_to_query(pstrbuf, newinstance, "ChangableType"); + add_u16_prop_to_query(pstrbuf, newinstance, "ChangeableType"); add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationDataRoot", 0); add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationFile", 0); add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationID", 0); 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); + } +} + +/*****************************************************************************/ +static void +add_u16_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.uint16); + omcStrBuf_cat(pstrbuf, wkbfr, 0); + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } +} + +/*****************************************************************************/ +static void +add_u32_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.uint32); + omcStrBuf_cat(pstrbuf, wkbfr, 0); + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } +} + +/*****************************************************************************/ +static void +add_str_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, + const char* prop_name, int endstmt) +{ + CMPIData data; + const char* pnnfmt; + const char* pnullfmt; + if (endstmt) { + pnnfmt = "%Q"; + pnullfmt = "NULL"; + } else { + pnnfmt = "%Q,"; + pnullfmt = "NULL,"; + } + data = CMGetProperty(instance, prop_name, NULL); + if (!CMIsNullValue(data)) { + char *p = (char*) CMGetCharPtr(data.value.string); + db_sql_insert(pstrbuf, pnnfmt, p); + } else { + omcStrBuf_cat(pstrbuf, pnullfmt, 0); + } +} + +/*****************************************************************************/ +static void +add_stra_prop_to_query(omcStrBuf* pstrbuf, const CMPIInstance* instance, + const char* prop_name) +{ + CMPIData data = CMGetProperty(instance, prop_name, NULL); + if (!CMIsNullValue(data)) { + omcStrBuf* lstrbuf = stringArray2Str(_broker, data.value.array); + if (lstrbuf) { + db_sql_insert(pstrbuf, "%Q,", lstrbuf->bfr); + omcStrBuf_destroy(lstrbuf); + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } +} + /****************************************************************************** CreateInstance() params: CMPIInstanceMI* self: [in] Handle to this provider @@ -559,7 +510,146 @@ const CMPIObjectPath* cop, const CMPIInstance* newinstance) { - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; + CMPIData data; + CMPIStatus status = {CMPI_RC_OK, NULL}; + char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL)); + const char *className, *iid; + char *query; + int cc; + VMBDBCtx dbctx; + char wkbfr[256]; + omcStrBuf *pstrbuf; + + DEBUGOUT("CreateInstance() called\n"); + + className = CMGetCharPtr(CMGetClassName(cop, NULL)); + if (strcasecmp(className, "XEN_VMBuilderVirtualSystemCreationData") == 0) { + iid = NULL; + data = CMGetProperty(newinstance, "InstanceID", NULL); + if (!CMIsNullValue(data)) { + iid = CMGetCharPtr(data.value.string); + } + if (!iid || !strlen(iid)) { + CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, + "'InstanceID' is a required property"); + return status; + } + + query = db_create_formatted_sql("Select InstanceID from CreationData " + "WHERE InstanceID=%Q;", iid); + cc = db_create_select_results(&dbctx, query, wkbfr, sizeof(wkbfr)); + db_destroy_formatted_sql(query); + if (cc != 0) { + DEBUGOUT("CreateInstance(): Failed to connect to database: %s", + wkbfr); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, wkbfr); + return status; + } + cc = db_results_have_more_rows(dbctx); + db_destroy_select_results(dbctx); + if (cc) { + /* Got hit on InstanceID - Already on file */ + CMSetStatus(&status, CMPI_RC_ERR_ALREADY_EXISTS); + return status; + } + pstrbuf = omcStrBuf_create(); + if (!pstrbuf) { + CMSetStatusWithChars(_broker, &status, CMPI_RC_ERROR_SYSTEM, + "Failed to create string buffer"); + return status; + } + omcStrBuf_cat(pstrbuf, "INSERT INFO CreationData (", 0); + omcStrBuf_cat(pstrbuf, CSV_FIELDS, 0); + omcStrBuf_cat(pstrbuf, ") VALUES (", 0); + db_sql_insert(pstrbuf, "%Q,", iid); + + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticRecoveryAction"); + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticShutdownAction"); + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupAction"); + + data = CMGetProperty(newinstance, "AutoMaticStartupActionDelay", NULL); + if (!CMIsNullValue(data)) { + if (!CMIsInterval(data.value.dateTime, &status)) { + CMSetStatusWithChars(_broker, &status, + CMPI_RC_ERR_INVALID_PARAMETER, + "'AutoMaticStartupActionDelay' must be an interval"); + omcStrBuf_destroy(pstrbuf); + return status; + } + CMPIUint64 wku64 = CMGetBinaryFormat(data.value.dateTime, &status); + snprintf(wkbfr, sizeof(wkbfr), "%llu,", wku64); + omcStrBuf_cat(pstrbuf, wkbfr, 0); + + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } + + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupActionSequenceNumber"); + add_str_prop_to_query(pstrbuf, newinstance, "CPUArchitecture", 0); + add_str_prop_to_query(pstrbuf, newinstance, "Caption", 0); + add_u16_prop_to_query(pstrbuf, newinstance, "ChangableType"); + add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationDataRoot", 0); + add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationFile", 0); + add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationID", 0); + add_str_prop_to_query(pstrbuf, newinstance, "ConfigurationName", 0); + + data = CMGetProperty(newinstance, "CreationTime", NULL); + if (!CMIsNullValue(data)) { + if (CMIsInterval(data.value.dateTime, &status)) { + CMSetStatusWithChars(_broker, &status, + CMPI_RC_ERR_INVALID_PARAMETER, + "'CreationTime' cannot be an interval"); + omcStrBuf_destroy(pstrbuf); + return status; + } + CMPIUint64 wku64 = CMGetBinaryFormat(data.value.dateTime, &status); + snprintf(wkbfr, sizeof(wkbfr), "%llu,", wku64); + omcStrBuf_cat(pstrbuf, wkbfr, 0); + + } else { + omcStrBuf_cat(pstrbuf, "NULL,", 0); + } + + add_str_prop_to_query(pstrbuf, newinstance, "Description", 0); + add_stra_prop_to_query(pstrbuf, newinstance, "Disks"); + add_str_prop_to_query(pstrbuf, newinstance, "ElementName", 0); + add_stra_prop_to_query(pstrbuf, newinstance, "ExtraConfigInfo"); + add_str_prop_to_query(pstrbuf, newinstance, "ExtraInstallArgs", 0); + add_u32_prop_to_query(pstrbuf, newinstance, "GraphicsType"); + add_u32_prop_to_query(pstrbuf, newinstance, "GraphicsViewerType"); + add_str_prop_to_query(pstrbuf, newinstance, "LogDataRoot", 0); + add_u32_prop_to_query(pstrbuf, newinstance, "MaxMemory"); + add_u32_prop_to_query(pstrbuf, newinstance, "Memory"); + add_stra_prop_to_query(pstrbuf, newinstance, "Nics"); + add_stra_prop_to_query(pstrbuf, newinstance, "Notes"); + add_u8_prop_to_query(pstrbuf, newinstance, "NumVCPUs"); + add_u32_prop_to_query(pstrbuf, newinstance, "OSType"); + add_str_prop_to_query(pstrbuf, newinstance, "RecoveryFile", 0); + add_str_prop_to_query(pstrbuf, newinstance, "ResponseFile", 0); + add_str_prop_to_query(pstrbuf, newinstance, "SnapshotDataRoot", 0); + add_str_prop_to_query(pstrbuf, newinstance, "SourceURL", 0); + add_str_prop_to_query(pstrbuf, newinstance, "SuspendDataRoot", 0); + add_str_prop_to_query(pstrbuf, newinstance, "SwapFileDataRoot", 0); + add_str_prop_to_query(pstrbuf, newinstance, "UUID", 0); + add_u32_prop_to_query(pstrbuf, newinstance, "VNCPort"); + add_u32_prop_to_query(pstrbuf, newinstance, "VirtType"); + add_str_prop_to_query(pstrbuf, newinstance, "VirtualSystemIdentifier", 0); + add_str_prop_to_query(pstrbuf, newinstance, "VirtualSystemType", 1); + omcStrBuf_cat(pstrbuf, ");", 0); + + if (db_exec(pstrbuf->bfr, wkbfr, sizeof(wkbfr)) < 0LL) { + DEBUGOUT("CreateInstance(): failed inserting record into " + "database: %s", wkbfr); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, wkbfr); + } else { + CMPIObjectPath* ref = CMGetObjectPath(newinstance, NULL); + CMSetNameSpace(ref, ns); + CMReturnObjectPath(results, ref); + CMReturnDone(results); + } + omcStrBuf_destroy(pstrbuf); + } + return status; } @@ -716,17 +806,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 @@ -736,9 +822,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"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-05-07 21:11:29
|
Revision: 600 http://omc.svn.sourceforge.net/omc/?rev=600&view=rev Author: jcarey Date: 2008-05-07 14:11:21 -0700 (Wed, 07 May 2008) Log Message: ----------- Implemented GetInstance for CreationData Modified Paths: -------------- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 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:22:58 UTC (rev 599) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-05-07 21:11:21 UTC (rev 600) @@ -68,6 +68,49 @@ #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 " + "WHERE InstanceID=%Q;"; + const char* all_cd_fields_query = "SELECT " "InstanceID," "AutoMaticRecoveryAction," @@ -152,51 +195,6 @@ 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 @@ -470,19 +468,54 @@ 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)); - const char *className; + char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL)); + const char *className, *iid; + char *query; + CMPIData key; + int cc; + VMBDBCtx dbctx; + char err_msg[256]; 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"); + key = CMGetKey(cop, "InstancdID", &status); + if (status.rc != CMPI_RC_OK || CMIsNullValue(key)) { + DEBUGOUT("GetInstance(): CMGetKey(\"InstanceID\") failed - %s\n", CMGetCharPtr(status.msg)); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Cannot get InstanceID property"); + return status; + } + + iid = CMGetCharPtr(key.value.string); + if (!iid || strlen(iid) == 0) { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Empty InstanceID property"); + return status; + } + + query = db_create_formatted_sql(all_cd_fields_query_with_where, iid); + cc = db_create_select_results(&dbctx, query, err_msg, sizeof(err_msg)); + db_destroy_formatted_sql(query); + if (cc != 0) { + DEBUGOUT("GetInstance(): Failed to connect to database: %s", + 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_VMBuilderVirtualSystemCreationData", + creation_data_keys, properties, &status); + _fillInstance(dbctx, instance); + CMReturnInstance(results, instance); + } + else { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, "Instance Not Found"); + } + db_destroy_select_results(dbctx); } DEBUGOUT("Leaving GetInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed"); 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-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-07 20:14:21
|
Revision: 598 http://omc.svn.sourceforge.net/omc/?rev=598&view=rev Author: jcarey Date: 2008-05-07 13:14:16 -0700 (Wed, 07 May 2008) Log Message: ----------- Added string array/buffer functions Modified Paths: -------------- omccmpi/trunk/src/include/omc/string.h omccmpi/trunk/src/lib/omc/string.c Modified: omccmpi/trunk/src/include/omc/string.h =================================================================== --- omccmpi/trunk/src/include/omc/string.h 2008-05-05 15:10:58 UTC (rev 597) +++ omccmpi/trunk/src/include/omc/string.h 2008-05-07 20:14:16 UTC (rev 598) @@ -165,6 +165,133 @@ */ char** omcStrTokenize(const char* src, const char* delims, size_t* numberOfElements); +/** + * omcStrBuf represent a dynamic string buffer. It is created/destroyed/manipulted + * by the omcStrBuf_xxx set of functions that follow. + */ +typedef struct { + size_t buf_len; + size_t str_len; + char* bfr; +} omcStrBuf; + +/** + * Create an initialized omcStrBuf object. + * @return A pointer to an initialized omcStrBuf object. This pointer must + * eventually be destroyed by calling omcStrBuf_destroy. This function will + * return NULL on failure. + */ +omcStrBuf* omcStrBuf_create(); + +/** + * Destroy an omcStrBuf object and release the allocated memory associated with it. + * @param psbuf A pointer to the omcStrBuf object to be destroyed. + * @return 0 for success. Otherwise -1 + */ +int omcStrBuf_destroy(omcStrBuf* psbuf); + +/** + * Append a string to the string represented by a given omcStrBuf object. + * @param psbuf The omcStrBuf object to append the string to. + * @param str A the string to append to the given omcStrBuf object. + * @param n The number of character of str to append to the given + * omcStrBuf object. If this parameter is 0, then all of str will + * be appended. + * @return A pointer to the modified string or NULL on failure. + */ +const char* omcStrBuf_cat(omcStrBuf* psbuf, const char* str, size_t n); + +/** + * Set the omcStrBuf object to a given string. + * @param psbuf The omcStrBuf object to set. + * @param str A the string to set the given omcStrBuf object to. + * @param n The number of character of str to set the given + * omcStrBuf object to. If this parameter is 0, then all of str will + * be used. + * @return A pointer to the string represented by the omcStrBuf object, + * or NULL on failure. + */ +const char* omcStrBuf_set(omcStrBuf* psbuf, const char* str, size_t n); + +/** + * Reset a given omcStrBuf object to an empty string. + * @param psbuf The omcStrBuf object to reset. + * @return 0 on success. Otherwise -1. + */ +int omcStrBuf_reset(omcStrBuf* psbuf); + +/** + * omcStrArray represent a dynamic string array. It is created/destroyed/manipulated + * by the omcStrArray_xxx set of functions that follow. + */ +typedef struct { + size_t num_strings; + size_t buf_size; + char** strs; +} omcStrArray; + +/** + * Create/initialize an omcStrArray object. + * @return A pointer to the newly created/initialized omcStrArray object. + * This pointer will be used in all subsequent calls to omcStrArray_xxx + * functions and must eventually be passed to omcStrArray_destroy() + */ +omcStrArray* omcStrArray_create(); + +/** + * Destroy an omcStrArray object and release all resources associated with it. + * @param pra The pointer to the omcStrArray object to destroy. + * @return 0 on success. Otherwise -1 on error. + */ +int omcStrArray_destroy(omcStrArray* pra); + +/** + * Append a string to the string array represented by a given omcStrArray + * object. + * @param pra A pointer to an omcStrArray object to append the string to. + * @param str The string to append to the omcStrArray + * @return A pointer to the omcStrArray on success or NULL on failure + */ +omcStrArray* omcStrArray_append(omcStrArray* pra, const char* str); + +/** + * Determine the number of strings contained by a given omcStrArray object. + * @param pra A pointer to an omcStrArray object to get the number of + * strings from. + * @return The number of strings contained by the given omcStrArray object, + * or -1 on error. + */ +int omcStrArray_size(omcStrArray* pra); + +/** + * Reset/Clear a given omcStrArray object. After this call the omcStrArray + * object will not contain any strings. + * @param pra A pointer to the omcStrArray object to reset. + * @return 0 on success. Otherwise -1. + */ +int omcStrArray_reset(omcStrArray* pra); + +/** + * Set an element within an omcStrArray object to a given string. + * @param pra A pointer to the omcStrArray object to set the + * element in. + * @param str The string to set the given element to. + * @param ndx The array index of the element to set. This is zero relative, + * and must be less than the values returned by omcStrArray_size() + * @return A pointer to the omcStrArray just modified on success, or + * NULL on failure. + */ +omcStrArray* omcStrArray_set_element(omcStrArray* pra, const char* str, size_t ndx); + +/** + * Get an element within an omcStrArray object. + * @param pra A pointer to the omcStrArray object to get the string from. + * @param ndx The index of the string to retrieve within the given omcStrArray. + * @return A pointer to the string specified by ndx on success, or + * NULL on failure. + */ +const char* omcStrArray_get_element(omcStrArray* pra, size_t ndx); + #ifdef __cplusplus } #endif Modified: omccmpi/trunk/src/lib/omc/string.c =================================================================== --- omccmpi/trunk/src/lib/omc/string.c 2008-05-05 15:10:58 UTC (rev 597) +++ omccmpi/trunk/src/lib/omc/string.c 2008-05-07 20:14:16 UTC (rev 598) @@ -296,3 +296,270 @@ return dest; } +/*****************************************************************************/ +omcStrArray* +omcStrArray_create() +{ + omcStrArray* pra = (omcStrArray*)calloc(1, sizeof(omcStrArray)); + if (!pra) { + errno = ENOMEM; + return NULL; + } + pra->strs = (char**) calloc(16, sizeof(char*)); + if (!pra->strs) { + free(pra); + errno = ENOMEM; + return NULL; + } + pra->buf_size = 16; + return pra; +} + +/*****************************************************************************/ +int +omcStrArray_destroy(omcStrArray* pra) +{ + size_t nstrs; + + if (!pra) { + errno = EINVAL; + return -1; + } + + for(nstrs = 0; nstrs < pra->num_strings; nstrs++) { + if (pra->strs[nstrs]) { + free(pra->strs[nstrs]); + } + } + free(pra->strs); + free(pra); + return 0; +} + +/*****************************************************************************/ +omcStrArray* +omcStrArray_append(omcStrArray* pra, const char* str) +{ + int slen = strlen(str); + if (!pra) { + errno = EINVAL; + return NULL; + } + if (pra->num_strings == pra->buf_size-1) { + size_t nsize = pra->buf_size + 16; + char** nbuf = (char**) calloc(nsize, sizeof(char*)); + if (!nbuf) { + errno = ENOMEM; + return NULL; + } + memcpy(nbuf, pra->strs, sizeof(char*) * pra->num_strings); + free(pra->strs); + pra->strs = nbuf; + pra->buf_size = nsize; + } + pra->strs[pra->num_strings] = (char*) malloc(slen+1); + if (!pra->strs[pra->num_strings]) { + errno = ENOMEM; + return NULL; + } + strcpy(pra->strs[pra->num_strings], str); + pra->num_strings++; + return pra; +} + +/*****************************************************************************/ +int +omcStrArray_size(omcStrArray* pra) +{ + if (!pra) { + errno = EINVAL; + return -1; + } + return (int)pra->num_strings; +} + +/*****************************************************************************/ +int +omcStrArray_reset(omcStrArray* pra) +{ + size_t nstrs; + + if (!pra) { + errno = EINVAL; + return -1; + } + + for(nstrs = 0; nstrs < pra->num_strings; nstrs++) { + if (pra->strs[nstrs]) { + free(pra->strs[nstrs]); + pra->strs[nstrs] = NULL; + } + } + pra->num_strings = 0; + return 0; +} + +/*****************************************************************************/ +omcStrArray* +omcStrArray_set_element(omcStrArray* pra, const char* str, size_t ndx) +{ + int argslen = strlen(str); + + if (!pra) { + errno = EINVAL; + return NULL; + } + if (ndx >= pra->num_strings || !str) { + errno = EINVAL; + return NULL; + } + + if (argslen > strlen(pra->strs[ndx])) { + free(pra->strs[ndx]); + pra->strs[ndx] = (char*) malloc(argslen+1); + if (!pra->strs[ndx]) { + errno = ENOMEM; + return NULL; + } + } + strcpy(pra->strs[ndx], str); + return pra; +} + +/*****************************************************************************/ +const char* +omcStrArray_get_element(omcStrArray* pra, size_t ndx) +{ + if (!pra || ndx >= pra->num_strings) { + errno = EINVAL; + return NULL; + } + return pra->strs[ndx]; +} + +/*****************************************************************************/ +omcStrBuf* +omcStrBuf_create() +{ + omcStrBuf* psbuf = (omcStrBuf*) malloc(sizeof(omcStrBuf)); + if (!psbuf) { + errno = ENOMEM; + return NULL; + } + psbuf->bfr = (char*) malloc(512); + psbuf->bfr[0] = 0; + psbuf->buf_len = 512; + psbuf->str_len = 0; + return psbuf; +} + +/*****************************************************************************/ +const char* +omcStrBuf_cat(omcStrBuf* psbuf, const char* str, size_t n) +{ + size_t slen; + + if (!psbuf) { + errno = EINVAL; + return NULL; + } + + if (!str) { + return psbuf->bfr; + } + + slen = n ? n : strlen(str); + if (!slen) { + return psbuf->bfr; + } + if ((psbuf->str_len + slen) >= psbuf->buf_len) { + int nsize = psbuf->str_len + slen + 512; + char* nbuf = (char*) malloc(nsize); + if (!nbuf) { + errno = ENOMEM; + return NULL; + } + strcpy(nbuf, psbuf->bfr); + strncat(nbuf, str, slen); + free(psbuf->bfr); + psbuf->bfr = nbuf; + psbuf->buf_len = nsize; + } + else { + strncat(psbuf->bfr, str, slen); + } + psbuf->str_len = strlen(psbuf->bfr); + return psbuf->bfr; +} + +/*****************************************************************************/ +int +omcStrBuf_reset(omcStrBuf* psbuf) +{ + if (!psbuf) { + errno = EINVAL; + return -1; + } + psbuf->bfr[0] = 0; + psbuf->str_len = 0; + return 0; +} + +/*****************************************************************************/ +const char* +omcStrBuf_set(omcStrBuf* psbuf, const char* str, size_t n) +{ + size_t slen; + + if (!psbuf) { + errno = EINVAL; + return NULL; + } + + if (!str) { + omcStrBuf_reset(psbuf); + return psbuf->bfr; + } + + slen = n ? n : strlen(str); + psbuf->bfr[0] = 0; + psbuf->str_len = slen; + if (!slen) { + return psbuf->bfr; + } + + if (slen >= psbuf->buf_len) { + int nsize = psbuf->str_len + 512; + char* nbuf = (char*) malloc(nsize); + if (!nbuf) { + errno = ENOMEM; + return NULL; + } + strncpy(nbuf, str, slen); + nbuf[slen] = 0; + free(psbuf->bfr); + psbuf->bfr = nbuf; + psbuf->buf_len = nsize; + } + else { + strncpy(psbuf->bfr, str, slen); + psbuf->bfr[slen] = 0; + } + return psbuf->bfr; +} + +/*****************************************************************************/ +int +omcStrBuf_destroy(omcStrBuf* psbuf) +{ + if (!psbuf) { + errno = EINVAL; + return -1; + } + if (psbuf->bfr) { + free(psbuf->bfr); + } + free(psbuf); + return 0; +} + 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: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-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 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; +} + + + + + + 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-30 17:11:01 UTC (rev 595) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.h 2008-05-05 15:09:41 UTC (rev 596) @@ -9,7 +9,7 @@ typedef void* VMBDBCtx; -int db_create_connection(VMBDBCtx* ctx, const char* query, char* err_msg, size_t err_msg_len); +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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-04-30 17:10:59
|
Revision: 595 http://omc.svn.sourceforge.net/omc/?rev=595&view=rev Author: jcarey Date: 2008-04-30 10:11:01 -0700 (Wed, 30 Apr 2008) Log Message: ----------- Clean up Modified Paths: -------------- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 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:55:15 UTC (rev 594) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuild-db.c 2008-04-30 17:11:01 UTC (rev 595) @@ -111,8 +111,7 @@ _db_busy_handler(void* cbdata, int call_count) { // Logging? - if (call_count > 10) - { + if (call_count > 10) { // Been waiting for the lock condition for to long. // return failure, so the sqlite call will fail. return 0; @@ -129,10 +128,8 @@ static int _str_is_empty(const char* str) { - if (str) - { - while (*str) - { + if (str) { + while (*str) { if (!isspace(*str)) return 0; str++; @@ -149,8 +146,7 @@ { struct stat st; if (stat(path, &st) == 0 - && S_ISDIR(st.st_mode)) - { + && S_ISDIR(st.st_mode)) { return 1; } return 0; @@ -170,20 +166,16 @@ cur_path[0] = '\0'; toks = omcStrTokenize(path, "/", &number_of_toks); - if (!toks) - { + if (!toks) { // Invalid path? return -1; } - for(i = 0; toks[i]; i++) - { + 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) - { + if (!_is_dir(cur_path)) { + if (mkdir(cur_path, 0755) != 0) { return -1; } } @@ -204,22 +196,19 @@ { char *zErr = 0; - if (!_is_dir(VMB_DB_DIR)) - { - if (_make_dirs(VMB_DB_DIR) != 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 + if (access(VMB_DB_NAME, F_OK) != 0) { + // Database does NOT exist // Create Database - if (sqlite3_open(VMB_DB_NAME, db)) - { + if (sqlite3_open(VMB_DB_NAME, db)) { snprintf(err_msg, err_msg_len, "Failed to open database "VMB_DB_NAME": %s", sqlite3_errmsg(*db)); @@ -227,26 +216,21 @@ return -1; } // Extend schema - if (sqlite3_exec(*db, _create_sql, NULL, NULL, &zErr) != SQLITE_OK) - { - if (zErr != NULL) - { + 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 - { + 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)) - { + 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)); @@ -266,28 +250,24 @@ size_t err_msg_len) { VMBDBCtx_t *pctx; - if (_str_is_empty(query)) - { + 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) - { + 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) - { + 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) - { + &pctx->tail) != SQLITE_OK) { snprintf(err_msg, err_msg_len, "Failed preparing DB Query: %s", sqlite3_errmsg(pctx->db)); sqlite3_finalize(pctx->stmt); @@ -309,10 +289,8 @@ db_destroy_connection(VMBDBCtx ctx) { VMBDBCtx_t *pctx = (VMBDBCtx_t*) ctx; - if (pctx) - { - if (pctx->stmt) - { + if (pctx) { + if (pctx->stmt) { sqlite3_finalize(pctx->stmt); } sqlite3_close(pctx->db); @@ -338,13 +316,9 @@ 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; - } + if (pctx && pctx->lastcc == SQLITE_ROW) { + pctx->lastcc = sqlite3_step(pctx->stmt); + return 0; } return -1; } @@ -368,8 +342,9 @@ 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) + if (pctx && pctx->col_count && column_index < pctx->col_count) { return sqlite3_column_text(pctx->stmt, (int)column_index); + } return NULL; } @@ -406,27 +381,22 @@ char* zErr = NULL; long long insert_row_id = -1LL; - if (_get_db_connection(&db, err_msg, err_msg_len) != 0) - { + 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) - { + if (cc != SQLITE_OK) { + if (zErr) { 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); } 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-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-25 23:47:45
|
Revision: 592 http://omc.svn.sourceforge.net/omc/?rev=592&view=rev Author: jcarey Date: 2008-04-25 16:47:48 -0700 (Fri, 25 Apr 2008) Log Message: ----------- Initial version of builder-job Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am Added Paths: ----------- contrib/xen-vm-builder/trunk/mof/builder-job-peg.reg contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c Added: contrib/xen-vm-builder/trunk/mof/builder-job-peg.reg =================================================================== --- contrib/xen-vm-builder/trunk/mof/builder-job-peg.reg (rev 0) +++ contrib/xen-vm-builder/trunk/mof/builder-job-peg.reg 2008-04-25 23:47:48 UTC (rev 592) @@ -0,0 +1,29 @@ +instance of PG_ProviderModule +{ + Name = "OMC_XENVMBuilderJob_Module"; + Location = "omc_xenvmbuilderjob"; + Vendor = "OMC"; + Version = "1.0.0"; + InterfaceType = "CMPI"; + InterfaceVersion = "2.0.0"; +}; + +instance of PG_Provider +{ + ProviderModuleName = "OMC_XENVMBuilderJob_Module"; + Name = "omc_xenvmbuilderjob"; +}; + +instance of PG_ProviderCapabilities +{ + ProviderModuleName = "OMC_XENVMBuilderJob_Module"; + ProviderName = "omc_xenvmbuilderjob"; + CapabilityID = "1"; + ClassName = "XEN_VMBuilderJob"; + Namespaces = {"root/cimv2"}; + ProviderType = { 2, 5 }; // Instance, Method + SupportedProperties = NULL; // All properties + SupportedMethods = NULL; // All methods +}; + + Modified: contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg =================================================================== --- contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg 2008-04-24 20:24:45 UTC (rev 591) +++ contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg 2008-04-25 23:47:48 UTC (rev 592) @@ -33,7 +33,7 @@ CapabilityID = "2"; ClassName = "XEN_VMBuilderHostedService"; Namespaces = {"root/cimv2"}; - ProviderType = { 2, 3 }; // Instance, Method + ProviderType = { 2, 3 }; // Instance, Associator SupportedProperties = NULL; // All properties SupportedMethods = NULL; // All methods }; 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-24 20:24:45 UTC (rev 591) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/Makefile.am 2008-04-25 23:47:48 UTC (rev 592) @@ -1,6 +1,8 @@ include $(top_srcdir)/Makefile.incl.am -provider_LTLIBRARIES = libomc_xenvmbuilder.la +provider_LTLIBRARIES = \ + libomc_xenvmbuilder.la \ + libomc_xenvmbuilderjob.la INCLUDES = -I$(top_builddir) @@ -12,5 +14,12 @@ -lomc_cmpi \ -version-info 1 +libomc_xenvmbuilderjob_la_SOURCES = \ + builder-job.c +libomc_xenvmbuilderjob_la_LDFLAGS = \ + -lpthread \ + -lomc_cmpi \ + -version-info 1 + Added: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c =================================================================== --- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c (rev 0) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-job.c 2008-04-25 23:47:48 UTC (rev 592) @@ -0,0 +1,600 @@ +/******************************************************************************* +* 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 <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* job_class_keys[] = +{ + "Name", + NULL +}; + +static const char* job_states[] = +{ + "SETTINGS", + "PREP_INSTALL", + "INSTALL", + "POST_INSTALL", + "RUNTIME_CONF", + "RUNTIME", + "FINISHED", + "FAILED", + "CANCELED" +}; + +typedef struct { + char vnc[8]; + char uuid[40]; + char name[64]; + int exit_code; + char id[32]; + char log[256]; + int state; + 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 + */ +static const CMPIBroker* _broker; + +/****************************************************************************** + CMPI INSTANCE PROVIDER FUNCTIONS +******************************************************************************/ + +static int +get_job_info(const char* id, VMInstallInfo* pinfo) +{ + int status, cc = -1; + char *output = NULL; + char **lines; + unsigned int output_size; + const char* cmd[] = { + "/usr/bin/vm-install-jobs", + "-s", + id, + NULL + }; + + DEBUGOUT("get_job_info called with %s\n", id); + + memset(pinfo, 0, sizeof(*pinfo)); + if (omcExecuteProcessAndGatherOutputAndError((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); + 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 ")) { + 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 ")) { + pinfo->state = atoi(lines[i]+6); + } + else if (omcStrStartsWith(lines[i], "inotify ")) { + omcStrNCpy(pinfo->inotify, lines[i]+8, sizeof(pinfo->inotify)); + omcStrTrim(pinfo->inotify); + } + } + free(lines); + cc = 0; + } + } + else { + DEBUGOUT("exec & gather errno: %d-%s\n", errno, strerror(errno)); + } + if (output) { + free(output); + } + DEBUGOUT("get_job_info returning %d\n", cc); + return cc; +} + +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; +} + +/****************************************************************************** +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; + + className = (char*) CMGetCharPtr(CMGetClassName(cop, NULL)); + + DEBUGOUT("EnumInstanceNames() called class:%s\n", className); + if (strcasecmp(className, "XEN_VMBuilderJob") == 0) { + CMPIObjectPath* ref = CMNewObjectPath(_broker, ns, + "XEN_VMBUilderJob", &status); + if (status.rc != CMPI_RC_OK || CMIsNullObject(ref)) { + DEBUGOUT("EnumbInstanceNames(): CMNewObjectPath() " + "failed - %s\n", CMGetCharPtr(status.msg)); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, + "Failed creating object path"); + return status; + } + char** names = get_job_names(); + if (names) { + int i; + for(i = 0; names[i]; i++) { + CMAddKey(ref, "Name", (CMPIValue*)names[i], CMPI_chars); + CMReturnObjectPath(results, ref); + } + free(names); + } + 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_VMBuilderJob") == 0) { + 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_VMBuilderJob", + job_class_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_VMBuilderJob") == 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_VMBuilderJob") != 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_xenvmbuilderjob, _broker, Init(&mi)); +CMMethodMIStub( , omc_xenvmbuilderjob, _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-24 20:24:44
|
Revision: 591 http://omc.svn.sourceforge.net/omc/?rev=591&view=rev Author: jcarey Date: 2008-04-24 13:24:45 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Renamed file Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/Makefile.am contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof Added Paths: ----------- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderHostedService.mof Removed Paths: ------------- contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof Modified: contrib/xen-vm-builder/trunk/mof/Makefile.am =================================================================== --- contrib/xen-vm-builder/trunk/mof/Makefile.am 2008-04-24 20:13:38 UTC (rev 590) +++ contrib/xen-vm-builder/trunk/mof/Makefile.am 2008-04-24 20:24:45 UTC (rev 591) @@ -1,9 +1,9 @@ EXTRA_DIST = \ - XEN_HostedVMBuilderService.mof \ XEN_SettingsDefineBuild.mof \ XEN_VMBuilder.mof \ XEN_VMBuilderJob.mof \ XEN_VMBuilderOwningJobElement.mof \ XEN_VMBuilderProcessOfJob.mof \ XEN_VMBuilderService.mof \ + XEN_VMBuilderHostedService.mof \ XEN_VMBuilderVirtualSystemCreationData.mof Deleted: contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof 2008-04-24 20:13:38 UTC (rev 590) +++ contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof 2008-04-24 20:24:45 UTC (rev 591) @@ -1,20 +0,0 @@ -// ================================================================== -// XEN_VMBuilderHostedService -// ================================================================== -[Association, Description ( - "XEN_VMBuilderHostedService is an association between the virtual " - "machine incubation service (XEN_VMBuilderService) and the hosting " - "computer system (CIM_ComputerSystem). The cardinality of " - "this association is one-to-one. A System can only host one virtual " - "machine builder.")] -class XEN_VMBuilderHostedService : CIM_HostedService -{ - [Override ("Antecedent"), Min (1), Max (1), - Description ("The hosting System.")] - CIM_ComputerSystem REF Antecedent; - - [Override ( "Dependent" ), Weak, Max(1), - Description ("The VM Builder Service hosted on the System.")] - XEN_VMBuilderService REF Dependent; -}; - Modified: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof 2008-04-24 20:13:38 UTC (rev 590) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof 2008-04-24 20:24:45 UTC (rev 591) @@ -6,7 +6,7 @@ // Associations #pragma include ("XEN_VMBuilderOwningJobElement.mof") #pragma include ("XEN_VMBuilderProcessOfJob.mof") -#pragma include ("XEN_HostedVMBuilderService.mof") +#pragma include ("XEN_VMBuilderHostedService.mof") #pragma include ("XEN_SettingsDefineBuild.mof") Added: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderHostedService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderHostedService.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderHostedService.mof 2008-04-24 20:24:45 UTC (rev 591) @@ -0,0 +1,20 @@ +// ================================================================== +// XEN_VMBuilderHostedService +// ================================================================== +[Association, Description ( + "XEN_VMBuilderHostedService is an association between the virtual " + "machine incubation service (XEN_VMBuilderService) and the hosting " + "computer system (CIM_ComputerSystem). The cardinality of " + "this association is one-to-one. A System can only host one virtual " + "machine builder.")] +class XEN_VMBuilderHostedService : CIM_HostedService +{ + [Override ("Antecedent"), Min (1), Max (1), + Description ("The hosting System.")] + CIM_ComputerSystem REF Antecedent; + + [Override ( "Dependent" ), Weak, Max(1), + Description ("The VM Builder Service hosted on the System.")] + XEN_VMBuilderService REF Dependent; +}; + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-04-24 20:14:20
|
Revision: 590 http://omc.svn.sourceforge.net/omc/?rev=590&view=rev Author: jcarey Date: 2008-04-24 13:13:38 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Implemented the XEN_VMBuilderHostedService association Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c Modified: contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg =================================================================== --- contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg 2008-04-24 16:45:56 UTC (rev 589) +++ contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg 2008-04-24 20:13:38 UTC (rev 590) @@ -26,3 +26,15 @@ SupportedMethods = NULL; // All methods }; +instance of PG_ProviderCapabilities +{ + ProviderModuleName = "OMC_XENVMBuilder_Module"; + ProviderName = "omc_xenvmbuilder"; + CapabilityID = "2"; + ClassName = "XEN_VMBuilderHostedService"; + Namespaces = {"root/cimv2"}; + ProviderType = { 2, 3 }; // Instance, Method + SupportedProperties = NULL; // All properties + SupportedMethods = NULL; // All methods +}; + 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-24 16:45:56 UTC (rev 589) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-04-24 20:13:38 UTC (rev 590) @@ -61,6 +61,13 @@ NULL }; +static const char* hosted_service_class_keys[] = +{ + "Dependent", + "Antecedent", + NULL +}; + #define SERVICE_NAME "xen-vmbuilder" #define RPM_NAME "omc-xenvm-builder" @@ -79,15 +86,49 @@ static const CMPIBroker* _broker; /*****************************************************************************/ +static CMPIObjectPath* +get_service_ref( + const char* ns, + CMPIStatus* pstatus) +{ + CMPIObjectPath* objectpath; + char hname[256]; + + objectpath = CMNewObjectPath(_broker, ns, "XEN_VMBuilderService", pstatus); + if ((pstatus->rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) + { + return NULL; + } + + 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); + return objectpath; +} + +/*****************************************************************************/ static int fillServiceInstance( - CMPIInstance* instance, - const char* hostName) + CMPIInstance* instance) { unsigned short wku16; CMPIDateTime* datetime; CMPIArray *pra; + char hostName[256]; + if (!omcGetComputerSystemName(hostName, sizeof(hostName))) + { + omcStrNCpy(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); @@ -142,7 +183,6 @@ CMPIStatus status = {CMPI_RC_OK, NULL}; CMPIObjectPath* objectpath; char *ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL)); - char hname[256]; char *className; DEBUGOUT("EnumInstanceNames() called\n"); @@ -150,27 +190,53 @@ 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)) + objectpath = get_service_ref(ns, &status); + if ((status.rc != CMPI_RC_OK) || objectpath == NULL) { - DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() failed - %s\n", CMGetCharPtr(status.msg)); - OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, "Failed creating new object path"); + DEBUGOUT("EnumInstanceNames(): get_service_ref() 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))) + CMReturnObjectPath(results, objectpath); + CMReturnDone(results); + } + 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)) { - omcStrNCpy(hname, "localhost", sizeof(hname)); + DEBUGOUT("EnumInstanceNames(): CMNewObjectPath() failed - %s\n", + CMGetCharPtr(status.msg)); + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, + "Failed creating new object path"); + return status; } - - 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); + depref = get_service_ref(ns, &status); + 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, + "Failed creating new object path"); + return status; + } + CMAddKey(objectpath, "Dependent", (CMPIValue*)&depref, CMPI_ref); + antref = omccmpiCreateCSObjectPath(_broker, ns, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(antref)) + { + DEBUGOUT("EnumInstanceNames(): omccmpiCreateCSObjectPath failed - %s\n", + CMGetCharPtr(status.msg)); + return status; + } + CMAddKey(objectpath, "Antecedent", (CMPIValue*)&antref, CMPI_ref); CMReturnObjectPath(results, objectpath); CMReturnDone(results); } - DEBUGOUT("Leaving EnumInstanceNames(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed"); + DEBUGOUT("Leaving EnumInstanceNames(): %s\n", + (status.rc == CMPI_RC_OK)? "succeeded":"failed"); return status; } @@ -193,7 +259,7 @@ CMPIStatus status = {CMPI_RC_OK, NULL}; char * ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL)); CMPIInstance* instance; - char hname[256], *className; + char *className; DEBUGOUT("EnumInstances() called\n"); @@ -208,11 +274,41 @@ return status; } - if (!omcGetComputerSystemName(hname, sizeof(hname))) + fillServiceInstance(instance); + CMReturnInstance(results, instance); + CMReturnDone(results); + } + 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)) { - omcStrNCpy(hname, "localhost", sizeof(hname)); + 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; } - fillServiceInstance(instance, hname); + depref = get_service_ref(ns, &status); + 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, + "Failed creating new object path"); + return status; + } + CMSetProperty(instance, "Dependent", (CMPIValue*)&depref, CMPI_ref); + antref = omccmpiCreateCSObjectPath(_broker, ns, &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(antref)) + { + DEBUGOUT("EnumInstances(): omccmpiCreateCSObjectPath failed - %s\n", + CMGetCharPtr(status.msg)); + return status; + } + CMSetProperty(instance, "Antecedent", (CMPIValue*)&antref, CMPI_ref); CMReturnInstance(results, instance); CMReturnDone(results); } @@ -238,16 +334,29 @@ const char** properties) { CMPIInstance* instance; + CMPIObjectPath *objectpath; 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) { + objectpath = get_service_ref(ns, &status); + 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)) + { + 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)) @@ -256,19 +365,84 @@ } else { - if (!omcGetComputerSystemName(hname, sizeof(hname))) - { - omcStrNCpy(hname, "localhost", sizeof(hname)); - } - fillServiceInstance(instance, hname); + fillServiceInstance(instance); CMReturnInstance(results, instance); } } + if (strcasecmp(className, "XEN_VMBuilderHostedService") == 0) + { + CMPIData antecedent, dependent; + antecedent = CMGetKey(cop, "Antecedent", &status); + 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) + { + 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)) + { + DEBUGOUT("GetInstance(): omccmpiCreateCSObjectPath failed - %s\n", + CMGetCharPtr(status.msg)); + return status; + } + if (!omccmpiAreObjectPathsSame(antecedent.value.ref, objectpath, &status)) + { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, + "Instance does not exists"); + return status; + } + instance = omccmpiNewInstance(_broker, ns, + "XEN_VMBuilderHostedService", + hosted_service_class_keys, properties, &status); + CMSetProperty(instance, "Antecedent", (CMPIValue*)&objectpath, CMPI_ref); + + dependent = CMGetKey(cop, "Dependent", &status); + 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) + { + DEBUGOUT("GetInstance(): Invalid 'Dependent' key property type\n"); + CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_INVALID_PARAMETER, + "Dependent key invalid"); + return status; + } + + objectpath = get_service_ref(ns, &status); + 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)) + { + OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_NOT_FOUND, + "Instance does not exists"); + return status; + } + CMSetProperty(instance, "Dependent", (CMPIValue*)&objectpath, 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 @@ -504,6 +678,312 @@ 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}; + char * ns = (char*) CMGetCharPtr(CMGetNameSpace(cop, NULL)); + CMPIObjectPath *csOp, *objectpath; + CMPIInstance *instance; + + DEBUGOUT("doReferences called\n"); + + 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) + { + /* 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; + } + } + 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; + } + + 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 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; + } + + 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); + return status; + } + } + DEBUGOUT("Leaving doReferences\n"); + return status; +} + +/****************************************************************************** +Associators() + params: CMPIAssociationMI* 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 *assocClass + char *resultClass + char *role + char *resultRole + char **properties +******************************************************************************/ +static CMPIStatus +Associators( + CMPIAssociationMI* self, + 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}; + + DEBUGOUT("Associators() called"); + + status = omccmpiSimpleAssociators(doReferences, self, + _broker, context, results, cop, assocClass, + resultClass, role, resultRole, properties); + + DEBUGOUT("Leaving Associatiors(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed"); + return status; +} + + +/****************************************************************************** +AssociatorNames() + params: CMPIAssociationMI* 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 *assocClass + char *resultClass + char *role + char *resultRole +******************************************************************************/ +static CMPIStatus +AssociatorNames( + CMPIAssociationMI* self, + const CMPIContext* context, + const CMPIResult* results, + const CMPIObjectPath* cop, + const char *assocClass, + const char *resultClass, + const char *role, + const char *resultRole) +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; + + DEBUGOUT("AssociatorNames() called"); + + status = omccmpiSimpleAssociatorNames(doReferences, self, _broker, + context, results, cop, assocClass, resultClass, role, + resultRole); + + DEBUGOUT("Leaving AssociatiorNames(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed"); + return status; +} + +/****************************************************************************** +References() + params: CMPIAssociationMI* 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 *resultClass + char *role + char **properties +******************************************************************************/ +static CMPIStatus References( + CMPIAssociationMI* self, + const CMPIContext* context, + const CMPIResult* results, + const CMPIObjectPath* cop, + const char* resultClass, + const char* role, + const char** properties) +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; + + DEBUGOUT("References() called"); + + status = omccmpiSimpleReferences( doReferences, self, _broker, context, + results, cop, resultClass, role, properties); + + DEBUGOUT("Leaving References(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed"); + return status; +} + + +/****************************************************************************** +ReferenceNames() + params: CMPIAssociationMI* 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 *resultClass + char *role +******************************************************************************/ +static CMPIStatus +ReferenceNames( + CMPIAssociationMI* self, + const CMPIContext* context, + const CMPIResult* results, + const CMPIObjectPath* cop, + const char* resultClass, + const char* role) +{ + CMPIStatus status = {CMPI_RC_OK, NULL}; + + DEBUGOUT("ReferenceNames() called"); + + status = omccmpiSimpleReferenceNames( doReferences, self, _broker, + context, results, cop, resultClass, role); + + DEBUGOUT("Leaving ReferenceNames(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed"); + return status; +} + /***************************************************************************** SETUP CMPI INSTANCE PROVIDER FUNCTION TABLE ******************************************************************************/ @@ -520,12 +1000,9 @@ 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)); -*/ CMInstanceMIStub( , omc_xenvmbuilder, _broker, Init(&mi)); CMMethodMIStub( , omc_xenvmbuilder, _broker, MethodInit(&mi)); +CMAssociationMIStub( , omc_xenvmbuilder, _broker, AssocInit(&mi)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-04-24 16:46:01
|
Revision: 589 http://omc.svn.sourceforge.net/omc/?rev=589&view=rev Author: jcarey Date: 2008-04-24 09:45:56 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Changed of MIStubs to work correctly Modified Paths: -------------- contrib/xen-vm-builder/trunk/configure.ac contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c Added Paths: ----------- contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg Property Changed: ---------------- / Property changes on: ___________________________________________________________________ Name: svn:ignore + .*.swp Modified: contrib/xen-vm-builder/trunk/configure.ac =================================================================== --- contrib/xen-vm-builder/trunk/configure.ac 2008-04-23 23:23:28 UTC (rev 588) +++ contrib/xen-vm-builder/trunk/configure.ac 2008-04-24 16:45:56 UTC (rev 589) @@ -96,13 +96,13 @@ case $debuglevel in 1) - AC_DEFINE(SMASH_DEBUG, 1, "Debugging flag.") + AC_DEFINE(XEN_VMBUILDER_DEBUG, 1, "Debugging Flag") CXXFLAGS="$CXXFLAGS $DEBUG_FLAGS -Wall" CPPFLAGS="$CPPFLAGS $DEBUG_FLAGS -Wall" CFLAGS=" $CFLAGS $DEBUG_FLAGS -Wall" LDFLAGS=" $LDFLAGS $DEBUG_FLAGS";; 2) - AC_DEFINE(SMASH_DEBUG, 2, "Debugging flag.") + AC_DEFINE(XEN_VMBUILDER_DEBUG, 2, "Debugging Flag") CXXFLAGS="$CXXFLAGS $DEBUG_FLAGS $FULL_DEBUG_FLAGS -Wall" CPPFLAGS="$CPPFLAGS $DEBUG_FLAGS $FULL_DEBUG_FLAGS -Wall" CFLAGS=" $CFLAGS $DEBUG_FLAGS $FULL_DEBUG_FLAGS -Wall" Added: contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg =================================================================== --- contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg (rev 0) +++ contrib/xen-vm-builder/trunk/mof/builder-service-peg.reg 2008-04-24 16:45:56 UTC (rev 589) @@ -0,0 +1,28 @@ +instance of PG_ProviderModule +{ + Name = "OMC_XENVMBuilder_Module"; + Location = "omc_xenvmbuilder"; + Vendor = "OMC"; + Version = "1.0.0"; + InterfaceType = "CMPI"; + InterfaceVersion = "2.0.0"; +}; + +instance of PG_Provider +{ + ProviderModuleName = "OMC_XENVMBuilder_Module"; + Name = "omc_xenvmbuilder"; +}; + +instance of PG_ProviderCapabilities +{ + ProviderModuleName = "OMC_XENVMBuilder_Module"; + ProviderName = "omc_xenvmbuilder"; + CapabilityID = "1"; + ClassName = "XEN_VMBuilderService"; + Namespaces = {"root/cimv2"}; + ProviderType = { 2, 5 }; // Instance, Method + SupportedProperties = NULL; // All properties + SupportedMethods = NULL; // All methods +}; + 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-23 23:23:28 UTC (rev 588) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-04-24 16:45:56 UTC (rev 589) @@ -65,12 +65,8 @@ #define RPM_NAME "omc-xenvm-builder" -/* Enable this for tracing */ -#ifdef OMC_DEBUG -#undef OMC_DEBUG -#endif - -#ifdef OMC_DEBUG +/* If built for debug, enable tracing */ +#ifdef XEN_VMBUILDER_DEBUG #define DEBUGOUT(fmt, args...) printf(fmt,## args) #else #define DEBUGOUT(fmt, args...) @@ -524,6 +520,13 @@ 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)); +*/ +CMInstanceMIStub( , omc_xenvmbuilder, _broker, Init(&mi)); +CMMethodMIStub( , omc_xenvmbuilder, _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-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-23 22:12:29
|
Revision: 587 http://omc.svn.sourceforge.net/omc/?rev=587&view=rev Author: jcarey Date: 2008-04-23 15:12:30 -0700 (Wed, 23 Apr 2008) Log Message: ----------- Added value/valmap for return code of CreateVM Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof Modified: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-04-23 22:06:27 UTC (rev 586) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-04-23 22:12:30 UTC (rev 587) @@ -10,7 +10,58 @@ "to the instance of XEN_VMBuilderJob representing the " "vm creation job, via the OUT parameter. Return code = 0 if success " "or error code. All ongoing status about the vm creation will be " - "reflected in the properties of that instance.")] + "reflected in the properties of that instance."), + ValueMap { "0", "1", // General Errors + "10", "11", "12", "13", "14", // XEN Errors + "20", "21", "22", "23", "24", "25", // VM Errors + "30", "31", "32", "33", "34", "35", //Installation Source Errors + "40", "41", // Architecture Errors + "50", // Memory + "60", "61", "62", "63", // Disk + "70", "71", "72", // Job Errors + "80", "81", "82"}, // Parameter Errors + Values { + // General Errors + "Success", + "Other runtime error", + // XEN Errors + "An error occurred in Xen.", + "The hypervisor is not running.", + "An incompatible version of the hypervisor is running.", + "Unable to connect to the Xen daemon.", + "Must be the 'root' user to manage Xen.", + // VM Errors + "Failed to start the VM.", + "The VM has crashed.", + "A VM by that name is already running.", + "A VM configuration already exists with that name.", + "A valid boot sector was not found. The installation may have failed.", + "No kernel was found. The installation may have failed.", + // Installation Source Errors + "The installation source is using an unsupported protocol.", + "An error occurred while reading from the installation source.", + "The installation source was not found.", + "The installation source is unusable.", + "No installation source was defined.", + "A CD-ROM or DVD must be specified from which to boot.", + // Architecture Errors + "The operating system is incompatible with the processor architecture of this machine.", + "The processor(s) in this machine do not support full virtualization.", + // Resources: Memory + "Not enough memory.", + // Resources: Disk + "The disk does not exist.", + "The disk is read-only.", + "Permission was denied while attempting to access the disk.", + "Two of the virtual disks have conflicting virtual names or physical devices.", + // Job Errors + "The job was canceled.", + "The job was not found.", + "The job is in the wrong state to perform that action.", + // Parameter Errors + "A parameter is invalid or missing.", + "The operating system does not support paravirtualization.", + "The operating system does not support automated installations."}] uint32 CreateVM( [IN, Description("The name that the VM will be given.")] string VMName, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-04-23 22:06:27
|
Revision: 586 http://omc.svn.sourceforge.net/omc/?rev=586&view=rev Author: jcarey Date: 2008-04-23 15:06:27 -0700 (Wed, 23 Apr 2008) Log Message: ----------- Added new mofs Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/Makefile.am Modified: contrib/xen-vm-builder/trunk/mof/Makefile.am =================================================================== --- contrib/xen-vm-builder/trunk/mof/Makefile.am 2008-04-23 21:14:35 UTC (rev 585) +++ contrib/xen-vm-builder/trunk/mof/Makefile.am 2008-04-23 22:06:27 UTC (rev 586) @@ -1,9 +1,9 @@ EXTRA_DIST = \ XEN_HostedVMBuilderService.mof \ + XEN_SettingsDefineBuild.mof \ XEN_VMBuilder.mof \ XEN_VMBuilderJob.mof \ XEN_VMBuilderOwningJobElement.mof \ XEN_VMBuilderProcessOfJob.mof \ XEN_VMBuilderService.mof \ XEN_VMBuilderVirtualSystemCreationData.mof - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-04-23 21:14:30
|
Revision: 585 http://omc.svn.sourceforge.net/omc/?rev=585&view=rev Author: jcarey Date: 2008-04-23 14:14:35 -0700 (Wed, 23 Apr 2008) Log Message: ----------- Refactor Added Paths: ----------- contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof contrib/xen-vm-builder/trunk/mof/XEN_SettingsDefineBuild.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderJob.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderOwningJobElement.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderProcessOfJob.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof Added: contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof 2008-04-23 21:14:35 UTC (rev 585) @@ -0,0 +1,20 @@ +// ================================================================== +// XEN_VMBuilderHostedService +// ================================================================== +[Association, Description ( + "XEN_VMBuilderHostedService is an association between the virtual " + "machine incubation service (XEN_VMBuilderService) and the hosting " + "computer system (CIM_ComputerSystem). The cardinality of " + "this association is one-to-one. A System can only host one virtual " + "machine builder.")] +class XEN_VMBuilderHostedService : CIM_HostedService +{ + [Override ("Antecedent"), Min (1), Max (1), + Description ("The hosting System.")] + CIM_ComputerSystem REF Antecedent; + + [Override ( "Dependent" ), Weak, Max(1), + Description ("The VM Builder Service hosted on the System.")] + XEN_VMBuilderService REF Dependent; +}; + Added: contrib/xen-vm-builder/trunk/mof/XEN_SettingsDefineBuild.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_SettingsDefineBuild.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_SettingsDefineBuild.mof 2008-04-23 21:14:35 UTC (rev 585) @@ -0,0 +1,18 @@ +// ================================================================== +// XEN_SettingsDefineBuild +// ================================================================== +[Association, Description ( + "XEN_SettingsDefineBuild is used to associate a XEN_VMBuilderJob " + "with the all the settings provided to build the virtual machine " + "(XEN_VMBuilderVirtualSystemCreationData)")] +class XEN_SettingsDefineBuild : CIM_SettingsDefineState +{ + [Override("ManagedElement"), Key, + Description("The builder job")] + XEN_VMBuilderJob REF ManagedElement; + + [Override("SettingData"), Key, + Description ("The creation data used for the build")] + XEN_VMBuilderVirtualSystemCreationData REF SettingData; +}; + Added: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof 2008-04-23 21:14:35 UTC (rev 585) @@ -0,0 +1,16 @@ +// Import OMC VM Builder schema +#pragma include ("XEN_VMBuilderService.mof") +#pragma include ("XEN_VMBuilderJob.mof") +#pragma include ("XEN_VMBuilderVirtualSystemCreationData.mof") + +// Associations +#pragma include ("XEN_VMBuilderOwningJobElement.mof") +#pragma include ("XEN_VMBuilderProcessOfJob.mof") +#pragma include ("XEN_HostedVMBuilderService.mof") +#pragma include ("XEN_SettingsDefineBuild.mof") + + + + + + Added: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderJob.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderJob.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderJob.mof 2008-04-23 21:14:35 UTC (rev 585) @@ -0,0 +1,153 @@ +// ================================================================== +// XEN_VMBuilderJob +// ================================================================== +[Description( + "XEN_VMBuilderJob represents a vm installation(build) job. " + "These jobs are the result of running the vm-install command " + "line utility")] +class XEN_VMBuilderJob : CIM_Job +{ + [Key, Override("Name"), + Description("XEN:VMBUILDER:<JobID>")] + string Name; + + [Propagated ("CIM_ComputerSystem.Name"), + Description("The name of the system that owns this job")] + string HostComputerSystemName; + + [Description("Unique id of the vm-install job. " + "Use this jobId to track through the Incubation process. ")] + string JobID; + + [Description("Process ID (if applicable) of the vm installation job")] + uint32 PID; + + [Description("Exit code of the incubation creation process"), + ValueMap { "0", "1", // General Errors + "10", "11", "12", "13", "14", // XEN Errors + "20", "21", "22", "23", "24", "25", // VM Errors + "30", "31", "32", "33", "34", "35", //Installation Source Errors + "40", "41", // Architecture Errors + "50", // Memory + "60", "61", "62", "63", // Disk + "70", "71", "72", // Job Errors + "80", "81", "82"}, // Parameter Errors + Values { + // General Errors + "Success", + "Other runtime error", + // XEN Errors + "An error occurred in Xen.", + "The hypervisor is not running.", + "An incompatible version of the hypervisor is running.", + "Unable to connect to the Xen daemon.", + "Must be the 'root' user to manage Xen.", + // VM Errors + "Failed to start the VM.", + "The VM has crashed.", + "A VM by that name is already running.", + "A VM configuration already exists with that name.", + "A valid boot sector was not found. The installation may have failed.", + "No kernel was found. The installation may have failed.", + // Installation Source Errors + "The installation source is using an unsupported protocol.", + "An error occurred while reading from the installation source.", + "The installation source was not found.", + "The installation source is unusable.", + "No installation source was defined.", + "A CD-ROM or DVD must be specified from which to boot.", + // Architecture Errors + "The operating system is incompatible with the processor architecture of this machine.", + "The processor(s) in this machine do not support full virtualization.", + // Resources: Memory + "Not enough memory.", + // Resources: Disk + "The disk does not exist.", + "The disk is read-only.", + "Permission was denied while attempting to access the disk.", + "Two of the virtual disks have conflicting virtual names or physical devices.", + // Job Errors + "The job was canceled.", + "The job was not found.", + "The job is in the wrong state to perform that action.", + // Parameter Errors + "A parameter is invalid or missing.", + "The operating system does not support paravirtualization.", + "The operating system does not support automated installations."}] + uint32 ExitCode; + + [Override("JobStatus"), + Values {"SETTINGS", + "PREP_INSTALL", + "INSTALL", + "POST_INSTALL", + "RUNTIME_CONF", + "RUNTIME", + "FINISHED", + "FAILED", + "CANCELED", + "UNKNOWN"}] + string JobStatus; + + [Description("URL to VNC port to contact the vm. NOTE: This does not " + "guarantee that the URL is active. It is the last known VNC URL.")] + string VncURL; + + [Description("UUID of resulting VM")] + string VM_UUID; + + [Description("File name that the vm installation will post status " + "changes to")] + string StatusFileName; + + [Description("Location (host:/path) of the installation log for the job")] + string InstallLogFileLocation; + + // The parameters with which the installation was created + + [Description("The user friendly name given to the VM")] + string VMName; + + // DeleteInstance: + // Deletes the job. The job must be in one of the FINISHED, FAILED, or + // CANCELED states. The VM's configuration is deleted, as are any disks + // that were created during the job. + + [Description("Detaches the created VM from this job. This job must be in the " + "FINISHED state. This job will be deleted, but the VM's configuration " + "and its disks are left intact."), + ValueMap { + "0", + "1", + "2", + "4", + "4097" }, + Values { + "Completed with No Error", + "Not Supported", + "Unknown/Unspecified Error", + "Failed", + "Invalid State Transition" }] + uint32 Detach(); + + [Description ( + "Cancels the specified job. If the VM is still running, it is " + "stopped. This command may return before the VM is completely " + "stopped or the vm-install process has completely exited. The " + "job is not implicitly deleted, so that the cancelation progress " + "may be observed."), + ValueMap { + "0", + "1", + "2", + "4", + "4097"}, + Values { + "Completed with No Error", + "Not Supported", + "Unknown/Unspecified Error", + "Failed", + "Invalid State Transition"}] + uint32 Cancel(); +}; + Added: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderOwningJobElement.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderOwningJobElement.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderOwningJobElement.mof 2008-04-23 21:14:35 UTC (rev 585) @@ -0,0 +1,17 @@ +// ================================================================== +// XEN_VMBuilderOwningJobElement +// ================================================================== +[Association, Description ( + "XEN_VMBuilderOwningJobElement describes the association between " + "the virtual machine builder service and a running builder job")] +class XEN_VMBuilderOwningJobElement : CIM_OwningJobElement +{ + [Override("OwningElement"), Description( + "The builder service that owns the job")] + XEN_VMBuilderService REF OwningElement; + + [Override("OwnedElement"), Description( + "The incubation job")] + XEN_VMBuilderJob REF OwnedElement; +}; + Added: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderProcessOfJob.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderProcessOfJob.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderProcessOfJob.mof 2008-04-23 21:14:35 UTC (rev 585) @@ -0,0 +1,21 @@ +// ================================================================== +// XEN_VMBuilderProcessOfJob +// ================================================================== +[Association, Aggregation, Composition, Description ( + "XEN_VMBuilderProcessOfJob describes the relationship between a VM " + "Builder Job that was submitted by the CIM Provider and a running " + "process on the system.")] +class XEN_VMBuilderProcessOfJob : CIM_ProcessOfJob +{ + [Aggregate, Override ("GroupComponent"), Description ( + "Execution of a VM Builder Job results in the createion of a " + "process running on the local machine. The Job aggregates the " + "process(es) that created when it is executed")] + XEN_VMBuilderJob REF GroupComponent; + + [Override ("PartComponent"), Description ( + "The Process that results from the execution of the VM Builder " + "job")] + OMC_UnixProcess REF PartComponent; +}; + Added: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-04-23 21:14:35 UTC (rev 585) @@ -0,0 +1,29 @@ +// ================================================================== +// XEN_VMBuilderService +// ================================================================== +[Description ( + "XEN_VMBuilderService represents the virtual machine incubator " + "functionality/service")] +class XEN_VMBuilderService : CIM_Service +{ + [Description("Initiate the creation of a VM. Result will be the object path " + "to the instance of XEN_VMBuilderJob representing the " + "vm creation job, via the OUT parameter. Return code = 0 if success " + "or error code. All ongoing status about the vm creation will be " + "reflected in the properties of that instance.")] + uint32 CreateVM( + [IN, Description("The name that the VM will be given.")] + string VMName, + + [IN, Description("The object path to the instance of " + "XEN_VMBuilderVirtualSystemCreationData that will be used " + "for the build")] + XEN_VMBuilderVirtualSystemCreationData REF NewSystemCreationData, + + [IN(false), OUT, Description ("REF to the new " + "XEN_VMBuilderJob instance.")] + XEN_VMBuilderJob REF VMBuilderJob); + + [Description("VM builder service version")] + string BuilderVersion; +}; Added: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof (rev 0) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-04-23 21:14:35 UTC (rev 585) @@ -0,0 +1,120 @@ +// ================================================================== +// XEN_VMBuilderVirtualSystemCreationData +// ================================================================== +[Description ( + "XEN_VMBuilderVirtualSystemCreationData defines the incubator aspects of a " + "virtual system through a set of virtualization specific properties, for " + "vm creation. " + "It is intended that incubator clients to create a static instance of this " + "class filling in appropriate properties as a means of passing all the vssd " + "specific parameters for creating a vm, in one parameter, to the CreateVM " + "method on XEN_VMBuilderService.")] +class XEN_VMBuilderVirtualSystemCreationData : CIM_VirtualSystemSettingData +{ + [Description( + "UUID contains the universal unique identifier for the virtual machine. " + "If none is given, a random UUID will be generated.")] + string UUID; + + [Description("type of virtualization. Values: " + " Unknown: undefined behavior - maybe try to determine best? " + " Para: Para Virtualization: OS Must support para virtualization. " + " Full: Full Virtualization: Hardware must support full virtualization."), + ValueMap { "0", "1", "2"}, + Values { "Unknown", "Para", "Full" }] + uint32 VirtType; + + [Description("Number of virtual CPUs for the virtual machine")] + uint8 NumVCPUs; + + [Description("Megabytes of RAM to initially allocate to the VM")] + uint32 Memory; + + [Description("Max Megabytes of RAM to allocate to the VM")] + uint32 MaxMemory; + + [Description("Disk definitions for the virtual machine." + " Format: 'PDEV,VDEV[,TYPE[,MODE[,MB]]]', where TYPE='disk' or 'cdrom' " + " ie /x/y/$$VMNAME$$/disk0,xvda,disk,w,10 " + " TAGS: if $$VMNAME$$ is found in the disk string, it will be " + " replaced by the vmName specified by parameter to " + " XEN_VMBuilderService::CreateVM ")] + string Disks[]; + + [Description("Network Interface definitions for the virtual machine." + " This is a multi-value property: each array entry represents a " + " separate value. " + " Format for each entry: " + " A comma-separated list of key/value pairs. Valid keys: " + " mac=AA.BB.CC.DD.EE.FF randomly generated if not specified" + " bridge=BRIDGE " + " model=MODEL only applicable for full-virt. can be one of: " + " 'pcnet' AMD PCnet 32 " + " 'ne2k_isa' NE2000 on ISA bus " + " 'ne2k_pci' NE2000 on PCI bus " + " 'rtl8139' Realtec 8139 " + " To define a NIC with all defaults, specify only 'default' ")] + string Nics[]; + + [Description("type of virtualized graphics hardware:" + " 'unknown': default to none " + " 'cirrus' : cirrus logic gc5446 pci vga: for full virt only. " + " 'none' : no graphics support; use serial console or network access. " + " 'para' : paravirtualized framebuffer; requires driver in os. " + " 'vesa' : standard vga with vesa extensions: for full virt only."), + ValueMap { "0", "1", "2", "3", "4"}, + Values { "Unknown", "Cirrus", "None", "Para", "Vesa" }] + uint32 GraphicsType; + + [Description("type of graphics viewer. Values: " + " Unknown: undefined behavior - default to VNC? " + " SDL: use SDL for graphics viewer - best when the vm will usually " + " be viewed locally. " + " VNC: use VNC for graphics viewer."), + ValueMap { "0", "1", "2"}, + Values { "Unknown", "SDL", "VNC" }] + uint32 GraphicsViewerType; + + [Description("CPU Architecture for the virtual machine. For incubation, also " + " serves as the constraint for where to dispatch the incubation job." ), + Values { "Unknown", "x86", "x86_64", "ia64", "ppc" }] + string CPUArchitecture; + + [Description("Port to use for VNC server")] + uint32 VNCPort; + + [Description("Field for users of this object to store additional data related " + "to this object. This is not used by the providers. It is user-defined " + "and user consumed. It is defined as a string array to allow for " + "key:value pairs within each element of the array, if the user so desires.")] + String ExtraConfigInfo[]; + + [Description("Extra arguments used for the VM Install. May not need.")] + string ExtraInstallArgs; + + [Description("A string containing the URL where the install source " + "can be obtained. ie:" + " nfs:host:/path " + " http://host/path " + " ftp://host/path " + " To install from virtual disk defined in the Disks property:" + " dev:/xvda (example syntax - provide appropriate device name")] + string SourceURL; + + [Description("Contents of response file to automate the " + "installation of the OS. The format of the file depends on the OS. " + "Not all OS types support automated installations.")] + string ResponseFile; + + [Description("Type of guest (vm) OS. This defines many defaults and " + " provides bootstrap capability. "), + ValueMap { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"}, + Values { "other", "suse", "sles8", "sles9", "sles10", "sled10", + "oes2l", "oes2nw", "netware", "redhat", "rhel3", "rhel4", + "rhel5", "solaris9", "solaris10", "windows", "windowsx64", + "windowsnt", "windowsxp", "windowsxpx64", "windowsvista", + "windowsvistax64" }] + uint32 OSType; +}; + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-04-23 21:08:35
|
Revision: 584 http://omc.svn.sourceforge.net/omc/?rev=584&view=rev Author: jcarey Date: 2008-04-23 14:08:16 -0700 (Wed, 23 Apr 2008) Log Message: ----------- Clean up Removed Paths: ------------- contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderJob.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderOwningJobElement.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderProcessOfJob.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof Deleted: contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof 2008-04-23 20:26:34 UTC (rev 583) +++ contrib/xen-vm-builder/trunk/mof/XEN_HostedVMBuilderService.mof 2008-04-23 21:08:16 UTC (rev 584) @@ -1,20 +0,0 @@ -// ================================================================== -// XEN_VMBuilderHostedService -// ================================================================== -[Association, Description ( - "XEN_VMBuilderHostedService is an association between the virtual " - "machine incubation service (XEN_VMBuilderService) and the hosting " - "computer system (CIM_ComputerSystem). The cardinality of " - "this association is one-to-one. A System can only host one virtual " - "machine builder.")] -class XEN_VMBuilderHostedService : CIM_HostedService -{ - [Override ("Antecedent"), Min (1), Max (1), - Description ("The hosting System.")] - CIM_ComputerSystem REF Antecedent; - - [Override ( "Dependent" ), Weak, Max(1), - Description ("The VM Incubation Service hosted on the System.")] - XEN_VMBuilderService REF Dependent; -}; - Deleted: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof 2008-04-23 20:26:34 UTC (rev 583) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilder.mof 2008-04-23 21:08:16 UTC (rev 584) @@ -1,10 +0,0 @@ -// Import OMC VM Builder schema -#pragma include ("XEN_VMBuilderService.mof") -#pragma include ("XEN_VMBuilderJob.mof") -#pragma include ("XEN_VMBuilderVirtualSystemCreationData.mof") - -// Associations -#pragma include ("XEN_HostedVMBuilderService.mof") -#pragma include ("XEN_VMBuilderOwningJobElement.mof") -#pragma include ("XEN_VMBuilderProcessOfJob.mof") - Deleted: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderJob.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderJob.mof 2008-04-23 20:26:34 UTC (rev 583) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderJob.mof 2008-04-23 21:08:16 UTC (rev 584) @@ -1,178 +0,0 @@ -// ================================================================== -// XEN_VMBuilderJob -// ================================================================== -[Abstract, Description ( - "XEN_VMBuilderJob represents a vm installation(build) job")] -class XEN_VMBuilderJob : CIM_Job -{ - [Key, Override("Name"), - Description("XEN:VMBUILDER:<JobID>")] - string Name; - - [Propagated ("CIM_ComputerSystem.Name"), - Description("The name of the system that owns this job")] - string HostComputerSystemName; - - [Description("Unique id of the vm-install job. " - "Use this jobId to track through the Incubation process. ")] - string JobID; - - [Description("Process ID (if applicable) of the vm installation job")] - uint32 PID; - - [Description("Exit code of the incubation creation process"), - ValueMap { "0", "1", // General Errors - "10", "11", "12", "13", "14", // XEN Errors - "20", "21", "22", "23", "24", "25", // VM Errors - "30", "31", "32", "33", "34", "35", //Installation Source Errors - "40", "41", // Architecture Errors - "50", // Memory - "60", "61", "62", "63", // Disk - "70", "71", "72", // Job Errors - "80", "81", "82"}, // Parameter Errors - Values { - // General Errors - "Success", - "Other runtime error", - // XEN Errors - "An error occurred in Xen.", - "The hypervisor is not running.", - "An incompatible version of the hypervisor is running.", - "Unable to connect to the Xen daemon.", - "Must be the 'root' user to manage Xen.", - // VM Errors - "Failed to start the VM.", - "The VM has crashed.", - "A VM by that name is already running.", - "A VM configuration already exists with that name.", - "A valid boot sector was not found. The installation may have failed.", - "No kernel was found. The installation may have failed.", - // Installation Source Errors - "The installation source is using an unsupported protocol.", - "An error occurred while reading from the installation source.", - "The installation source was not found.", - "The installation source is unusable.", - "No installation source was defined.", - "A CD-ROM or DVD must be specified from which to boot.", - // Architecture Errors - "The operating system is incompatible with the processor architecture of this machine.", - "The processor(s) in this machine do not support full virtualization.", - // Resources: Memory - "Not enough memory.", - // Resources: Disk - "The disk does not exist.", - "The disk is read-only.", - "Permission was denied while attempting to access the disk.", - "Two of the virtual disks have conflicting virtual names or physical devices.", - // Job Errors - "The job was canceled.", - "The job was not found.", - "The job is in the wrong state to perform that action.", - // Parameter Errors - "A parameter is invalid or missing.", - "The operating system does not support paravirtualization.", - "The operating system does not support automated installations."}] - uint32 ExitCode; - - [Override("JobStatus"), - Values {"SETTINGS", - "PREP_INSTALL", - "INSTALL", - "POST_INSTALL", - "RUNTIME_CONF", - "RUNTIME", - "FINISHED", - "FAILED", - "CANCELED", - "UNKNOWN", - "PRE_DISPATCH", - "DISPATCHED" }] - string JobStatus; - - [Description("URL to VNC port to contact the vm. NOTE: This does not " - "guarantee that the URL is active. It is the last known VNC URL.")] - string VncURL; - - [Description("UUID of resulting VM")] - string VM_UUID; - - [Description("File name that the vm installation will post status " - "changes to")] - string StatusFileName; - - [Description("Location (host:/path) of the installation log for the job")] - string InstallLogFileLocation; - - // The parameters with which the installation was created - - [Description("The user friendly name given to the VM")] - string VMName; - - // make this an embedded instance? - [Description("The object path to the static instance of " - "XEN_VMBuilderVirtualSystemCreationData")] - string NewSystemCreationData; - - [Description("Type of guest (vm) OS. This defines many defaults and " - " provides bootstrap capability. "), - ValueMap { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"}, - Values { "other", "suse", "sles8", "sles9", "sles10", "sled10", - "oes2l", "oes2nw", "netware", "redhat", "rhel3", "rhel4", - "rhel5", "solaris9", "solaris10", "windows", "windowsx64", - "windowsnt", "windowsxp", "windowsxpx64", "windowsvista", - "windowsvistax64" }] - uint32 OSType; - - [Description("A string containing the URL where the install source " - "can be obtained. ie:" - " nfs:host:/path " - " http://host/path " - " ftp://host/path " - " To install from virtual disk defined in the 'NewSystemCreationData' " - " instance: " - " dev:/xvda (example syntax - provide appropriate device name")] - string SourceURL; - - [Description("Contents of response file to automate the " - "installation of the OS. The format of the file depends on the OS. " - "Not all OS types support automated installations.")] - string ResponseFile; -}; - - - -// ================================================================== -// XEN_VMBuilderLocalJob -// ================================================================== -[Description ( - "XEN_VMBuilderLocalJob is an instance of a vm creation that is " - "occurring on the local box.")] -// Provider("cmpi::omc_vmbuilderlocaljob")] -class XEN_VMBuilderLocalJob : XEN_VMBuilderJob -{ - -}; - - - -// ================================================================== -// XEN_VMBuilderDispatchJob -// ================================================================== -[Description ( - "XEN_VMBuilderDispatchJob is an instance of a vm creation that has " - "been dispatched to some server in a network of incubation servers. It " - "indicates that the IncubationServer on the local box dispatched the job, " - "and will have ongoing status information about that job.")] -class XEN_VMBuilderDispatchJob : XEN_VMBuilderJob -{ - // ref to actual BuilderLocalJob on the remote box. - [Description("A String representation of the object path to the LocalJob " - "instance on the box where the actual install is occurring. ")] - string ActualIncubationJobPath; - [Propagated ("XEN_UnitaryComputerSystem.Name"), - Description("The name of the system where the actual incubation " - "took place")] - string IncubationSystemHostName; - -}; Deleted: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderOwningJobElement.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderOwningJobElement.mof 2008-04-23 20:26:34 UTC (rev 583) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderOwningJobElement.mof 2008-04-23 21:08:16 UTC (rev 584) @@ -1,17 +0,0 @@ -// ================================================================== -// XEN_VMBuilderOwningJobElement -// ================================================================== -[Association, Description ( - "XEN_VMBuilderOwningJobElement describes the association between " - "the virtual machine builder service and a running builder job")] -class XEN_VMBuilderOwningJobElement : CIM_OwningJobElement -{ - [Override("OwningElement"), Description( - "The builder service that owns the job")] - XEN_VMBuilderService REF OwningElement; - - [Override("OwnedElement"), Description( - "The incubation job")] - XEN_VMBuilderJob REF OwnedElement; -}; - Deleted: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderProcessOfJob.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderProcessOfJob.mof 2008-04-23 20:26:34 UTC (rev 583) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderProcessOfJob.mof 2008-04-23 21:08:16 UTC (rev 584) @@ -1,21 +0,0 @@ -// ================================================================== -// XEN_VMBuilderProcessOfJob -// ================================================================== -[Association, Aggregation, Composition, Description ( - "XEN_VMBuilderProcessOfJob describes the relationship between a VM " - "Builder Job that was submitted by the CIM Provider and a running " - "process on the system.")] -class XEN_VMBuilderProcessOfJob : CIM_ProcessOfJob -{ - [Aggregate, Override ("GroupComponent"), Description ( - "Execution of a VM Builder Job results in the createion of a " - "process running on the local machine. The Job aggregates the " - "process(es) that created when it is executed")] - XEN_VMBuilderJob REF GroupComponent; - - [Override ("PartComponent"), Description ( - "The Process that results from the execution of the VM Builder " - "job")] - OMC_UnixProcess REF PartComponent; -}; - Deleted: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-04-23 20:26:34 UTC (rev 583) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-04-23 21:08:16 UTC (rev 584) @@ -1,131 +0,0 @@ -// ================================================================== -// XEN_VMBuilderService -// ================================================================== -[Description ( - "XEN_VMBuilderService represents the virtual machine incubator " - "functionality/service")] -// Provider("cmpi::omc_vmincubatorservice")] -class XEN_VMBuilderService : CIM_Service -{ - [Description("Initiate the creation of a VM. Result will be the object path " - "to the instance of XEN_VMBuilderJob representing the " - "vm creation job, via the OUT parameter. Return code = 0 if success " - "or error code. All ongoing status about the vm creation will be " - "reflected in the properties of that instance.")] - uint32 CreateVM( - [IN, Description("This flag applies to distributed incubation " - "environments. It indicates whether this request should be forced " - "to occur on the local box or can be dispatched. If FALSE and in " - "a distributed environment, the dispatcher should set to true before " - "dispatching, so that the system the the request is dispatched to " - "sees it as ForceLocal=TRUE")] - boolean ForceLocal, - - [IN, Description("The name that the VM will be given.")] - string VMName, - - [IN, Description("The object path to the static instance of " - "XEN_VMBuilderVirtualSystemCreationData " - "NOTE: Either NewSystemCreationData or NewSystemCreationDataInstance " - " must be provided")] - XEN_VMBuilderVirtualSystemCreationData REF NewSystemCreationData, - - [IN, Description("The embedded instance (MOF, not CIM-XML) of the static instance of " - "XEN_VMBuilderVirtualSystemCreationData. " - "NOTE: Either NewSystemCreationData or NewSystemCreationDataInstance " - " must be provided"), - EmbeddedInstance ( "XEN_VMBuilderVirtualSystemCreationData" )] - string NewSystemCreationDataInstance, - - [IN, Description("Type of guest (vm) OS. This defines many defaults and " - " provides bootstrap capability. "), - ValueMap { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"}, - Values { "other", "suse", "sles8", "sles9", "sles10", "sled10", - "oes2l", "oes2nw", "netware", "redhat", "rhel3", "rhel4", - "rhel5", "solaris9", "solaris10", "windows", "windowsx64", - "windowsnt", "windowsxp", "windowsxpx64", "windowsvista", - "windowsvistax64" }] - uint32 OSType, - - [IN, Description("A string containing the URL where the install source " - "can be obtained. ie:" - " nfs:host:/path " - " http://host/path " - " ftp://host/path " - " To install from virtual disk defined in the 'NewSystemCreationData' " - " instance: " - " dev:/xvda (example syntax - provide appropriate device name")] - string SourceURL, - - [IN, Description("Either path to, or the contents of, response file to automate " - "the installation of the OS. The format of the file depends on the OS. " - "Not all OS types support automated installations. " - "If path to file, must start with FILE:, then fully-qualified path " - "relative to the incubation machine. If contents, then full contents " - "of the file. Any text that doesn't start with FILE: will be considered " - "contents.")] - string ResponseFile, - - [IN, Description("Additional arguments to pass to the paravirtualized OS. " - "(No need to provide OS-specific arguments to bootstrap the " - "installation")] - string ExtraInstallArgs, - - [IN, Description("The dispatched job ID, ie ZosJobID. Only applicable " - "if this createVM call is made from the dispatcher")] - string ZosJobID, - - [IN ( false ), OUT, Description ("REF to the new " - "XEN_VMBuilderJob instance. If forceLocal=True, returns a " - "XEN_VMBuilderLocalJob instance. If false, returns a " - "XEN_VMBuilderDispatchJob instance")] - XEN_VMBuilderJob REF VMBuilderJob); - - - [Description("Cancel a vm installation job that was previously initiated.")] - boolean CancelBuildJob( - [IN, Description("The jobID of the XEN_VMBuilderJob to cancel. " - "Cancel will remove all remnants of the incubation job, leaving " - "only an entry in the XEN_VMBuilderJobRecordLog.")] - string JobID, - [IN, Description("This flag applies to distributed incubation " - "environments. It indicates whether this request should be forced " - "to occur on the local box or can be dispatched. If FALSE, " - "the ZOS job ID should be given for the JobID parameter. " - "If TRUE, the vm-install Local job ID should be given for " - "the JobID parameter.")] - boolean ForceLocal); - - [Description("Delete a vm installation job that was previously initiated. " - "Delete will remove all remnants of the incubation job, leaving " - "only an entry in the XEN_VMBuilderJobRecordLog.")] - boolean DeleteBuildJob( - [IN, Description("The jobID of the XEN_VMBuilderJob to delete. ")] - string JobID, - [IN, Description("This flag applies to distributed incubation " - "environments. It indicates whether this request should be forced " - "to occur on the local box or can be dispatched. If FALSE, " - "the ZOS job ID should be given for the JobID parameter. " - "If TRUE, the vm-install Local job ID should be given for " - "the JobID parameter.")] - boolean ForceLocal); - - [Description("Cancel a vm installation job that was previously initiated. " - "Detach will remove knowledge of the incubation job / incubated vm, " - "but it will leave the incubated vm on the system. It will also leave " - "an entry in XEN_VMBuilderJobRecordLog.")] - boolean DetachBuildJob( - [IN, Description("The jobID of the XEN_VMBuilderJob to detach. ")] - string JobID); - - - [Description("Retrieve the location (host:path) of the installation log " - "of the specified jobID.")] - string GetJobLogLocation( - [IN, Description("The jobID of the XEN_VMBuilderJob.")] - string JobID); - - [Description("VM builder service version")] - string BuilderVersion; -}; Deleted: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-04-23 20:26:34 UTC (rev 583) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-04-23 21:08:16 UTC (rev 584) @@ -1,92 +0,0 @@ -// ================================================================== -// XEN_VMBuilderVirtualSystemCreationData -// ================================================================== -[Description ( - "XEN_VMBuilderVirtualSystemCreationData defines the incubator aspects of a " - "virtual system through a set of virtualization specific properties, for " - "vm creation. " - "It is intended that incubator clients to create a static instance of this " - "class filling in appropriate properties as a means of passing all the vssd " - "specific parameters for creating a vm, in one parameter, to the CreateVM " - "method on XEN_VMBuilderService.")] -class XEN_VMBuilderVirtualSystemCreationData : CIM_VirtualSystemSettingData -{ - [Description( - "UUID contains the universal unique identifier for the virtual machine. " - "If none is given, a random UUID will be generated.")] - string UUID; - - [Description("type of virtualization. Values: " - " Unknown: undefined behavior - maybe try to determine best? " - " Para: Para Virtualization: OS Must support para virtualization. " - " Full: Full Virtualization: Hardware must support full virtualization."), - ValueMap { "0", "1", "2"}, - Values { "Unknown", "Para", "Full" }] - uint32 VirtType; - - [Description("Number of virtual CPUs for the virtual machine")] - uint8 NumVCPUs; - - [Description("Megabytes of RAM to initially allocate to the VM")] - uint32 Memory; - - [Description("Max Megabytes of RAM to allocate to the VM")] - uint32 MaxMemory; - - [Description("Disk definitions for the virtual machine." - " Format: 'PDEV,VDEV[,TYPE[,MODE[,MB]]]', where TYPE='disk' or 'cdrom' " - " ie /x/y/$$VMNAME$$/disk0,xvda,disk,w,10 " - " TAGS: if $$VMNAME$$ is found in the disk string, it will be " - " replaced by the vmName specified by parameter to " - " XEN_VMBuilderService::CreateVM ")] - string Disks[]; - - [Description("Network Interface definitions for the virtual machine." - " This is a multi-value property: each array entry represents a " - " separate value. " - " Format for each entry: " - " A comma-separated list of key/value pairs. Valid keys: " - " mac=AA.BB.CC.DD.EE.FF randomly generated if not specified" - " bridge=BRIDGE " - " model=MODEL only applicable for full-virt. can be one of: " - " 'pcnet' AMD PCnet 32 " - " 'ne2k_isa' NE2000 on ISA bus " - " 'ne2k_pci' NE2000 on PCI bus " - " 'rtl8139' Realtec 8139 " - " To define a NIC with all defaults, specify only 'default' ")] - string Nics[]; - - [Description("type of virtualized graphics hardware:" - " 'unknown': default to none " - " 'cirrus' : cirrus logic gc5446 pci vga: for full virt only. " - " 'none' : no graphics support; use serial console or network access. " - " 'para' : paravirtualized framebuffer; requires driver in os. " - " 'vesa' : standard vga with vesa extensions: for full virt only."), - ValueMap { "0", "1", "2", "3", "4"}, - Values { "Unknown", "Cirrus", "None", "Para", "Vesa" }] - uint32 GraphicsType; - - [Description("type of graphics viewer. Values: " - " Unknown: undefined behavior - default to VNC? " - " SDL: use SDL for graphics viewer - best when the vm will usually " - " be viewed locally. " - " VNC: use VNC for graphics viewer."), - ValueMap { "0", "1", "2"}, - Values { "Unknown", "SDL", "VNC" }] - uint32 GraphicsViewerType; - - [Description("CPU Architecture for the virtual machine. For incubation, also " - " serves as the constraint for where to dispatch the incubation job." ), - Values { "Unknown", "x86", "x86_64", "ia64", "ppc" }] - string CPUArchitecture; - - [Description("Port to use for VNC server")] - uint32 VNCPort; - - [Description("Field for users of this object to store additional data related " - "to this object. This is not used by the providers. It is user-defined " - "and user consumed. It is defined as a string array to allow for " - "key:value pairs within each element of the array, if the user so desires.")] - String ExtraConfigInfo[]; -}; - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-04-23 20:27:57
|
Revision: 583 http://omc.svn.sourceforge.net/omc/?rev=583&view=rev Author: jcarey Date: 2008-04-23 13:26:34 -0700 (Wed, 23 Apr 2008) Log Message: ----------- Clean up Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof Modified: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-04-23 17:45:50 UTC (rev 582) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderService.mof 2008-04-23 20:26:34 UTC (rev 583) @@ -84,10 +84,10 @@ [Description("Cancel a vm installation job that was previously initiated.")] - boolean CancelIncubationJob( - [IN, Description("The jobID of the XEN_VMIncubationJob to cancel. " + boolean CancelBuildJob( + [IN, Description("The jobID of the XEN_VMBuilderJob to cancel. " "Cancel will remove all remnants of the incubation job, leaving " - "only an entry in the XEN_VMIncubationJobRecordLog.")] + "only an entry in the XEN_VMBuilderJobRecordLog.")] string JobID, [IN, Description("This flag applies to distributed incubation " "environments. It indicates whether this request should be forced " @@ -99,9 +99,9 @@ [Description("Delete a vm installation job that was previously initiated. " "Delete will remove all remnants of the incubation job, leaving " - "only an entry in the XEN_VMIncubationJobRecordLog.")] - boolean DeleteIncubationJob( - [IN, Description("The jobID of the XEN_VMIncubationJob to delete. ")] + "only an entry in the XEN_VMBuilderJobRecordLog.")] + boolean DeleteBuildJob( + [IN, Description("The jobID of the XEN_VMBuilderJob to delete. ")] string JobID, [IN, Description("This flag applies to distributed incubation " "environments. It indicates whether this request should be forced " @@ -114,16 +114,16 @@ [Description("Cancel a vm installation job that was previously initiated. " "Detach will remove knowledge of the incubation job / incubated vm, " "but it will leave the incubated vm on the system. It will also leave " - "an entry in XEN_VMIncubationJobRecordLog.")] - boolean DetachIncubationJob( - [IN, Description("The jobID of the XEN_VMIncubationJob to detach. ")] + "an entry in XEN_VMBuilderJobRecordLog.")] + boolean DetachBuildJob( + [IN, Description("The jobID of the XEN_VMBuilderJob to detach. ")] string JobID); [Description("Retrieve the location (host:path) of the installation log " "of the specified jobID.")] string GetJobLogLocation( - [IN, Description("The jobID of the XEN_VMIncubationJob.")] + [IN, Description("The jobID of the XEN_VMBuilderJob.")] string JobID); [Description("VM builder service version")] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |