os-cmpi-xen

annotate src/Xen_VirtualSystemManagementService.c @ 89:93600f4355d8

Added support for Xen_ConsoleSettingData.ConsoleConfigInfo
in Xen_VirtualSystemManagementService.DefineSystem(). This
allows specifying additional console configuration such as
vncunused=1, vncpasswd=foobar, etc.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Wed Feb 28 16:28:14 2007 -0700 (2007-02-28)
parents 9a96ebba2b60
children 66600aae1e53
rev   line source
jfehlig@9 1 // Copyright (C) 2006 IBM Corporation
jfehlig@9 2 //
jfehlig@9 3 // This library is free software; you can redistribute it and/or
jfehlig@9 4 // modify it under the terms of the GNU Lesser General Public
jfehlig@9 5 // License as published by the Free Software Foundation; either
jfehlig@9 6 // version 2.1 of the License, or (at your option) any later version.
jfehlig@9 7 //
jfehlig@9 8 // This library is distributed in the hope that it will be useful,
jfehlig@9 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
jfehlig@9 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
jfehlig@9 11 // Lesser General Public License for more details.
jfehlig@9 12 //
jfehlig@9 13 // You should have received a copy of the GNU Lesser General Public
jfehlig@9 14 // License along with this library; if not, write to the Free Software
jfehlig@9 15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
jfehlig@9 16 // ============================================================================
jfehlig@9 17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
jfehlig@33 18 // Contributors: Jim Fehlig, <jfehlig@novell.com>
jfehlig@9 19 // Description:
jfehlig@9 20 // ============================================================================
jfehlig@9 21
jfehlig@9 22 /**
jfehlig@9 23 * TODO:
jfehlig@33 24 * 1. Currently not checking if incoming embedded settings are valid in
jfehlig@9 25 * the various extrinsic method code paths within InvokeMethod().
jfehlig@9 26 */
jfehlig@9 27
jfehlig@9 28 #include <string.h>
jfehlig@9 29 #include <stdio.h>
jfehlig@22 30 #include <unistd.h>
jfehlig@33 31 #include <assert.h>
jfehlig@33 32
jfehlig@36 33 #include <xen_vm.h>
jfehlig@36 34 #include <xen_vif.h>
jfehlig@36 35 #include <xen_vbd.h>
jfehlig@87 36 #include <xen_console.h>
jfehlig@89 37 #include <xen_string_string_map.h>
jfehlig@9 38
jfehlig@47 39 /* Include utility functions */
jfehlig@47 40 #include "cmpiutil.h"
jfehlig@47 41
jfehlig@47 42 /* Include _SBLIM_TRACE() logging support */
jfehlig@47 43 #include "cmpitrace.h"
jfehlig@47 44
jfehlig@47 45 /* Include Xen utilities */
jfehlig@47 46 #include "xen_utils.h"
jfehlig@47 47
jfehlig@47 48 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
jfehlig@47 49 #include "Xen_VirtualSystemManagementService_Resource.h"
jfehlig@47 50
jfehlig@9 51 /* Include the required CMPI data types, function headers, and macros */
jfehlig@9 52 #include "cmpidt.h"
jfehlig@9 53 #include "cmpift.h"
jfehlig@9 54 #include "cmpimacs.h"
jfehlig@9 55
jfehlig@25 56 #include "provider_common.h"
jfehlig@35 57 #include "xen_utils.h"
jfehlig@9 58
jfehlig@47 59
jfehlig@9 60 // ----------------------------------------------------------------------------
jfehlig@9 61 // COMMON GLOBAL VARIABLES
jfehlig@9 62 // ----------------------------------------------------------------------------
jfehlig@9 63
jfehlig@9 64 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
jfehlig@31 65 static const CMPIBroker *_BROKER;
jfehlig@9 66
jfehlig@47 67 /* Xen session object. Initialize when the provider is loaded, close when
jfehlig@47 68 * provider unloaded. */
jfehlig@47 69 static xen_utils_session *session = NULL;
jfehlig@9 70
jfehlig@9 71
jfehlig@9 72 // ============================================================================
jfehlig@9 73 // CMPI INSTANCE PROVIDER FUNCTION TABLE
jfehlig@9 74 // ============================================================================
jfehlig@9 75
jfehlig@9 76 // ----------------------------------------------------------------------------
jfehlig@9 77 // Info for the class supported by the instance provider
jfehlig@9 78 // ----------------------------------------------------------------------------
jfehlig@9 79
jfehlig@9 80 /* Name of the class implemented by this instance provider. */
jfehlig@9 81 /*** CUSTOMIZE FOR EACH PROVIDER ***/
jfehlig@9 82 static char * _CLASSNAME = "Xen_VirtualSystemManagementService";
jfehlig@9 83
jfehlig@9 84 /* NULL terminated list of key properties of this class. */
jfehlig@9 85 /*** CUSTOMIZE FOR EACH PROVIDER ***/
jfehlig@9 86 const static char * _KEYNAMES[] = {"SystemName", "SystemCreationClassName", "Name", "CreationClassName", NULL};
jfehlig@9 87
jfehlig@9 88
jfehlig@47 89 static int create_vm(char *vsSettings, CMPIArray *resourceSettings,
jfehlig@47 90 xen_vm *result, CMPIStatus *status);
jfehlig@60 91 static int add_resource_to_vm(xen_vm_record *vmRec,
jfehlig@60 92 char *sourceSetting,
jfehlig@60 93 CMPIObjectPath **resultSetting,
jfehlig@60 94 char *namespace,
jfehlig@60 95 CMPIStatus *status);
jfehlig@47 96 static void remove_vm(xen_vm vm);
jfehlig@35 97 static int vssd2xenconfig(CMPIInstance *vssd, xen_vm_record *vm_rec, CMPIStatus *status);
jfehlig@35 98 static int proc_rasd2vmconfig(CMPIInstance *proc_rasd, xen_vm_record *vm_rec,
jfehlig@35 99 CMPIStatus *status);
jfehlig@35 100 static int mem_rasd2vmconfig(CMPIInstance *instance, xen_vm_record *vm_rec,
jfehlig@35 101 CMPIStatus *status);
jfehlig@35 102 static int disk_rasd2vmconfig(CMPIInstance *instance, xen_vbd_record **vbd_rec,
jfehlig@35 103 CMPIStatus *status);
jfehlig@35 104 static int nic_rasd2vmconfig(CMPIInstance *instance, xen_vif_record **vif_rec,
jfehlig@35 105 CMPIStatus *status);
jfehlig@87 106 static int con_rasd2vmconfig(CMPIInstance *instance, xen_console_record *con_rec,
jfehlig@87 107 CMPIStatus *status);
jfehlig@9 108 static CMPIInstance *parse_embedded_instance(char *instanceStr);
jfehlig@9 109
jfehlig@9 110
jfehlig@33 111
jfehlig@9 112 // ----------------------------------------------------------------------------
jfehlig@9 113 // Cleanup()
jfehlig@9 114 // Perform any necessary cleanup immediately before this provider is unloaded.
jfehlig@9 115 // ----------------------------------------------------------------------------
jfehlig@9 116 static CMPIStatus Cleanup(
jfehlig@9 117 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 118 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 119 CMPIBoolean terminating) /* [in] True if MB is terminating */
jfehlig@9 120 {
jfehlig@9 121 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
jfehlig@9 122
jfehlig@9 123 _SBLIM_ENTER("Cleanup");
jfehlig@9 124 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 125 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 126
jfehlig@47 127 if (session) {
jfehlig@47 128 xen_utils_xen_close(session);
jfehlig@47 129 session = NULL;
jfehlig@47 130 }
jfehlig@9 131 _SBLIM_RETURNSTATUS(status);
jfehlig@9 132 }
jfehlig@9 133
jfehlig@9 134 // ----------------------------------------------------------------------------
jfehlig@9 135 // EnumInstanceNames()
jfehlig@9 136 // Return a list of all the instances names (return their object paths only).
jfehlig@9 137 // ----------------------------------------------------------------------------
jfehlig@9 138 static CMPIStatus EnumInstanceNames(
jfehlig@9 139 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 140 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 141 const CMPIResult * results, /* [out] Results of this operation. */
jfehlig@31 142 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
jfehlig@9 143 {
jfehlig@9 144 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 145 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jfehlig@9 146 _RESOURCE * resource; /* Handle to each system resource. */
jfehlig@9 147 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jfehlig@9 148 int found = 0; /* Found any instances? */
jfehlig@9 149
jfehlig@9 150 _SBLIM_ENTER("EnumInstanceNames");
jfehlig@9 151 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 152 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 153 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jfehlig@9 154 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jfehlig@9 155
jfehlig@25 156 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 157 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 158 goto exit;
jfehlig@25 159 }
jfehlig@25 160
jfehlig@9 161 /* Get a handle to the list of system resources. */
jfehlig@9 162 if (!Xen_VirtualSystemManagementService_getResources(&resources)) {
jfehlig@9 163 _SBLIM_TRACE(1,("--- _getResources() failed"));
jfehlig@9 164 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jfehlig@9 165 goto exit;
jfehlig@9 166 }
jfehlig@9 167
jfehlig@9 168 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
jfehlig@47 169 while (Xen_VirtualSystemManagementService_getNextResource(session, resources, &resource)) {
jfehlig@9 170 /* Create a new CMPIInstance to store this resource. */
jfehlig@9 171 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
jfehlig@9 172 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
jfehlig@9 173 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
jfehlig@9 174 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
jfehlig@9 175 goto exit;
jfehlig@9 176 }
jfehlig@9 177
jfehlig@9 178 /* Set the instance property values from the resource data. */
jfehlig@9 179 if (!Xen_VirtualSystemManagementService_setInstanceFromResource(resource, instance, _BROKER)) {
jfehlig@9 180 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
jfehlig@9 181 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
jfehlig@9 182 goto exit;
jfehlig@9 183 }
jfehlig@9 184
jfehlig@9 185 /* Free the resource data. */
jfehlig@9 186 if (!Xen_VirtualSystemManagementService_freeResource(resource)) {
jfehlig@9 187 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jfehlig@9 188 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jfehlig@9 189 goto exit;
jfehlig@9 190 }
jfehlig@9 191
jfehlig@9 192 /* Return the CMPIObjectPath for this instance. */
jfehlig@9 193 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
jfehlig@9 194 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
jfehlig@9 195 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
jfehlig@9 196 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
jfehlig@9 197 goto exit;
jfehlig@9 198 }
jfehlig@9 199 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
jfehlig@9 200
jfehlig@9 201 _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
jfehlig@9 202 CMReturnObjectPath(results, objectpath);
jfehlig@9 203 found++;
jfehlig@9 204 }
jfehlig@9 205
jfehlig@9 206 _SBLIM_TRACE(2,("--- %d object paths found", found));
jfehlig@9 207 CMReturnDone(results);
jfehlig@9 208
jfehlig@9 209 exit:
jfehlig@9 210 /* Free the list of system resources. */
jfehlig@9 211 if (!Xen_VirtualSystemManagementService_freeResources(resources)) {
jfehlig@9 212 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jfehlig@9 213 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jfehlig@9 214 }
jfehlig@9 215
jfehlig@9 216 _SBLIM_RETURNSTATUS(status);
jfehlig@9 217 }
jfehlig@9 218
jfehlig@9 219 // ----------------------------------------------------------------------------
jfehlig@9 220 // EnumInstances()
jfehlig@9 221 // Return a list of all the instances (return all the instance data).
jfehlig@9 222 // ----------------------------------------------------------------------------
jfehlig@9 223 static CMPIStatus EnumInstances(
jfehlig@9 224 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 225 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 226 const CMPIResult * results, /* [out] Results of this operation. */
jfehlig@31 227 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
jfehlig@9 228 const char ** properties) /* [in] List of desired properties (NULL=all). */
jfehlig@9 229 {
jfehlig@9 230 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 231 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jfehlig@9 232 _RESOURCE * resource; /* Handle to each system resource. */
jfehlig@9 233 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jfehlig@9 234 int found = 0; /* Found any resource instances? */
jfehlig@9 235
jfehlig@9 236 _SBLIM_ENTER("EnumInstances");
jfehlig@9 237 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 238 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 239 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jfehlig@9 240 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jfehlig@9 241
jfehlig@25 242 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 243 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 244 goto exit;
jfehlig@25 245 }
jfehlig@25 246
jfehlig@9 247 /* Get a handle to the list of system resources. */
jfehlig@9 248 if (!Xen_VirtualSystemManagementService_getResources(&resources)) {
jfehlig@9 249 _SBLIM_TRACE(1,("--- _getResources() failed"));
jfehlig@9 250 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jfehlig@9 251 goto exit;
jfehlig@9 252 }
jfehlig@9 253
jfehlig@9 254 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
jfehlig@47 255 while (Xen_VirtualSystemManagementService_getNextResource(session, resources, &resource)) {
jfehlig@9 256 /* Create a new CMPIInstance to store this resource. */
jfehlig@9 257 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
jfehlig@9 258 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
jfehlig@9 259 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
jfehlig@9 260 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
jfehlig@9 261 goto exit;
jfehlig@9 262 }
jfehlig@9 263
jfehlig@9 264 /* Setup a filter to only return the desired properties. */
jfehlig@9 265 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
jfehlig@9 266 if (status.rc != CMPI_RC_OK) {
jfehlig@9 267 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
jfehlig@9 268 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
jfehlig@9 269 goto exit;
jfehlig@9 270 }
jfehlig@9 271
jfehlig@9 272 /* Set the instance property values from the resource data. */
jfehlig@9 273 if (!Xen_VirtualSystemManagementService_setInstanceFromResource(resource, instance, _BROKER)) {
jfehlig@9 274 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
jfehlig@9 275 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
jfehlig@9 276 goto exit;
jfehlig@9 277 }
jfehlig@9 278
jfehlig@9 279 /* Free the resource data. */
jfehlig@9 280 if (!Xen_VirtualSystemManagementService_freeResource(resource)) {
jfehlig@9 281 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jfehlig@9 282 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jfehlig@9 283 goto exit;
jfehlig@9 284 }
jfehlig@9 285
jfehlig@9 286 /* Return the CMPIInstance for this instance. */
jfehlig@9 287 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
jfehlig@9 288 CMReturnInstance(results, instance);
jfehlig@9 289 found++;
jfehlig@9 290 }
jfehlig@9 291
jfehlig@9 292 _SBLIM_TRACE(2,("--- %d instances found", found));
jfehlig@9 293 CMReturnDone(results);
jfehlig@9 294
jfehlig@9 295 exit:
jfehlig@9 296 /* Free the list of system resources. */
jfehlig@9 297 if (!Xen_VirtualSystemManagementService_freeResources(resources)) {
jfehlig@9 298 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jfehlig@9 299 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jfehlig@9 300 }
jfehlig@9 301
jfehlig@9 302 _SBLIM_RETURNSTATUS(status);
jfehlig@9 303 }
jfehlig@9 304
jfehlig@9 305 // ----------------------------------------------------------------------------
jfehlig@9 306 // GetInstance()
jfehlig@9 307 // Return the instance data for the specified instance only.
jfehlig@9 308 // ----------------------------------------------------------------------------
jfehlig@9 309 static CMPIStatus GetInstance(
jfehlig@9 310 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 311 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 312 const CMPIResult * results, /* [out] Results of this operation. */
jfehlig@31 313 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
jfehlig@9 314 const char ** properties) /* [in] List of desired properties (NULL=all). */
jfehlig@9 315 {
jfehlig@9 316 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 317 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jfehlig@9 318 _RESOURCE * resource; /* Handle to the system resource. */
jfehlig@9 319 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jfehlig@9 320 int found = 0; /* Found the target instance? */
jfehlig@9 321
jfehlig@9 322 _SBLIM_ENTER("GetInstance");
jfehlig@9 323 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 324 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 325 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jfehlig@9 326 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jfehlig@9 327
jfehlig@25 328 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 329 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 330 goto exit;
jfehlig@25 331 }
jfehlig@25 332
jfehlig@9 333 /* Get a handle to the list of system resources. */
jfehlig@9 334 if (!Xen_VirtualSystemManagementService_getResources(&resources)) {
jfehlig@9 335 _SBLIM_TRACE(1,("--- _getResources() failed"));
jfehlig@9 336 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jfehlig@9 337 goto exit;
jfehlig@9 338 }
jfehlig@9 339
jfehlig@9 340 /* Get the target resource. */
jfehlig@47 341 found = Xen_VirtualSystemManagementService_getResourceForObjectPath(session, resources, &resource, reference);
jfehlig@9 342 if (!found || (resource == NULL)) {
jfehlig@9 343 _SBLIM_TRACE(1,("--- Target instance not found"));
jfehlig@9 344 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
jfehlig@9 345 goto exit;
jfehlig@9 346 }
jfehlig@9 347
jfehlig@9 348 /* Create a new CMPIInstance to store this resource. */
jfehlig@9 349 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
jfehlig@9 350 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
jfehlig@9 351 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
jfehlig@9 352 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
jfehlig@9 353 goto exit;
jfehlig@9 354 }
jfehlig@9 355
jfehlig@9 356 /* Setup a filter to only return the desired properties. */
jfehlig@9 357 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
jfehlig@9 358 if (status.rc != CMPI_RC_OK) {
jfehlig@9 359 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
jfehlig@9 360 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
jfehlig@9 361 goto exit;
jfehlig@9 362 }
jfehlig@9 363
jfehlig@9 364 /* Set the instance property values from the resource data. */
jfehlig@9 365 if (!Xen_VirtualSystemManagementService_setInstanceFromResource(resource, instance, _BROKER)) {
jfehlig@9 366 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
jfehlig@9 367 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
jfehlig@9 368 goto exit;
jfehlig@9 369 }
jfehlig@9 370
jfehlig@9 371 /* Free the resource data. */
jfehlig@9 372 if (!Xen_VirtualSystemManagementService_freeResource(resource)) {
jfehlig@9 373 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jfehlig@9 374 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jfehlig@9 375 goto exit;
jfehlig@9 376 }
jfehlig@9 377
jfehlig@9 378 /* Return the CMPIInstance for this instance. */
jfehlig@9 379 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
jfehlig@9 380 CMReturnInstance(results, instance);
jfehlig@9 381
jfehlig@9 382 _SBLIM_TRACE(2,("--- instance found"));
jfehlig@9 383 CMReturnDone(results);
jfehlig@9 384
jfehlig@9 385 exit:
jfehlig@9 386 /* Free the list of system resources. */
jfehlig@9 387 if (!Xen_VirtualSystemManagementService_freeResources(resources)) {
jfehlig@9 388 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jfehlig@9 389 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jfehlig@9 390 }
jfehlig@9 391
jfehlig@9 392 _SBLIM_RETURNSTATUS(status);
jfehlig@9 393 }
jfehlig@9 394
jfehlig@9 395 // ----------------------------------------------------------------------------
jfehlig@9 396 // SetInstance()
jfehlig@9 397 // Save modified instance data for the specified instance.
jfehlig@9 398 // ----------------------------------------------------------------------------
jfehlig@9 399 static CMPIStatus SetInstance(
jfehlig@9 400 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 401 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 402 const CMPIResult * results, /* [out] Results of this operation. */
jfehlig@31 403 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
jfehlig@31 404 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
jfehlig@31 405 const char **properties)
jfehlig@9 406 {
jfehlig@9 407 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 408 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jfehlig@9 409 _RESOURCE * resource; /* Handle to the system resource. */
jfehlig@9 410 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jfehlig@9 411 int found = 0; /* Found the target instance? */
jfehlig@9 412
jfehlig@9 413 _SBLIM_ENTER("SetInstance");
jfehlig@9 414 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 415 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 416 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jfehlig@9 417 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
jfehlig@9 418 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jfehlig@9 419
jfehlig@25 420 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 421 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 422 goto exit;
jfehlig@25 423 }
jfehlig@25 424
jfehlig@9 425 /* Get a handle to the list of system resources. */
jfehlig@9 426 if (!Xen_VirtualSystemManagementService_getResources(&resources)) {
jfehlig@9 427 _SBLIM_TRACE(1,("--- _getResources() failed"));
jfehlig@9 428 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jfehlig@9 429 goto exit;
jfehlig@9 430 }
jfehlig@9 431
jfehlig@9 432 /* Get the target resource. */
jfehlig@47 433 found = Xen_VirtualSystemManagementService_getResourceForObjectPath(session, resources, &resource, reference);
jfehlig@9 434 if (!found || (resource == NULL)) {
jfehlig@9 435 _SBLIM_TRACE(1,("--- Target instance not found"));
jfehlig@9 436 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
jfehlig@9 437 goto exit;
jfehlig@9 438 }
jfehlig@9 439
jfehlig@9 440 _SBLIM_TRACE(2,("--- instance found"));
jfehlig@9 441
jfehlig@9 442 /* Update the target resource data with the new instance property values. */
jfehlig@9 443 int rc = Xen_VirtualSystemManagementService_setResourceFromInstance(resource, newinstance, _BROKER);
jfehlig@9 444
jfehlig@9 445 /* Free the resource data. */
jfehlig@9 446 if (!Xen_VirtualSystemManagementService_freeResource(resource)) {
jfehlig@9 447 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jfehlig@9 448 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jfehlig@9 449 goto exit;
jfehlig@9 450 }
jfehlig@9 451
jfehlig@9 452 if (rc != 1) {
jfehlig@9 453 if (rc == -1) {
jfehlig@9 454 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
jfehlig@9 455 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jfehlig@9 456 } else {
jfehlig@9 457 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
jfehlig@9 458 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
jfehlig@9 459 }
jfehlig@9 460 goto exit;
jfehlig@9 461 }
jfehlig@9 462
jfehlig@9 463 exit:
jfehlig@9 464 /* Free the list of system resources. */
jfehlig@9 465 if (!Xen_VirtualSystemManagementService_freeResources(resources)) {
jfehlig@9 466 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jfehlig@9 467 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jfehlig@9 468 }
jfehlig@9 469
jfehlig@9 470 _SBLIM_RETURNSTATUS(status);
jfehlig@9 471 }
jfehlig@9 472
jfehlig@9 473 // ----------------------------------------------------------------------------
jfehlig@9 474 // CreateInstance()
jfehlig@9 475 // Create a new instance from the specified instance data.
jfehlig@9 476 // ----------------------------------------------------------------------------
jfehlig@9 477 static CMPIStatus CreateInstance(
jfehlig@9 478 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 479 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 480 const CMPIResult * results, /* [out] Results of this operation. */
jfehlig@31 481 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
jfehlig@31 482 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
jfehlig@9 483 {
jfehlig@9 484 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 485 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jfehlig@9 486 _RESOURCE * resource; /* Handle to the system resource. */
jfehlig@9 487 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jfehlig@9 488 int found = 0; /* Found the target instance? */
jfehlig@9 489
jfehlig@9 490 _SBLIM_ENTER("CreateInstance");
jfehlig@9 491 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 492 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 493 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jfehlig@9 494 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
jfehlig@9 495 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jfehlig@9 496
jfehlig@25 497 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 498 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 499 goto exit;
jfehlig@25 500 }
jfehlig@25 501
jfehlig@9 502 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
jfehlig@9 503 reference = CMGetObjectPath(newinstance, NULL);
jfehlig@9 504
jfehlig@9 505 /* Get a handle to the list of system resources. */
jfehlig@9 506 if (!Xen_VirtualSystemManagementService_getResources(&resources)) {
jfehlig@9 507 _SBLIM_TRACE(1,("--- _getResources() failed"));
jfehlig@9 508 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jfehlig@9 509 goto exit;
jfehlig@9 510 }
jfehlig@9 511
jfehlig@9 512 /* Get the target resource. */
jfehlig@47 513 found = Xen_VirtualSystemManagementService_getResourceForObjectPath(session, resources, &resource, reference);
jfehlig@9 514
jfehlig@9 515 /* Free the resource data. */
jfehlig@9 516 if (!Xen_VirtualSystemManagementService_freeResource(resource)) {
jfehlig@9 517 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jfehlig@9 518 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jfehlig@9 519 goto exit;
jfehlig@9 520 }
jfehlig@9 521
jfehlig@9 522 if (found) {
jfehlig@9 523 _SBLIM_TRACE(1,("--- Target instance already exists"));
jfehlig@9 524 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
jfehlig@9 525 goto exit;
jfehlig@9 526 }
jfehlig@9 527
jfehlig@9 528 /* Create a new resource with the new instance property values. */
jfehlig@9 529 int rc = Xen_VirtualSystemManagementService_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
jfehlig@9 530 if (rc != 1) {
jfehlig@9 531 if (rc == -1) {
jfehlig@9 532 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
jfehlig@9 533 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jfehlig@9 534 } else {
jfehlig@9 535 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
jfehlig@9 536 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
jfehlig@9 537 }
jfehlig@9 538 goto exit;
jfehlig@9 539 }
jfehlig@9 540
jfehlig@9 541 /* Return the object path for the newly created instance. */
jfehlig@9 542 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
jfehlig@9 543 CMSetNameSpace(objectpath, namespace);
jfehlig@9 544 CMReturnObjectPath(results, objectpath);
jfehlig@9 545 CMReturnDone(results);
jfehlig@9 546
jfehlig@9 547 exit:
jfehlig@9 548 /* Free the list of system resources. */
jfehlig@9 549 if (!Xen_VirtualSystemManagementService_freeResources(resources)) {
jfehlig@9 550 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jfehlig@9 551 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jfehlig@9 552 }
jfehlig@9 553
jfehlig@9 554 _SBLIM_RETURNSTATUS(status);
jfehlig@9 555 }
jfehlig@9 556
jfehlig@9 557 // ----------------------------------------------------------------------------
jfehlig@9 558 // DeleteInstance()
jfehlig@9 559 // Delete or remove the specified instance from the system.
jfehlig@9 560 // ----------------------------------------------------------------------------
jfehlig@9 561 static CMPIStatus DeleteInstance(
jfehlig@9 562 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 563 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 564 const CMPIResult * results, /* [out] Results of this operation. */
jfehlig@31 565 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
jfehlig@9 566 {
jfehlig@9 567 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 568 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jfehlig@9 569 _RESOURCE * resource; /* Handle to the system resource. */
jfehlig@9 570 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jfehlig@9 571 int found = 0; /* Found the target instance? */
jfehlig@9 572
jfehlig@9 573 _SBLIM_ENTER("DeleteInstance");
jfehlig@9 574 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 575 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 576 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jfehlig@9 577 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jfehlig@9 578
jfehlig@25 579 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 580 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 581 goto exit;
jfehlig@25 582 }
jfehlig@25 583
jfehlig@9 584 /* Get a handle to the list of system resources. */
jfehlig@9 585 if (!Xen_VirtualSystemManagementService_getResources(&resources)) {
jfehlig@9 586 _SBLIM_TRACE(1,("--- _getResources() failed"));
jfehlig@9 587 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jfehlig@9 588 goto exit;
jfehlig@9 589 }
jfehlig@9 590
jfehlig@9 591 /* Get the target resource. */
jfehlig@47 592 found = Xen_VirtualSystemManagementService_getResourceForObjectPath(session, resources, &resource, reference);
jfehlig@9 593 if (!found || (resource == NULL)) {
jfehlig@9 594 _SBLIM_TRACE(1,("--- Target instance not found"));
jfehlig@9 595 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
jfehlig@9 596 goto exit;
jfehlig@9 597 }
jfehlig@9 598
jfehlig@9 599 _SBLIM_TRACE(2,("--- instance found"));
jfehlig@9 600
jfehlig@9 601 /* Delete the target resource. */
jfehlig@9 602 int rc = Xen_VirtualSystemManagementService_deleteResource(resources, resource);
jfehlig@9 603
jfehlig@9 604 /* Free the resource data. */
jfehlig@9 605 if (!Xen_VirtualSystemManagementService_freeResource(resource)) {
jfehlig@9 606 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jfehlig@9 607 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jfehlig@9 608 goto exit;
jfehlig@9 609 }
jfehlig@9 610
jfehlig@9 611 if (rc != 1) {
jfehlig@9 612 if (rc == -1) {
jfehlig@9 613 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
jfehlig@9 614 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jfehlig@9 615 } else {
jfehlig@9 616 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
jfehlig@9 617 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
jfehlig@9 618 }
jfehlig@9 619 goto exit;
jfehlig@9 620 }
jfehlig@9 621
jfehlig@9 622 exit:
jfehlig@9 623 /* Free the list of system resources. */
jfehlig@9 624 if (!Xen_VirtualSystemManagementService_freeResources(resources)) {
jfehlig@9 625 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jfehlig@9 626 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jfehlig@9 627 }
jfehlig@9 628
jfehlig@9 629 _SBLIM_RETURNSTATUS(status);
jfehlig@9 630 }
jfehlig@9 631
jfehlig@9 632
jfehlig@9 633 // ----------------------------------------------------------------------------
jfehlig@9 634 // ExecQuery()
jfehlig@9 635 // Return a list of all the instances that satisfy the specified query filter.
jfehlig@9 636 // ----------------------------------------------------------------------------
jfehlig@9 637 static CMPIStatus ExecQuery(
jfehlig@9 638 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 639 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 640 const CMPIResult * results, /* [out] Results of this operation. */
jfehlig@31 641 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
jfehlig@31 642 const char * language, /* [in] Name of the query language. */
jfehlig@31 643 const char * query) /* [in] Text of the query written in the query language. */
jfehlig@9 644 {
jfehlig@9 645 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@9 646 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jfehlig@9 647
jfehlig@9 648 _SBLIM_ENTER("ExecQuery");
jfehlig@9 649 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 650 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 651 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jfehlig@9 652 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
jfehlig@9 653 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
jfehlig@9 654 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jfehlig@9 655
jfehlig@25 656 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 657 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 658 goto exit;
jfehlig@25 659 }
jfehlig@25 660
jfehlig@9 661 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
jfehlig@9 662 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jfehlig@9 663
jfehlig@9 664 CMReturnDone(results);
jfehlig@9 665
jfehlig@9 666 exit:
jfehlig@9 667 _SBLIM_RETURNSTATUS(status);
jfehlig@9 668 }
jfehlig@9 669
jfehlig@9 670 // ----------------------------------------------------------------------------
jfehlig@47 671 // InstInitialize()
jfehlig@47 672 // Perform any necessary initialization immediately after the instance provider
jfehlig@47 673 // is first loaded.
jfehlig@9 674 // ----------------------------------------------------------------------------
jfehlig@47 675 static void InstInitialize(
jfehlig@9 676 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 677 const CMPIContext * context) /* [in] Additional context info, if any. */
jfehlig@9 678 {
jfehlig@47 679 _SBLIM_ENTER("InstInitialize");
jfehlig@9 680 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 681 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 682
jfehlig@47 683 /* Initialized Xen session object. */
jfehlig@47 684 if (session == NULL)
jfehlig@78 685 xen_utils_xen_init(&session);
jfehlig@47 686
jfehlig@9 687 _SBLIM_RETURN();
jfehlig@9 688 }
jfehlig@9 689
jfehlig@9 690
jfehlig@9 691 // ============================================================================
jfehlig@9 692 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
jfehlig@9 693 // ============================================================================
jfehlig@47 694 CMInstanceMIStub( , Xen_VirtualSystemManagementService, _BROKER, InstInitialize(&mi, ctx));
jfehlig@9 695
jfehlig@9 696
jfehlig@9 697 // ============================================================================
jfehlig@9 698 // CMPI METHOD PROVIDER FUNCTION TABLE
jfehlig@9 699 // ============================================================================
jfehlig@9 700
jfehlig@9 701 // ----------------------------------------------------------------------------
jfehlig@9 702 // MethodCleanup()
jfehlig@9 703 // Perform any necessary cleanup immediately before this provider is unloaded.
jfehlig@9 704 // ----------------------------------------------------------------------------
jfehlig@9 705 static CMPIStatus MethodCleanup(
jfehlig@31 706 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@31 707 const CMPIContext * context, /* [in] Additional context info, if any. */
jfehlig@31 708 CMPIBoolean terminating) /* [in] True if MB is terminating */
jfehlig@9 709 {
jfehlig@9 710 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
jfehlig@9 711
jfehlig@9 712 _SBLIM_ENTER("MethodCleanup");
jfehlig@9 713 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 714 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 715
jfehlig@47 716 if (session) {
jfehlig@47 717 xen_utils_xen_close(session);
jfehlig@47 718 session = NULL;
jfehlig@47 719 }
jfehlig@9 720 _SBLIM_RETURNSTATUS(status);
jfehlig@9 721 }
jfehlig@9 722
jfehlig@9 723 // ----------------------------------------------------------------------------
jfehlig@9 724 // InvokeMethod()
jfehlig@9 725 // Execute an extrinsic method on the specified instance.
jfehlig@9 726 // ----------------------------------------------------------------------------
jfehlig@9 727 static CMPIStatus InvokeMethod(
jfehlig@9 728 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self') */
jfehlig@31 729 const CMPIContext * context, /* [in] Additional context info, if any */
jfehlig@31 730 const CMPIResult * results, /* [out] Results of this operation */
jfehlig@31 731 const CMPIObjectPath * reference, /* [in] Contains the CIM namespace, classname and desired object path */
jfehlig@31 732 const char * methodname, /* [in] Name of the method to apply against the reference object */
jfehlig@31 733 const CMPIArgs * argsin, /* [in] Method input arguments */
jfehlig@9 734 CMPIArgs * argsout) /* [in] Method output arguments */
jfehlig@9 735 {
jfehlig@9 736 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */
jfehlig@9 737 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jfehlig@9 738 int rc = 0;
jfehlig@9 739 int argsInCount;
jfehlig@33 740 _RESOURCES * resources; /* Handle to the list of system resources. */
jfehlig@9 741 CMPIData argdata;
jfehlig@39 742 char error_msg[XEN_UTILS_ERROR_BUF_LEN];
jfehlig@9 743
jfehlig@9 744 _SBLIM_ENTER("InvokeMethod");
jfehlig@9 745 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@9 746 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@9 747 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jfehlig@9 748 _SBLIM_TRACE(2, ("--- methodname=\"%s\"", methodname));
jfehlig@9 749 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jfehlig@9 750
jfehlig@78 751 if (!xen_utils_validate_session(&session)) {
jfehlig@75 752 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
jfehlig@75 753 goto Exit;
jfehlig@75 754 }
jfehlig@75 755
jfehlig@9 756 argsInCount = CMGetArgCount(argsin, NULL);
jfehlig@9 757 _SBLIM_TRACE(2, ("--- # argsin=%d", argsInCount));
jfehlig@9 758
jfehlig@33 759 /* Get a handle to the list of system resources. */
jfehlig@33 760 if (!Xen_VirtualSystemManagementService_getResources(&resources)) {
jfehlig@33 761 _SBLIM_TRACE(1,("--- _getResources() failed"));
jfehlig@33 762 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jfehlig@60 763 rc = 2;
jfehlig@60 764 goto Exit;
jfehlig@33 765 }
jfehlig@33 766
jfehlig@9 767 /* Start/stop the service. */
jfehlig@9 768 if (strcmp(methodname, "StartService") == 0) {
jfehlig@47 769 if (!Xen_VirtualSystemManagementService_enableResource(session, resources, NULL)) {
jfehlig@9 770 _SBLIM_TRACE(1,("--- StartService() failed"));
jfehlig@9 771 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Method operation failed");
jfehlig@60 772 rc = 2;
jfehlig@60 773 goto Exit;
jfehlig@9 774 }
jfehlig@9 775 }
jfehlig@9 776 else if (strcmp(methodname, "StopService") == 0) {
jfehlig@47 777 if (!Xen_VirtualSystemManagementService_disableResource(session, resources, NULL)) {
jfehlig@9 778 _SBLIM_TRACE(1,("--- StopService() failed"));
jfehlig@9 779 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Method operation failed");
jfehlig@60 780 rc = 2;
jfehlig@60 781 goto Exit;
jfehlig@9 782 }
jfehlig@9 783 }
jfehlig@49 784 else if (strcmp(methodname, "DefineSystem") == 0) {
jfehlig@22 785 if (argsInCount != 3) {
jfehlig@9 786 _SBLIM_TRACE(1,("--- Incorrect number of method arguments"));
jfehlig@9 787 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Incorrect number of method arguments");
jfehlig@60 788 rc = 5;
jfehlig@60 789 goto Exit;
jfehlig@9 790 }
jfehlig@9 791
jfehlig@9 792 /* Get embedded instance of VirtualSystemSettingData. */
jfehlig@9 793 argdata = CMGetArgAt(argsin, 0, NULL, &status);
jfehlig@9 794 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) {
jfehlig@9 795 _SBLIM_TRACE(1,("--- CMGetArgAt(0) failed"));
jfehlig@9 796 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Cannot get method input argument");
jfehlig@60 797 rc = 5;
jfehlig@60 798 goto Exit;
jfehlig@9 799 }
jfehlig@9 800
jfehlig@9 801 if (argdata.type != CMPI_string) {
jfehlig@9 802 _SBLIM_TRACE(1,("--- Invalid setting type - %s", _CMPITypeName(argdata.type)));
jfehlig@9 803 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid setting type");
jfehlig@60 804 rc = 5;
jfehlig@60 805 goto Exit;
jfehlig@9 806 }
jfehlig@9 807
jfehlig@9 808 char *vsSettingData = CMGetCharPtr(argdata.value.string);
jfehlig@9 809 _SBLIM_TRACE(2,("--- vsSettingData=\"%s\"", vsSettingData));
jfehlig@9 810
jfehlig@9 811 /* Get input array of ResourceAllocationSettingData instances. */
jfehlig@9 812 argdata = CMGetArgAt(argsin, 1, NULL, &status);
jfehlig@9 813 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) {
jfehlig@9 814 _SBLIM_TRACE(1,("--- CMGetArgAt(1) failed"));
jfehlig@9 815 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Cannot get method input argument");
jfehlig@60 816 rc = 5;
jfehlig@60 817 goto Exit;
jfehlig@9 818 }
jfehlig@9 819
jfehlig@9 820 /* Check that the input arg is an array. */
jfehlig@9 821 if (!CMIsArray(argdata) || CMIsNullObject(argdata.value.array)) {
jfehlig@9 822 _SBLIM_TRACE(1,("--- Invalid method argument type. Array expected"));
jfehlig@9 823 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid method argument type. Array expected");
jfehlig@60 824 rc = 5;
jfehlig@60 825 goto Exit;
jfehlig@9 826 }
jfehlig@9 827
jfehlig@9 828 CMPIArray *resourceSettings = argdata.value.array;
jfehlig@33 829 xen_vm vm;
jfehlig@47 830 if (!create_vm(vsSettingData, resourceSettings, &vm, &status))
jfehlig@9 831 {
jfehlig@33 832 _SBLIM_TRACE(1,("--- create_vm() failed"));
jfehlig@33 833 /* status set in create_vm */
jfehlig@60 834 rc = 3;
jfehlig@60 835 goto Exit;
jfehlig@9 836 }
jfehlig@9 837
jfehlig@9 838 /* Return the objectpath for the resulting DomU in the output args */
jfehlig@9 839 CMPIObjectPath * op = CMNewObjectPath(_BROKER, namespace, "Xen_ComputerSystem", NULL);
jfehlig@9 840 CMAddKey(op, "CreationClassName", (CMPIValue *)"Xen_ComputerSystem", CMPI_chars);
jfehlig@33 841 char *vm_name;
jfehlig@47 842 if (!xen_vm_get_name_label(session->xen, &vm_name, vm)) {
jfehlig@33 843 /* Can't get the name after all of this work! Unwind this mess. */
jfehlig@47 844 remove_vm(vm);
jfehlig@50 845 xen_vm_free(vm);
jfehlig@33 846 _SBLIM_TRACE(1,("--- Unable to retrieve name of new VM"));
jfehlig@33 847 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create the virtual system");
jfehlig@60 848 rc = 3;
jfehlig@60 849 goto Exit;
jfehlig@33 850 }
jfehlig@33 851
jfehlig@33 852 CMAddKey(op, "Name", (CMPIValue *)vm_name, CMPI_chars);
jfehlig@9 853 /*
jfehlig@9 854 * WARNING: J. Fehlig
jfehlig@9 855 * What does this do?
jfehlig@9 856 *
jfehlig@9 857 * CMSetHostAndNameSpaceFromObjectPath(op, reference);
jfehlig@9 858 *
jfehlig@9 859 */
jfehlig@9 860 _SBLIM_TRACE(2,("--- VirtualSystem=%s", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
jfehlig@49 861 CMAddArg(argsout, "ResultingSystem", (CMPIValue*)&op, CMPI_ref);
jfehlig@50 862 xen_vm_free(vm);
jfehlig@9 863
jfehlig@60 864 _SBLIM_TRACE(2, ("--- DefineSystem completed with success"));
jfehlig@9 865 }
jfehlig@49 866 else if (strcmp(methodname, "AddResourceSettings") == 0) {
jfehlig@9 867 /* TODO */
jfehlig@9 868 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, NULL);
jfehlig@60 869 rc = 1;
jfehlig@60 870 goto Exit;
jfehlig@60 871 }
jfehlig@60 872 else if (strcmp(methodname, "AddResourceSetting") == 0) {
jfehlig@60 873 if (argsInCount != 2) {
jfehlig@60 874 _SBLIM_TRACE(1,("--- Incorrect number of method arguments"));
jfehlig@60 875 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Incorrect number of method arguments");
jfehlig@60 876 rc = 5;
jfehlig@60 877 goto Exit;
jfehlig@60 878 }
jfehlig@60 879
jfehlig@60 880 /* Get vm record based on VirtualSystemSettingData object path. */
jfehlig@60 881 argdata = CMGetArgAt(argsin, 0, NULL, &status);
jfehlig@60 882 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) {
jfehlig@60 883 _SBLIM_TRACE(1,("--- CMGetArgAt(0) failed"));
jfehlig@60 884 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Cannot get method input argument");
jfehlig@60 885 rc = 5;
jfehlig@60 886 goto Exit;
jfehlig@60 887 }
jfehlig@60 888
jfehlig@60 889 if (argdata.type != CMPI_ref) {
jfehlig@60 890 _SBLIM_TRACE(1,("--- Invalid setting type - %s", _CMPITypeName(argdata.type)));
jfehlig@60 891 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid setting type");
jfehlig@60 892 rc = 5;
jfehlig@60 893 goto Exit;
jfehlig@60 894 }
jfehlig@60 895
jfehlig@60 896 _SBLIM_TRACE(2, ("--- domain object path=\"%s\"", CMGetCharPtr(CDToString(_BROKER, argdata.value.ref, NULL))));
jfehlig@60 897
jfehlig@60 898 xen_vm_record *vmRec;
jfehlig@61 899 if (!xen_utils_get_domain_from_sd_OP(session, &vmRec, argdata.value.ref)) {
jfehlig@87 900 _SBLIM_TRACE(1,("--- Unable to retrieve domain record from object path"));
jfehlig@87 901 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Unable to retrieve domain record from object path");
jfehlig@60 902 rc = 5;
jfehlig@60 903 goto Exit;
jfehlig@60 904 }
jfehlig@60 905
jfehlig@60 906 /*
jfehlig@60 907 * Get input ResourceAllocationSettingData instance
jfehlig@60 908 * that will be added to domain.
jfehlig@60 909 */
jfehlig@60 910 argdata = CMGetArgAt(argsin, 1, NULL, &status);
jfehlig@60 911 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) {
jfehlig@60 912 _SBLIM_TRACE(1,("--- CMGetArgAt(1) failed"));
jfehlig@60 913 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Cannot get method input argument");
jfehlig@60 914 xen_vm_record_free(vmRec);
jfehlig@60 915 rc = 5;
jfehlig@60 916 goto Exit;
jfehlig@60 917 }
jfehlig@60 918
jfehlig@60 919 if (argdata.type != CMPI_string) {
jfehlig@60 920 _SBLIM_TRACE(1,("--- Invalid setting type - %s", _CMPITypeName(argdata.type)));
jfehlig@60 921 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid setting type");
jfehlig@60 922 rc = 5;
jfehlig@60 923 goto Exit;
jfehlig@60 924 }
jfehlig@60 925
jfehlig@60 926 char *newSetting = CMGetCharPtr(argdata.value.string);
jfehlig@60 927 _SBLIM_TRACE(2,("--- newSetting=\"%s\"", newSetting));
jfehlig@60 928
jfehlig@60 929
jfehlig@60 930 CMPIObjectPath *resultSetting;
jfehlig@60 931 if (!add_resource_to_vm(vmRec, newSetting, &resultSetting, namespace, &status))
jfehlig@60 932 {
jfehlig@60 933 _SBLIM_TRACE(1,("--- add_resource_to_vm() failed"));
jfehlig@60 934 /* status set in add_resource_to_vm */
jfehlig@60 935 xen_vm_record_free(vmRec);
jfehlig@60 936 rc = 3;
jfehlig@60 937 goto Exit;
jfehlig@60 938 }
jfehlig@60 939
jfehlig@60 940 CMAddArg(argsout, "ResultingResourceSetting",
jfehlig@60 941 (CMPIValue*)&resultSetting, CMPI_ref);
jfehlig@60 942 xen_vm_record_free(vmRec);
jfehlig@60 943
jfehlig@60 944 _SBLIM_TRACE(2, ("--- AddResourceSetting completed with success"));
jfehlig@9 945 }
jfehlig@49 946 else if (strcmp(methodname, "ModifyResourceSettings") == 0) {
jfehlig@9 947 /* TODO */
jfehlig@69 948 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jfehlig@60 949 rc = 1;
jfehlig@60 950 goto Exit;
jfehlig@49 951 }
jfehlig@49 952 else if (strcmp(methodname, "RemoveResourceSettings") == 0) {
jfehlig@49 953 /* TODO */
jfehlig@69 954 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jfehlig@60 955 rc = 1;
jfehlig@60 956 goto Exit;
jfehlig@60 957 }
jfehlig@69 958 else if (strcmp(methodname, "ModifySystemSettings") == 0) {
jfehlig@69 959 /* TODO */
jfehlig@69 960 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jfehlig@69 961 rc = 1;
jfehlig@69 962 goto Exit;
jfehlig@49 963 }
jfehlig@49 964 else if (strcmp(methodname, "DestroySystem") == 0) {
jfehlig@9 965 /* Check that the method has the correct number of arguments. */
jfehlig@9 966 if (argsInCount != 1) {
jfehlig@9 967 _SBLIM_TRACE(1,("--- Incorrect number of method arguments"));
jfehlig@9 968 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Incorrect number of method arguments");
jfehlig@60 969 rc = 5;
jfehlig@60 970 goto Exit;
jfehlig@9 971 }
jfehlig@9 972
jfehlig@9 973 /* Get object path of domain */
jfehlig@9 974 argdata = CMGetArgAt(argsin, 0, NULL, &status);
jfehlig@9 975 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) {
jfehlig@9 976 _SBLIM_TRACE(1,("--- CMGetArgAt(0) failed"));
jfehlig@9 977 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Cannot get method input argument");
jfehlig@60 978 rc = 5;
jfehlig@60 979 goto Exit;
jfehlig@9 980 }
jfehlig@9 981
jfehlig@9 982 if ((argdata.type != CMPI_ref) || CMIsNullObject(argdata.value.ref)) {
jfehlig@9 983 _SBLIM_TRACE(1,("--- Invalid parameter type - %s", _CMPITypeName(argdata.type)));
jfehlig@9 984 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid method input argument");
jfehlig@60 985 rc = 5;
jfehlig@60 986 goto Exit;
jfehlig@9 987 }
jfehlig@9 988
jfehlig@9 989 CMPIData namedata = CMGetKey(argdata.value.ref, "Name", &status);
jfehlig@9 990 char *domainname = CMGetCharPtr(namedata.value.string);
jfehlig@9 991 _SBLIM_TRACE(1,("--- domainname = %s", domainname));
jfehlig@33 992 xen_vm_set *vms;
jfehlig@47 993 if (!xen_vm_get_by_name_label(session->xen, &vms, domainname)) {
jfehlig@9 994 _SBLIM_TRACE(1,("--- Target instance not found"));
jfehlig@9 995 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
jfehlig@60 996 rc = 3;
jfehlig@60 997 goto Exit;
jfehlig@9 998 }
jfehlig@33 999 assert(vms->size == 1);
jfehlig@33 1000 xen_vm vm = vms->contents[0];
jfehlig@33 1001 enum xen_vm_power_state power_state;
jfehlig@47 1002 if (!xen_vm_get_power_state(session->xen, &power_state, vm)) {
jfehlig@47 1003 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@39 1004 _SBLIM_TRACE(1,("--- Unable to retrieve power state of vm - error = %s", error_msg));
jfehlig@33 1005 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Unable to determine power state of virtual system");
jfehlig@60 1006 rc = 3;
jfehlig@60 1007 goto Exit;
jfehlig@33 1008 }
jfehlig@33 1009
jfehlig@39 1010 _SBLIM_TRACE(1,("--- retrieved power state of vm - %", power_state));
jfehlig@39 1011
jfehlig@33 1012 if (power_state != XEN_VM_POWER_STATE_HALTED) {
jfehlig@39 1013 _SBLIM_TRACE(1,("--- calling xen_vm_clean_shutdown"));
jfehlig@47 1014 if (!xen_vm_clean_shutdown(session->xen, vm)) {
jfehlig@33 1015 _SBLIM_TRACE(1, ("--- xen_vm_clean_shutdown() failed"));
jfehlig@9 1016 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to shutdown VirtualSystem");
jfehlig@60 1017 rc = 3;
jfehlig@60 1018 goto Exit;
jfehlig@9 1019 }
jfehlig@9 1020 }
jfehlig@9 1021
jfehlig@39 1022 _SBLIM_TRACE(1,("--- calling xen_vm_destroy"));
jfehlig@47 1023 if (!xen_vm_destroy(session->xen, vm)) {
jfehlig@33 1024 _SBLIM_TRACE(1,("--- xen_vm_destroy failed"));
jfehlig@33 1025 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to destroy the virtual system");
jfehlig@60 1026 rc = 3;
jfehlig@60 1027 goto Exit;
jfehlig@9 1028 }
jfehlig@33 1029
jfehlig@9 1030 }
jfehlig@9 1031 else {
jfehlig@9 1032 _SBLIM_TRACE(1,("--- Method \"%s\" is not supported", methodname));
jfehlig@9 1033 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, NULL);
jfehlig@60 1034 rc = 5;
jfehlig@60 1035 goto Exit;
jfehlig@9 1036 }
jfehlig@9 1037
jfehlig@60 1038 Exit:
jfehlig@60 1039
jfehlig@33 1040 CMReturnData(results, (CMPIValue *)&rc, CMPI_uint32);
jfehlig@33 1041 CMReturnDone(results);
jfehlig@9 1042 _SBLIM_RETURNSTATUS(status);
jfehlig@9 1043 }
jfehlig@9 1044
jfehlig@47 1045
jfehlig@47 1046 // ----------------------------------------------------------------------------
jfehlig@47 1047 // MethodInitialize()
jfehlig@47 1048 // Perform any necessary initialization immediately after the method provider
jfehlig@47 1049 // is first loaded.
jfehlig@47 1050 // ----------------------------------------------------------------------------
jfehlig@47 1051 static void MethodInitialize(
jfehlig@47 1052 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jfehlig@47 1053 const CMPIContext * context) /* [in] Additional context info, if any. */
jfehlig@47 1054 {
jfehlig@47 1055 _SBLIM_ENTER("MethodInitialize");
jfehlig@47 1056 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@47 1057 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jfehlig@47 1058
jfehlig@47 1059 /* Initialized Xen session object. */
jfehlig@47 1060 if (session == NULL)
jfehlig@78 1061 xen_utils_xen_init(&session);
jfehlig@47 1062
jfehlig@47 1063 _SBLIM_RETURN();
jfehlig@47 1064 }
jfehlig@47 1065
jfehlig@9 1066 // ============================================================================
jfehlig@9 1067 // CMPI METHOD PROVIDER FUNCTION TABLE SETUP
jfehlig@9 1068 // ============================================================================
jfehlig@47 1069 CMMethodMIStub( , Xen_VirtualSystemManagementService, _BROKER, MethodInitialize(&mi, ctx));
jfehlig@9 1070
jfehlig@9 1071
jfehlig@35 1072 /*
jfehlig@35 1073 * Wild macro to support adding devices (vbd, vif) to as list of such
jfehlig@35 1074 * devices. To be used only in create_vm where list of devices is
jfehlig@35 1075 * collected from the incoming RASDs.
jfehlig@35 1076 */
jfehlig@39 1077 #define ADD_DEVICE_TO_LIST(list, device, type) \
jfehlig@39 1078 { \
jfehlig@39 1079 if (list == NULL) { \
jfehlig@39 1080 list = type ## _set_alloc(1); \
jfehlig@39 1081 if (list == NULL) { \
jfehlig@39 1082 _SBLIM_TRACE(1, \
jfehlig@39 1083 ("Cannot malloc memory for xen device settings list")); \
jfehlig@39 1084 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, \
jfehlig@39 1085 "Unable to malloc memory"); \
jfehlig@39 1086 type ## _free(device); \
jfehlig@39 1087 goto Error; \
jfehlig@39 1088 } \
jfehlig@39 1089 list->size = 1; \
jfehlig@39 1090 list->contents[0] = device; \
jfehlig@39 1091 } \
jfehlig@39 1092 /* List is not empty. Grow the list and add the new device */ \
jfehlig@39 1093 else { \
jfehlig@39 1094 int new_len = sizeof(type ## _set) + ((list->size + 1) * sizeof(type)); \
jfehlig@39 1095 list = realloc(list, new_len); \
jfehlig@39 1096 if (list == NULL) { \
jfehlig@39 1097 _SBLIM_TRACE(1, \
jfehlig@39 1098 ("Cannot malloc memory for xen device settings list")); \
jfehlig@39 1099 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, \
jfehlig@39 1100 "Unable to malloc memory"); \
jfehlig@39 1101 type ## _free(device); \
jfehlig@39 1102 goto Error; \
jfehlig@39 1103 } \
jfehlig@39 1104 list->contents[list->size] = device; \
jfehlig@39 1105 list->size++; \
jfehlig@39 1106 } \
jfehlig@39 1107 } \
jfehlig@35 1108
jfehlig@35 1109
jfehlig@47 1110 static int create_vm(char *vsSettings, CMPIArray *resourceSettings,
jfehlig@47 1111 xen_vm *result, CMPIStatus *status)
jfehlig@9 1112 {
jfehlig@9 1113 CMPIInstance *instance;
jfehlig@9 1114 CMPIObjectPath *objectpath;
jfehlig@9 1115 char *settingclassname;
jfehlig@87 1116 xen_vm_record *vm_rec;
jfehlig@33 1117 xen_vbd_record_set *vbds = NULL;
jfehlig@33 1118 xen_vif_record_set *vifs = NULL;
jfehlig@87 1119 xen_console_record *con_rec = NULL;
jfehlig@33 1120 xen_vm vm = NULL;
jfehlig@33 1121 int i;
jfehlig@50 1122 int ccode;
jfehlig@35 1123 char error_msg[XEN_UTILS_ERROR_BUF_LEN];
jfehlig@9 1124
jfehlig@9 1125 _SBLIM_TRACE(2,("--- vsSettings=\"%s\"", vsSettings));
jfehlig@9 1126
jfehlig@87 1127 vm_rec = xen_vm_record_alloc();
jfehlig@87 1128 if (vm_rec == NULL) {
jfehlig@87 1129 _SBLIM_TRACE(1,("--- Cannot malloc memory for vm record"));
jfehlig@87 1130 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory");
jfehlig@87 1131 return 0;
jfehlig@87 1132 }
jfehlig@87 1133
jfehlig@9 1134 instance = parse_embedded_instance(vsSettings);
jfehlig@9 1135 if (instance == NULL) { /* parser returns zero for success, non-zero for error */
jfehlig@9 1136 _SBLIM_TRACE(1,("--- Error parsing VirtualSystemSettingData: \"%s\"", vsSettings));
jfehlig@33 1137 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Cannot parse VirtualSystemSettingData");
jfehlig@33 1138
jfehlig@33 1139 return 0;
jfehlig@9 1140 }
jfehlig@9 1141
jfehlig@9 1142 objectpath = CMGetObjectPath(instance, NULL);
jfehlig@9 1143 _SBLIM_TRACE(2,("--- objectpath=%s", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
jfehlig@9 1144
jfehlig@9 1145 /* Get the class type of the setting data instance */
jfehlig@9 1146 settingclassname = CMGetCharPtr(CMGetClassName(objectpath, NULL));
jfehlig@9 1147 _SBLIM_TRACE(2,("--- settingclassname=%s", settingclassname));
jfehlig@9 1148
jfehlig@87 1149 /* Ensure we have a Xen_ComputerSystemSettingData */
jfehlig@9 1150 if (strcmp(settingclassname,"Xen_ComputerSystemSettingData") != 0) {
jfehlig@9 1151 _SBLIM_TRACE(1,("--- Unrecognized setting data class - %s", settingclassname));
jfehlig@33 1152 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Unrecognized setting data class");
jfehlig@33 1153 return 0;
jfehlig@9 1154 }
jfehlig@33 1155
jfehlig@87 1156 /* Convert the domain settings to respective xen settings. */
jfehlig@87 1157 if (!vssd2xenconfig(instance, vm_rec, status)) {
jfehlig@35 1158 _SBLIM_TRACE(1,("--- failed to convert VSSD to xen_vmrecord"));
jfehlig@87 1159 xen_vm_record_free(vm_rec);
jfehlig@35 1160 return 0;
jfehlig@9 1161 }
jfehlig@9 1162
jfehlig@87 1163
jfehlig@87 1164 /* Convert resource settings to their respecitve xen settings. */
jfehlig@9 1165 char *setting;
jfehlig@9 1166 for (i = 0; i < CMGetArrayCount(resourceSettings, NULL); i++) {
jfehlig@33 1167 CMPIData settingdata = CMGetArrayElementAt(resourceSettings, i, status);
jfehlig@33 1168 if ((status->rc != CMPI_RC_OK) || CMIsNullValue(settingdata)) {
jfehlig@9 1169 _SBLIM_TRACE(1,("--- CMGetArrayElementAt(%d) failed", i));
jfehlig@9 1170 goto Error;
jfehlig@9 1171 }
jfehlig@9 1172
jfehlig@9 1173 /* Check that the array element is an (embedded) instance */
jfehlig@9 1174 // if (settingdata.type != CMPI_instance) {
jfehlig@9 1175 if (settingdata.type != CMPI_string) {
jfehlig@9 1176 _SBLIM_TRACE(1,("--- Invalid setting type - %s", _CMPITypeName(settingdata.type)));
jfehlig@33 1177 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid resource setting data parameter");
jfehlig@9 1178 goto Error;
jfehlig@9 1179 }
jfehlig@9 1180
jfehlig@9 1181 setting = CMGetCharPtr(settingdata.value.string);
jfehlig@9 1182 _SBLIM_TRACE(2,("--- setting=\"%s\"", setting));
jfehlig@9 1183
jfehlig@9 1184 instance = parse_embedded_instance(setting);
jfehlig@9 1185
jfehlig@9 1186 if (instance == NULL) { /* Fail if we have an unparsable setting data? */
jfehlig@60 1187 _SBLIM_TRACE(1,("--- Error parsing RASD: \"%s\"", setting));
jfehlig@33 1188 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Unable to parse resource setting data parameter");
jfehlig@9 1189 goto Error;
jfehlig@9 1190 }
jfehlig@9 1191
jfehlig@9 1192 _SBLIM_TRACE(2,("--- instance=%s", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
jfehlig@9 1193 objectpath = CMGetObjectPath(instance, NULL);
jfehlig@9 1194 _SBLIM_TRACE(2,("--- objectpath=%s", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
jfehlig@9 1195
jfehlig@9 1196 /* Get the class type of the setting data instance */
jfehlig@9 1197 settingclassname = CMGetCharPtr(CMGetClassName(objectpath, NULL));
jfehlig@9 1198 _SBLIM_TRACE(2,("--- settingclassname=%s", settingclassname));
jfehlig@9 1199
jfehlig@9 1200 /* Populate config with instance data from the virtual device. */
jfehlig@9 1201 if (strcmp(settingclassname,"Xen_ProcessorSettingData") == 0) {
jfehlig@9 1202 _SBLIM_TRACE(2,("--- adding Xen_ProcessorSettingData to configuration"));
jfehlig@9 1203
jfehlig@87 1204 if (!proc_rasd2vmconfig(instance, vm_rec, status)) {
jfehlig@35 1205 _SBLIM_TRACE(1,("--- Error parsing processor settings"));
jfehlig@35 1206 goto Error;
jfehlig@9 1207 }
jfehlig@9 1208 }
jfehlig@9 1209 else if (strcmp(settingclassname,"Xen_MemorySettingData") == 0) {
jfehlig@9 1210 _SBLIM_TRACE(2,("--- adding Xen_MemorySettingData to configuration"));
jfehlig@9 1211
jfehlig@35 1212 /* Fail if duplicate memory rasd's? */
jfehlig@87 1213 if (vm_rec->memory_dynamic_max > 0) {
jfehlig@35 1214 _SBLIM_TRACE(1,("--- More than one memroy setting data specified"));
jfehlig@35 1215 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER,
jfehlig@35 1216 "More than one memory setting data specified");
jfehlig@35 1217 goto Error;
jfehlig@35 1218 }
jfehlig@35 1219
jfehlig@87 1220 if (!mem_rasd2vmconfig(instance, vm_rec, status)) {
jfehlig@35 1221 _SBLIM_TRACE(1,("--- Error parsing memory settings"));
jfehlig@35 1222 goto Error;
jfehlig@9 1223 }
jfehlig@9 1224 }
jfehlig@9 1225 else if (strcmp(settingclassname,"Xen_DiskSettingData") == 0) {
jfehlig@9 1226 _SBLIM_TRACE(2,("--- adding Xen_DiskSettingData to configuration"));
jfehlig@9 1227
jfehlig@35 1228 xen_vbd_record *vbd_rec;
jfehlig@35 1229 if (!disk_rasd2vmconfig(instance, &vbd_rec, status)) {
jfehlig@35 1230 _SBLIM_TRACE(1,("--- Error parsing disk settings"));
jfehlig@35 1231 goto Error;
jfehlig@35 1232 }
jfehlig@33 1233
jfehlig@35 1234 ADD_DEVICE_TO_LIST(vbds, vbd_rec, xen_vbd_record);
jfehlig@9 1235 }
jfehlig@9 1236 else if (strcmp(settingclassname,"Xen_NetworkPortSettingData") == 0) {
jfehlig@9 1237 _SBLIM_TRACE(2,("--- adding Xen_NetworkPortSettingData to configuration"));
jfehlig@9 1238
jfehlig@35 1239 xen_vif_record *vif_rec;
jfehlig@35 1240 if (!nic_rasd2vmconfig(instance, &vif_rec, status)) {
jfehlig@35 1241 _SBLIM_TRACE(1,("--- Error parsing network port settings"));
jfehlig@35 1242 goto Error;
jfehlig@35 1243 }
jfehlig@33 1244
jfehlig@35 1245 ADD_DEVICE_TO_LIST(vifs, vif_rec, xen_vif_record);
jfehlig@9 1246 }
jfehlig@87 1247 else if (strcmp(settingclassname,"Xen_ConsoleSettingData") == 0) {
jfehlig@87 1248 _SBLIM_TRACE(2,("--- adding Xen_ConsoleSettingData to configuration"));
jfehlig@87 1249
jfehlig@87 1250 con_rec = xen_console_record_alloc();
jfehlig@87 1251 if (con_rec == NULL) {
jfehlig@87 1252 _SBLIM_TRACE(1,("--- Cannot malloc memory for console record"));
jfehlig@87 1253 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory");
jfehlig@87 1254 goto Error;
jfehlig@87 1255 }
jfehlig@87 1256
jfehlig@87 1257 if (!con_rasd2vmconfig(instance, con_rec, status)) {
jfehlig@87 1258 _SBLIM_TRACE(1,("--- Error parsing console settings"));
jfehlig@87 1259 goto Error;
jfehlig@87 1260 }
jfehlig@87 1261 }
jfehlig@9 1262 else {
jfehlig@9 1263 _SBLIM_TRACE(1,("--- Unrecognized setting data class - %s", settingclassname));
jfehlig@9 1264 goto Error;
jfehlig@9 1265 }
jfehlig@9 1266 }
jfehlig@9 1267
jfehlig@33 1268 /* We have all of the settings. First create the vm. */
jfehlig@87 1269 if (!xen_vm_create(session->xen, &vm, vm_rec)) {
jfehlig@47 1270 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@35 1271 _SBLIM_TRACE(1,("--- xen_vm_create failed: %s", error_msg));
jfehlig@35 1272 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg);
jfehlig@33 1273 goto Error;
jfehlig@33 1274 }
jfehlig@9 1275
jfehlig@33 1276 xen_vm_record_opt vm_record_opt =
jfehlig@33 1277 {
jfehlig@33 1278 .u.handle = vm
jfehlig@33 1279 };
jfehlig@33 1280
jfehlig@33 1281 /* Add all of the virutal block devices. */
jfehlig@33 1282 for (i = 0; i < vbds->size; i++) {
jfehlig@50 1283
jfehlig@33 1284 xen_vbd_record *vbd_rec = vbds->contents[i];
jfehlig@33 1285 vbd_rec->vm = &vm_record_opt;
jfehlig@33 1286 xen_vbd new_vbd;
jfehlig@50 1287 ccode = xen_vbd_create(session->xen, &new_vbd, vbd_rec);
jfehlig@50 1288 /* Set vm field of vbd record to NULL so it is not freed */
jfehlig@50 1289 vbd_rec->vm = NULL;
jfehlig@50 1290 if (!ccode)
jfehlig@33 1291 {
jfehlig@47 1292 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@35 1293 _SBLIM_TRACE(1,("--- xen_vdb_create failed: %s", error_msg));
jfehlig@35 1294 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg);
jfehlig@33 1295 goto Error;
jfehlig@33 1296 }
jfehlig@33 1297 xen_vbd_free(new_vbd);
jfehlig@33 1298 }
jfehlig@33 1299
jfehlig@33 1300 /* Add all of the virutal network devices. */
jfehlig@33 1301 for (i = 0; i < vifs->size; i++) {
jfehlig@33 1302 xen_vif_record *vif_rec = vifs->contents[i];
jfehlig@33 1303 vif_rec->vm = &vm_record_opt;
jfehlig@33 1304 xen_vif new_vif;
jfehlig@50 1305 ccode = xen_vif_create(session->xen, &new_vif, vif_rec);
jfehlig@50 1306 /* Set vm field of vif record to NULL so it is not freed */
jfehlig@50 1307 vif_rec->vm = NULL;
jfehlig@50 1308 if (!ccode)
jfehlig@33 1309 {
jfehlig@47 1310 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@35 1311 _SBLIM_TRACE(1,("--- xen_vif_create failed %s", error_msg));
jfehlig@35 1312 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg);
jfehlig@33 1313 goto Error;
jfehlig@33 1314 }
jfehlig@33 1315 xen_vif_free(new_vif);
jfehlig@33 1316 }
jfehlig@35 1317
jfehlig@87 1318 /* Add console device if specified */
jfehlig@87 1319 if (con_rec) {
jfehlig@87 1320 con_rec->vm = &vm_record_opt;
jfehlig@87 1321 xen_console new_con;
jfehlig@87 1322 ccode = xen_console_create(session->xen, &new_con, con_rec);
jfehlig@87 1323 /* Set vm field of console record to NULL so it is not freed */
jfehlig@87 1324 con_rec->vm = NULL;
jfehlig@87 1325 if (!ccode)
jfehlig@87 1326 {
jfehlig@87 1327 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@87 1328 _SBLIM_TRACE(1,("--- xen_console_create failed %s", error_msg));
jfehlig@87 1329 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg);
jfehlig@87 1330 goto Error;
jfehlig@87 1331 }
jfehlig@87 1332 xen_console_free(new_con);
jfehlig@87 1333 }
jfehlig@87 1334
jfehlig@87 1335 xen_console_record_free(con_rec);
jfehlig@50 1336 xen_vbd_record_set_free(vbds);
jfehlig@50 1337 xen_vif_record_set_free(vifs);
jfehlig@87 1338 xen_vm_record_free(vm_rec);
jfehlig@87 1339
jfehlig@33 1340 *result = vm;
jfehlig@33 1341
jfehlig@33 1342 return 1;
jfehlig@33 1343
jfehlig@39 1344 /* Unwind if we failed.
jfehlig@39 1345 * remove_vm will nuke any vifs / vbds created and the vm.
jfehlig@39 1346 */
jfehlig@9 1347 Error:
jfehlig@33 1348 if (vm) {
jfehlig@47 1349 remove_vm(vm);
jfehlig@33 1350 xen_vm_free(vm);
jfehlig@33 1351 }
jfehlig@87 1352 xen_console_record_free(con_rec);
jfehlig@50 1353 xen_vbd_record_set_free(vbds);
jfehlig@50 1354 xen_vif_record_set_free(vifs);
jfehlig@87 1355 xen_vm_record_free(vm_rec);
jfehlig@50 1356 *result = NULL;
jfehlig@33 1357
jfehlig@33 1358 return 0;
jfehlig@33 1359 }
jfehlig@33 1360
jfehlig@33 1361
jfehlig@60 1362 static int add_resource_to_vm(xen_vm_record *vmRec,
jfehlig@60 1363 char *sourceSetting,
jfehlig@60 1364 CMPIObjectPath **resultSetting,
jfehlig@60 1365 char *namespace,
jfehlig@60 1366 CMPIStatus *status)
jfehlig@60 1367 {
jfehlig@60 1368 CMPIInstance *instance;
jfehlig@60 1369 CMPIObjectPath *op;
jfehlig@60 1370 char *settingclassname;
jfehlig@60 1371 CMPIData propertyvalue;
jfehlig@60 1372 int ccode;
jfehlig@60 1373 char instId[MAX_INSTANCEID_LEN];
jfehlig@60 1374 char error_msg[XEN_UTILS_ERROR_BUF_LEN];
jfehlig@60 1375 xen_vm_record_opt vm_record_opt =
jfehlig@60 1376 {
jfehlig@60 1377 .u.handle = vmRec->handle
jfehlig@60 1378
jfehlig@60 1379 };
jfehlig@60 1380
jfehlig@60 1381
jfehlig@60 1382 /* Parse sourceSetting - creating a CIM instance */
jfehlig@60 1383 instance = parse_embedded_instance(sourceSetting);
jfehlig@60 1384
jfehlig@60 1385 if (instance == NULL) { /* Fail if we have an unparsable setting data? */
jfehlig@60 1386 _SBLIM_TRACE(1,("--- Error parsing input RASD: \"%s\"", sourceSetting));
jfehlig@60 1387 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Unable to parse ResourceSetting parameter");
jfehlig@60 1388 return 0;
jfehlig@60 1389 }
jfehlig@60 1390
jfehlig@60 1391 _SBLIM_TRACE(2,("--- instance=%s", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
jfehlig@60 1392 op = CMGetObjectPath(instance, NULL);
jfehlig@60 1393 _SBLIM_TRACE(2,("--- objectpath=%s", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
jfehlig@60 1394
jfehlig@60 1395 /* Get the class type of the setting data instance */
jfehlig@60 1396 settingclassname = CMGetCharPtr(CMGetClassName(op, NULL));
jfehlig@60 1397 _SBLIM_TRACE(2,("--- settingclassname=%s", settingclassname));
jfehlig@60 1398
jfehlig@60 1399 /* Add the resource to the domain. */
jfehlig@60 1400 if (strcmp(settingclassname,"Xen_ProcessorSettingData") == 0) {
jfehlig@60 1401 #if 1
jfehlig@60 1402 _SBLIM_TRACE(1,("--- Adding processors not currently supported"));
jfehlig@60 1403 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, "Adding processors not currently supported");
jfehlig@60 1404 return 0;
jfehlig@60 1405
jfehlig@60 1406 #else
jfehlig@60 1407 /* Code for adding processors -- when Xen API supports it. */
jfehlig@60 1408 _SBLIM_TRACE(2,("--- adding Xen_ProcessorSettingData to configuration"));
jfehlig@60 1409 propertyvalue = CMGetProperty(instance, "VirtualQuantity", status);
jfehlig@60 1410 if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
jfehlig@60 1411 _SBLIM_TRACE(1,("--- Unable to determine VirtualQuantity in Processor RASD"));
jfehlig@60 1412 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "VirtualQuantity not specified in ResourceSetting");
jfehlig@60 1413 return 0;
jfehlig@60 1414 }
jfehlig@60 1415
jfehlig@60 1416 /* Adding cpus means just that - adding to existing amount */
jfehlig@60 1417 uint64_t cpus = propertyvalue.value.uint64 + vmRec->vcpus_number;
jfehlig@60 1418 /*
jfehlig@60 1419 * TODO:
jfehlig@60 1420 * 1. CPU weights and other scheduling parameters?
jfehlig@60 1421 */
jfehlig@60 1422 if (!xen_vm_set_vcpus_number(session->xen,
jfehlig@60 1423 vmRec->handle,
jfehlig@60 1424 cpus)) {
jfehlig@60 1425 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@60 1426 _SBLIM_TRACE(1,("--- xen_vm_set_vcpus_number failed: %s", error_msg));
jfehlig@60 1427 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg);
jfehlig@60 1428 return 0;
jfehlig@60 1429 }
jfehlig@60 1430
jfehlig@60 1431 /* Create new object path for setting */
jfehlig@60 1432 *resultSetting = CMNewObjectPath(_BROKER, namespace, "Xen_ProcessorSettingData", NULL);
jfehlig@60 1433 snprintf(instId, MAX_INSTANCEID_LEN, "Xen:%s:Processor", vmRec->name_label);
jfehlig@60 1434 CMAddKey(*resultSetting, "InstanceID", (CMPIValue *)instId, CMPI_chars);
jfehlig@60 1435 #endif
jfehlig@60 1436 }
jfehlig@60 1437 else if (strcmp(settingclassname,"Xen_MemorySettingData") == 0) {
jfehlig@60 1438 #if 1
jfehlig@60 1439 _SBLIM_TRACE(1,("--- Adding memory not currently supported"));
jfehlig@60 1440 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, "Adding memory not currently supported");
jfehlig@60 1441 return 0;
jfehlig@60 1442
jfehlig@60 1443 #else
jfehlig@60 1444 /* Code for adding memory -- when Xen API supports it. */
jfehlig@60 1445 _SBLIM_TRACE(2,("--- adding Xen_MemorySettingData to configuration"));
jfehlig@60 1446 propertyvalue = CMGetProperty(instance, "VirtualQuantity", status);
jfehlig@60 1447 if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
jfehlig@60 1448 _SBLIM_TRACE(1,("--- Unable to determine VirtualQuantity in Memory RASD"));
jfehlig@60 1449 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "VirtualQuantity not specified in ResourceSetting");
jfehlig@60 1450 return 0;
jfehlig@60 1451 }
jfehlig@60 1452
jfehlig@60 1453 /* Adding memory means just that - adding to existing amount */
jfehlig@60 1454 uint64_t mem = propertyvalue.value.uint64 + vmRec->memory_dynamic_max;
jfehlig@60 1455 if (!xen_vm_set_memory_dynamic_max(session->xen,
jfehlig@60 1456 vmRec->handle,
jfehlig@60 1457 mem)) {
jfehlig@60 1458 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@60 1459 _SBLIM_TRACE(1,("--- xen_vm_set_memory_dynamic_max failed: %s", error_msg));
jfehlig@60 1460 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg);
jfehlig@60 1461 return 0;
jfehlig@60 1462 }
jfehlig@60 1463
jfehlig@60 1464 /* Add object path to output array */
jfehlig@60 1465 *resultSetting = CMNewObjectPath(_BROKER, namespace, "Xen_MemorySettingData", NULL);
jfehlig@60 1466 snprintf(instId, MAX_INSTANCEID_LEN, "Xen:%s:Memory1", vmRec->name_label);
jfehlig@60 1467 CMAddKey(*resultSetting, "InstanceID", (CMPIValue *)instId, CMPI_chars);
jfehlig@60 1468 #endif
jfehlig@60 1469 }
jfehlig@60 1470 else if (strcmp(settingclassname,"Xen_DiskSettingData") == 0) {
jfehlig@60 1471 _SBLIM_TRACE(2,("--- adding Xen_DiskSettingData to configuration"));
jfehlig@60 1472
jfehlig@60 1473 xen_vbd_record *vbd_rec;
jfehlig@60 1474 if (!disk_rasd2vmconfig(instance, &vbd_rec, status)) {
jfehlig@60 1475 /* status set in disk_rasd2vmconfig */
jfehlig@60 1476 _SBLIM_TRACE(1,("--- Error parsing disk settings"));
jfehlig@60 1477 return 0;
jfehlig@60 1478 }
jfehlig@60 1479
jfehlig@60 1480 vbd_rec->vm = &vm_record_opt;
jfehlig@60 1481 xen_vbd new_vbd;
jfehlig@60 1482 ccode = xen_vbd_create(session->xen, &new_vbd, vbd_rec);
jfehlig@60 1483 /* Set vm field of vbd record to NULL so it is not freed */
jfehlig@60 1484 vbd_rec->vm = NULL;
jfehlig@60 1485 xen_vbd_record_free(vbd_rec);
jfehlig@60 1486 if (!ccode)
jfehlig@60 1487 {
jfehlig@60 1488 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@60 1489 _SBLIM_TRACE(1,("--- xen_vdb_create failed: %s", error_msg));
jfehlig@60 1490 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg);
jfehlig@60 1491 return 0;
jfehlig@60 1492 }
jfehlig@60 1493 xen_vbd_free(new_vbd);
jfehlig@60 1494
jfehlig@60 1495 /* Add object path to output array */
jfehlig@60 1496 *resultSetting = CMNewObjectPath(_BROKER, namespace, "Xen_DiskSettingData", NULL);
jfehlig@60 1497 snprintf(instId, MAX_INSTANCEID_LEN, "Xen:%s:Disk", vmRec->name_label);
jfehlig@60 1498 CMAddKey(*resultSetting, "InstanceID", (CMPIValue *)instId, CMPI_chars);
jfehlig@60 1499 }
jfehlig@60 1500 else if (strcmp(settingclassname,"Xen_NetworkPortSettingData") == 0) {
jfehlig@60 1501 _SBLIM_TRACE(2,("--- adding Xen_NetworkPortSettingData to configuration"));
jfehlig@60 1502 xen_vif_record *vif_rec;
jfehlig@60 1503 if (!nic_rasd2vmconfig(instance, &vif_rec, status)) {
jfehlig@60 1504 /* status set in disk_rasd2vmconfig */
jfehlig@60 1505 _SBLIM_TRACE(1,("--- Error parsing network port settings"));
jfehlig@60 1506 return 0;
jfehlig@60 1507 }
jfehlig@60 1508
jfehlig@60 1509 vif_rec->vm = &vm_record_opt;
jfehlig@60 1510 xen_vif new_vif;
jfehlig@60 1511 ccode = xen_vif_create(session->xen, &new_vif, vif_rec);
jfehlig@60 1512 /* Set vm field of vif record to NULL so it is not freed */
jfehlig@60 1513 vif_rec->vm = NULL;
jfehlig@60 1514 xen_vif_record_free(vif_rec);
jfehlig@60 1515 if (!ccode)
jfehlig@60 1516 {
jfehlig@60 1517 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
jfehlig@60 1518 _SBLIM_TRACE(1,("--- xen_vif_create failed %s", error_msg));
jfehlig@60 1519 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg);
jfehlig@60 1520 return 0;
jfehlig@60 1521 }
jfehlig@60 1522 xen_vif_free(new_vif);
jfehlig@60 1523
jfehlig@60 1524 /* Add object path to output array */
jfehlig@60 1525 *resultSetting = CMNewObjectPath(_BROKER, namespace, "Xen_NetworkPortSettingData", NULL);
jfehlig@60 1526 snprintf(instId, MAX_INSTANCEID_LEN, "Xen:%s:Vif", vmRec->name_label);
jfehlig@60 1527 CMAddKey(*resultSetting, "InstanceID", (CMPIValue *)instId, CMPI_chars);
jfehlig@60 1528 }
jfehlig@60 1529 else {
jfehlig@60 1530 _SBLIM_TRACE(1,("--- Unrecognized setting data class - %s", settingclassname));
jfehlig@60 1531 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Unrecognized ResourceSetting");
jfehlig@60 1532 return 0;
jfehlig@60 1533 }
jfehlig@60 1534
jfehlig@60 1535 return 1;
jfehlig@60 1536 }
jfehlig@60 1537
jfehlig@60 1538
jfehlig@47 1539 static void remove_vm(xen_vm vm)
jfehlig@33 1540 {
jfehlig@33 1541 xen_vbd_set *vbds;
jfehlig@33 1542 xen_vif_set *vifs;
jfehlig@33 1543 int i;
jfehlig@33 1544
jfehlig@47 1545 if (xen_vm_get_vbds(session->xen, &vbds, vm)) {
jfehlig@33 1546 for (i = 0; i < vbds->size; i++)
jfehlig@47 1547 xen_vbd_destroy(session->xen, vbds->contents[i]);
jfehlig@35 1548 }
jfehlig@35 1549
jfehlig@47 1550 if (xen_vm_get_vifs(session->xen, &vifs, vm)) {
jfehlig@35 1551 for (i = 0; i < vifs->size; i++)
jfehlig@47 1552 xen_vif_destroy(session->xen, vifs->contents[i]);
jfehlig@35 1553 }
jfehlig@35 1554
jfehlig@47 1555 xen_vm_destroy(session->xen, vm);
jfehlig@35 1556 }
jfehlig@35 1557
jfehlig@35 1558
jfehlig@35 1559 static int vssd2xenconfig(CMPIInstance *vssd, xen_vm_record *vm_rec, CMPIStatus *status)
jfehlig@35 1560 {
jfehlig@35 1561 CMPIData propertyvalue;
jfehlig@87 1562 char *vsType;;
jfehlig@35 1563
jfehlig@86 1564 /*
jfehlig@86 1565 * Get domain name.
jfehlig@86 1566 * WARNING!
jfehlig@86 1567 * Do we fail if VirtualSystemIdentifier is not specified?
jfehlig@86 1568 */
jfehlig@49 1569 propertyvalue = CMGetProperty(vssd, "VirtualSystemIdentifier", status);
jfehlig@35 1570 if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
jfehlig@49 1571 _SBLIM_TRACE(1,("--- failed to retrieve VirtualSystemIndentifier property value"));
jfehlig@49 1572 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Unable to retrieve VirtualSystemIdentifier (name) property from virtual system setting data");
jfehlig@35 1573 return 0;
jfehlig@35 1574 }
jfehlig@87 1575 vm_rec->name_label = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@86 1576
jfehlig@86 1577 /* Get UUID, if specified */
jfehlig@86 1578 propertyvalue = CMGetProperty(vssd, "UUID", status);
jfehlig@86 1579 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue))
jfehlig@87 1580 vm_rec->uuid = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@35 1581
jfehlig@88 1582 propertyvalue = CMGetProperty(vssd, "localtime", status);
jfehlig@88 1583 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue))
jfehlig@88 1584 vm_rec->platform_localtime = propertyvalue.value.boolean;
jfehlig@88 1585
jfehlig@88 1586 propertyvalue = CMGetProperty(vssd, "OnPoweroff", status);
jfehlig@88 1587 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue))
jfehlig@88 1588 vm_rec->actions_after_shutdown = propertyvalue.value.uint16;
jfehlig@88 1589
jfehlig@88 1590 propertyvalue = CMGetProperty(vssd, "OnReboot", status);
jfehlig@88 1591 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue))
jfehlig@88 1592 vm_rec->actions_after_reboot = propertyvalue.value.uint16;
jfehlig@88 1593
jfehlig@88 1594 propertyvalue = CMGetProperty(vssd, "OnCrash", status);
jfehlig@88 1595 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue))
jfehlig@88 1596 vm_rec->actions_after_crash = propertyvalue.value.uint16;
jfehlig@88 1597
jfehlig@87 1598 /* Paravirtual or HVM domain? */
jfehlig@87 1599 propertyvalue = CMGetProperty(vssd, "VirtualSystemType", status);
jfehlig@87 1600 if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
jfehlig@87 1601 _SBLIM_TRACE(1,("--- VirtualSystemType not specified"));
jfehlig@87 1602 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER,
jfehlig@87 1603 "VirtualSystemType not specified");
jfehlig@87 1604 return 0;
jfehlig@35 1605 }
jfehlig@35 1606
jfehlig@87 1607 vsType = CMGetCharPtr(propertyvalue.value.string);
jfehlig@87 1608 if (vsType == NULL) {
jfehlig@87 1609 _SBLIM_TRACE(1,("--- VirtualSystemType not specified"));
jfehlig@87 1610 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER,
jfehlig@87 1611 "VirtualSystemType not specified");
jfehlig@87 1612 return 0;
jfehlig@35 1613 }
jfehlig@87 1614
jfehlig@87 1615 if (strcasecmp(vsType, "Xen Paravirtual") == 0) {
jfehlig@87 1616
jfehlig@87 1617 propertyvalue = CMGetProperty(vssd, "Bootloader", status);
jfehlig@87 1618 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
jfehlig@87 1619 vm_rec->pv_bootloader = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@87 1620
jfehlig@87 1621 /* If Bootloader specified, get options. */
jfehlig@87 1622 /* WARNING!
jfehlig@87 1623 * Should we ensure that BootloaderOptions is specified if
jfehlig@87 1624 * Bootloader is specified? For domUloader probably but
jfehlig@87 1625 * pygrub should work with no options.
jfehlig@87 1626 */
jfehlig@87 1627 propertyvalue = CMGetProperty(vssd, "BootloaderOptions", status);
jfehlig@87 1628 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
jfehlig@87 1629 vm_rec->pv_bootloader_args = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@87 1630 }
jfehlig@87 1631 }
jfehlig@87 1632
jfehlig@87 1633 /* Only honor Kernel if Bootloader not specified. */
jfehlig@87 1634 propertyvalue = CMGetProperty(vssd, "Kernel", status);
jfehlig@87 1635 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue) &&
jfehlig@87 1636 vm_rec->pv_bootloader == NULL) {
jfehlig@87 1637 vm_rec->pv_kernel = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@87 1638
jfehlig@87 1639 /* If Kernel specified, get RAMDisk. */
jfehlig@87 1640 /* WARNING!
jfehlig@87 1641 * Should we ensure that RAMDisk is specified if
jfehlig@87 1642 * Kernel is specified? For Unix'ish guests we probably need
jfehlig@87 1643 * RAMDisk but what about OS's with no notion of RAMDisk?
jfehlig@87 1644 */
jfehlig@87 1645 propertyvalue = CMGetProperty(vssd, "RAMDisk", status);
jfehlig@87 1646 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
jfehlig@87 1647 vm_rec->pv_ramdisk = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@87 1648 }
jfehlig@87 1649 }
jfehlig@35 1650
jfehlig@87 1651 propertyvalue = CMGetProperty(vssd, "KernelOptions", status);
jfehlig@87 1652 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
jfehlig@87 1653 vm_rec->pv_args = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@87 1654 }
jfehlig@87 1655 }
jfehlig@87 1656 else if (strcasecmp(vsType, "Xen HVM") == 0) {
jfehlig@87 1657 propertyvalue = CMGetProperty(vssd, "BootOrder", status);
jfehlig@87 1658 if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
jfehlig@87 1659 _SBLIM_TRACE(1,("--- No BootOrder specified for HVM guest"));
jfehlig@87 1660 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER,
jfehlig@87 1661 "No BootOrder specified for HVM guest");
jfehlig@87 1662 return 0;
jfehlig@35 1663 }
jfehlig@87 1664 vm_rec->hvm_boot = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@88 1665
jfehlig@88 1666 propertyvalue = CMGetProperty(vssd, "stdvga", status);
jfehlig@88 1667 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue))
jfehlig@88 1668 vm_rec->platform_std_vga = propertyvalue.value.boolean;
jfehlig@87 1669 }
jfehlig@87 1670 else {
jfehlig@89 1671 _SBLIM_TRACE(1,("--- Invalid VirtualSystemType %s specified", vsType));
jfehlig@87 1672 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER,
jfehlig@87 1673 "Invalid VirtualSystemType specified");
jfehlig@87 1674 return 0;
jfehlig@35 1675 }
jfehlig@35 1676
jfehlig@35 1677 return 1;
jfehlig@35 1678 }
jfehlig@35 1679
jfehlig@35 1680
jfehlig@35 1681 static int proc_rasd2vmconfig(CMPIInstance *proc_rasd, xen_vm_record *vm_rec,
jfehlig@35 1682 CMPIStatus *status)
jfehlig@35 1683 {
jfehlig@35 1684 CMPIData propertyvalue;
jfehlig@35 1685
jfehlig@35 1686 propertyvalue = CMGetProperty(proc_rasd, "VirtualQuantity", status);
jfehlig@35 1687 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
jfehlig@35 1688 /*
jfehlig@35 1689 * TODO:
jfehlig@35 1690 * 1. Handle defaults if processors not specified.
jfehlig@35 1691 * 2. CPU weights and other scheduling parameters?
jfehlig@35 1692 */
jfehlig@35 1693 vm_rec->vcpus_number = propertyvalue.value.uint64;
jfehlig@35 1694
jfehlig@35 1695 return 1;
jfehlig@33 1696 }
jfehlig@33 1697
jfehlig@35 1698 return 0;
jfehlig@35 1699 }
jfehlig@35 1700
jfehlig@35 1701
jfehlig@35 1702 static int mem_rasd2vmconfig(CMPIInstance *mem_rasd, xen_vm_record *vm_rec,
jfehlig@35 1703 CMPIStatus *status)
jfehlig@35 1704 {
jfehlig@35 1705 CMPIData propertyvalue;
jfehlig@35 1706
jfehlig@35 1707 propertyvalue = CMGetProperty(mem_rasd, "VirtualQuantity", status);
jfehlig@35 1708 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
jfehlig@35 1709 /*
jfehlig@35 1710 * TODO:
jfehlig@35 1711 * 1. Handle defaults if memory is not specified.
jfehlig@35 1712 * 2. What is semantics of these fields? For now
jfehlig@35 1713 * set them all to the requested value.
jfehlig@35 1714 */
jfehlig@35 1715 vm_rec->memory_static_max = propertyvalue.value.uint64;
jfehlig@35 1716 vm_rec->memory_dynamic_max = propertyvalue.value.uint64;
jfehlig@35 1717 vm_rec->memory_static_min = propertyvalue.value.uint64;
jfehlig@35 1718 vm_rec->memory_dynamic_min = propertyvalue.value.uint64;
jfehlig@35 1719
jfehlig@35 1720 return 1;
jfehlig@33 1721 }
jfehlig@33 1722
jfehlig@35 1723 return 0;
jfehlig@35 1724 }
jfehlig@35 1725
jfehlig@35 1726
jfehlig@35 1727 static int disk_rasd2vmconfig(CMPIInstance *disk_rasd, xen_vbd_record **vbd_rec,
jfehlig@35 1728 CMPIStatus *status)
jfehlig@35 1729 {
jfehlig@35 1730 CMPIData propertyvalue;
jfehlig@35 1731
jfehlig@35 1732 propertyvalue = CMGetProperty(disk_rasd, "DiskConfigInfo", status);
jfehlig@35 1733 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
jfehlig@35 1734 *vbd_rec = xen_vbd_record_alloc();
jfehlig@35 1735 if (*vbd_rec == NULL) {
jfehlig@35 1736 _SBLIM_TRACE(1,("--- Cannot malloc memory for virtual block device"));
jfehlig@35 1737 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory");
jfehlig@35 1738 return 0;
jfehlig@35 1739 }
jfehlig@35 1740
jfehlig@35 1741 /* Extract the image, dev and mode params from the DiskConfigInfo string */
jfehlig@35 1742 char *tok;
jfehlig@35 1743 char *next_tok;
jfehlig@35 1744 char *string = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@35 1745 tok = strtok_r(string, ",", &next_tok);
jfehlig@35 1746 if (tok == NULL) {
jfehlig@35 1747 _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data"));
jfehlig@89 1748 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data");
jfehlig@89 1749 free(string);
jfehlig@35 1750 goto Error;
jfehlig@35 1751 }
jfehlig@35 1752 (*vbd_rec)->image = strdup(tok);
jfehlig@35 1753
jfehlig@35 1754 if ((tok = strtok_r(NULL, ",", &next_tok)) == NULL) {
jfehlig@35 1755 _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data"));
jfehlig@89 1756 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data");
jfehlig@89 1757 free(string);
jfehlig@35 1758 goto Error;
jfehlig@35 1759 }
jfehlig@35 1760 (*vbd_rec)->device = strdup(tok);
jfehlig@35 1761
jfehlig@35 1762 if ((tok = strtok_r(NULL, ",", &next_tok)) == NULL) {
jfehlig@35 1763 _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data"));
jfehlig@89 1764 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data");
jfehlig@89 1765 free(string);
jfehlig@35 1766 goto Error;
jfehlig@35 1767 }
jfehlig@35 1768 if (strcmp(tok, "w") == 0)
jfehlig@35 1769 (*vbd_rec)->mode = XEN_VBD_MODE_RW;
jfehlig@35 1770 else
jfehlig@35 1771 (*vbd_rec)->mode = XEN_VBD_MODE_RO;
jfehlig@35 1772
jfehlig@35 1773 free(string);
jfehlig@35 1774 _SBLIM_TRACE(2,("--- uname = %s", (*vbd_rec)->image));
jfehlig@35 1775 _SBLIM_TRACE(2,("--- dev = %s", (*vbd_rec)->device));
jfehlig@35 1776 _SBLIM_TRACE(2,("--- mode = %s",
jfehlig@35 1777 (*vbd_rec)->mode == XEN_VBD_MODE_RW ? "RW" : "RO"));
jfehlig@35 1778
jfehlig@35 1779 return 1;
jfehlig@35 1780 }
jfehlig@35 1781
jfehlig@35 1782 Error:
jfehlig@35 1783 /* frees fields as well */
jfehlig@35 1784 xen_vbd_record_free(*vbd_rec);
jfehlig@35 1785 *vbd_rec = NULL;
jfehlig@35 1786
jfehlig@35 1787 return 0;
jfehlig@35 1788 }
jfehlig@35 1789
jfehlig@35 1790
jfehlig@35 1791 static int nic_rasd2vmconfig(CMPIInstance *nic_rasd, xen_vif_record **vif_rec,
jfehlig@35 1792 CMPIStatus *status)
jfehlig@35 1793 {
jfehlig@35 1794 CMPIData propertyvalue;
jfehlig@35 1795
jfehlig@35 1796 /* Set the domain config data from the Xen_NetworkPortSettingData. */
jfehlig@35 1797 propertyvalue = CMGetProperty(nic_rasd, "NICConfigInfo", status);
jfehlig@89 1798 if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
jfehlig@89 1799 _SBLIM_TRACE(1,("--- No NICConfigInfo specified in network port setting data"));
jfehlig@89 1800 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "No NICConfigInfo specified in network port setting data");
jfehlig@35 1801
jfehlig@89 1802 *vif_rec = NULL;
jfehlig@89 1803 return 0;
jfehlig@89 1804 }
jfehlig@89 1805
jfehlig@89 1806 *vif_rec = xen_vif_record_alloc();
jfehlig@89 1807 if (*vif_rec == NULL) {
jfehlig@89 1808 _SBLIM_TRACE(1,("--- Cannot malloc memory for virtual network device"));
jfehlig@89 1809 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory");
jfehlig@89 1810 return 0;
jfehlig@35 1811 }
jfehlig@35 1812
jfehlig@89 1813 /* Extract the type, mac and network params from the NicConfigInfo
jfehlig@89 1814 * string. Expected syntax is "key=value,key=value" */
jfehlig@89 1815 char * next_tok;
jfehlig@89 1816 char * string = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@89 1817 char *tok = strtok_r(string, ",", &next_tok);
jfehlig@89 1818 while (tok) {
jfehlig@89 1819 if (strncmp(tok, "mac", 3) == 0)
jfehlig@89 1820 (*vif_rec)->mac = strdup(tok + 4);
jfehlig@89 1821 /*
jfehlig@89 1822 * TODO:
jfehlig@89 1823 * Map other config items in the NIC info to xen_vif_record struct.
jfehlig@89 1824 */
jfehlig@89 1825
jfehlig@89 1826 tok = strtok_r(NULL, ",", &next_tok);
jfehlig@89 1827 }
jfehlig@89 1828
jfehlig@89 1829 free(string);
jfehlig@89 1830 _SBLIM_TRACE(2,("--- mac = %s",
jfehlig@89 1831 (*vif_rec)->mac ? (*vif_rec)->mac : "not specified"));
jfehlig@89 1832
jfehlig@89 1833 return 1;
jfehlig@9 1834 }
jfehlig@9 1835
jfehlig@9 1836
jfehlig@87 1837 static int con_rasd2vmconfig(CMPIInstance *con_rasd, xen_console_record *con_rec,
jfehlig@87 1838 CMPIStatus *status)
jfehlig@87 1839 {
jfehlig@89 1840 CMPIStatus local_status = {CMPI_RC_OK, NULL};
jfehlig@87 1841 CMPIData propertyvalue;
jfehlig@60 1842
jfehlig@89 1843 propertyvalue = CMGetProperty(con_rasd, "Protocol", &local_status);
jfehlig@89 1844 if ((local_status.rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
jfehlig@87 1845 _SBLIM_TRACE(1,("--- No protocol field specified in console setting data"));
jfehlig@87 1846 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "No protocol specified in console setting data");
jfehlig@87 1847 return 0;
jfehlig@87 1848 }
jfehlig@87 1849
jfehlig@87 1850 switch (propertyvalue.value.uint16) {
jfehlig@87 1851 case 0:
jfehlig@87 1852 con_rec->protocol = XEN_CONSOLE_PROTOCOL_VT100;
jfehlig@87 1853 break;
jfehlig@87 1854 case 1:
jfehlig@87 1855 con_rec->protocol = XEN_CONSOLE_PROTOCOL_RFB;
jfehlig@87 1856 break;
jfehlig@87 1857 case 2:
jfehlig@87 1858 con_rec->protocol = XEN_CONSOLE_PROTOCOL_RDP;
jfehlig@87 1859 break;
jfehlig@87 1860 default:
jfehlig@87 1861 _SBLIM_TRACE(1,("--- Invalid protocol specified in console setting data"));
jfehlig@87 1862 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid protocol specified in console setting data");
jfehlig@87 1863 return 0;
jfehlig@87 1864 }
jfehlig@87 1865
jfehlig@89 1866 /*
jfehlig@89 1867 * Get any additional config from ConsoleConfigInfo.
jfehlig@89 1868 * Expected syntax is "key=value,key=value"
jfehlig@89 1869 */
jfehlig@89 1870 propertyvalue = CMGetProperty(con_rasd, "ConsoleConfigInfo", &local_status);
jfehlig@89 1871 if ((local_status.rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
jfehlig@89 1872 /* Count number of config items */
jfehlig@89 1873 int num_items = 0;
jfehlig@89 1874 char *next_tok;
jfehlig@89 1875 char *string = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@89 1876 char *tok = strtok_r(string, ",", &next_tok);
jfehlig@89 1877 while (tok) {
jfehlig@89 1878 num_items++;
jfehlig@89 1879 tok = strtok_r(NULL, ",", &next_tok);
jfehlig@89 1880 }
jfehlig@89 1881 free(string);
jfehlig@89 1882
jfehlig@89 1883 xen_string_string_map *con_params = xen_string_string_map_alloc(num_items);
jfehlig@89 1884 if (con_params == NULL) {
jfehlig@89 1885 _SBLIM_TRACE(1,("--- Cannot malloc memory for console options"));
jfehlig@89 1886 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory");
jfehlig@89 1887 return 0;
jfehlig@89 1888 }
jfehlig@89 1889
jfehlig@89 1890 /*
jfehlig@89 1891 * Go back through the options and populate the string map.
jfehlig@89 1892 */
jfehlig@89 1893 string = strdup(CMGetCharPtr(propertyvalue.value.string));
jfehlig@89 1894 tok = strtok_r(string, ",", &next_tok);
jfehlig@89 1895 /* If tok is NULL, then string contains only 1 key/value pair */
jfehlig@89 1896 if (tok == NULL)
jfehlig@89 1897 tok = string;
jfehlig@89 1898 int i = 0;
jfehlig@89 1899 while (tok) {
jfehlig@89 1900 char *val = strchr(tok, '=');
jfehlig@89 1901 if (val == NULL) {
jfehlig@89 1902 _SBLIM_TRACE(1,("--- Invalid console option specified in console setting data"));
jfehlig@89 1903 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid console option specified in console setting data");
jfehlig@89 1904 xen_string_string_map_free(con_params);
jfehlig@89 1905 free(string);
jfehlig@89 1906 return 0;
jfehlig@89 1907 }
jfehlig@89 1908 *val = '\0';
jfehlig@89 1909 val++;
jfehlig@89 1910 con_params->contents[i].key = strdup(tok);
jfehlig@89 1911 con_params->contents[i].val = strdup(val);
jfehlig@89 1912 i++;
jfehlig@89 1913 tok = strtok_r(NULL, ",", &next_tok);
jfehlig@89 1914 }
jfehlig@89 1915
jfehlig@89 1916 con_rec->other_config = con_params;
jfehlig@89 1917 free(string);
jfehlig@89 1918 }
jfehlig@89 1919
jfehlig@87 1920 return 1;
jfehlig@87 1921 }
jfehlig@87 1922
jfehlig@87 1923
jfehlig@87 1924
jfehlig@9 1925 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
jfehlig@9 1926 // THE FOLLOWING CODE IS REQUIRED UNTIL EMBEDDEDOBJECT SUPPORT IS WORKING!!!
jfehlig@9 1927 //
jfehlig@9 1928 static CMPIInstance *parse_embedded_instance(char *instanceStr)
jfehlig@9 1929 {
jfehlig@9 1930 char filename[L_tmpnam];
jfehlig@9 1931 FILE *fd;
jfehlig@9 1932 int rc;
jfehlig@9 1933 CMPIInstance *instance;
jfehlig@9 1934
jfehlig@9 1935 _SBLIM_TRACE(2,("--- parsing instance: \"%s\"", instanceStr));
jfehlig@9 1936
jfehlig@9 1937 /* Store the embedded Xen_*SettingData string data in a file for parsing */
jfehlig@9 1938 tmpnam(filename);
jfehlig@9 1939 fd = fopen(filename, "w");
jfehlig@9 1940 fprintf(fd, "%s", instanceStr);
jfehlig@9 1941 fclose(fd);
jfehlig@9 1942
jfehlig@9 1943 fd = fopen(filename, "r");
jfehlig@9 1944 Xen_SettingDatayyrestart(fd);
jfehlig@9 1945
jfehlig@9 1946 /* Parse the embedded Xen_*SettingData string data into a CMPIInstance */
jfehlig@9 1947 rc = Xen_SettingDatayyparseinstance(_BROKER, &instance);
jfehlig@9 1948 fclose(fd);
jfehlig@9 1949 remove(filename);
jfehlig@9 1950 if (rc != 0) { /* parser returns zero for success, non-zero for error */
jfehlig@9 1951 _SBLIM_TRACE(1,("--- error parsing instance"));
jfehlig@9 1952 return NULL;
jfehlig@9 1953 }
jfehlig@9 1954
jfehlig@9 1955 _SBLIM_TRACE(2,("--- parsed instance: \"%s\"",
jfehlig@9 1956 CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
jfehlig@9 1957 return instance;
jfehlig@9 1958 }