os-cmpi-xen

view src/Xen_ComputerSystemSettingData.c @ 121:4868ace2726b

Add initial consistence checks in test suite for Xen_MemoryPool, Xen_ProcessorPool and Xen_VirtualSystemManagementService.

Signed-off-by: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Jun 08 10:22:05 2007 -0600 (2007-06-08)
parents b328bc8e58a4
children dc1be661c5ee
line source
1 // Copyright (C) 2006 IBM Corporation
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 // ============================================================================
17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
18 // Contributors: Jim Fehlig, <jfehlig@novell.com>
19 // Description:
20 // ============================================================================
22 /* Include the required CMPI data types, function headers, and macros */
23 #include "cmpidt.h"
24 #include "cmpift.h"
25 #include "cmpimacs.h"
27 /* Include utility functions */
28 #include "cmpiutil.h"
30 /* Include _SBLIM_TRACE() logging support */
31 #include "cmpitrace.h"
33 /* Include Xen utilities */
34 #include "xen_utils.h"
36 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
37 #include "Xen_ComputerSystemSettingData_Resource.h"
40 // ----------------------------------------------------------------------------
41 // COMMON GLOBAL VARIABLES
42 // ----------------------------------------------------------------------------
44 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
45 static const CMPIBroker *_BROKER;
47 /* Xen session object. Initialize when the provider is loaded, close when
48 * provider unloaded. */
49 static xen_utils_session *session = NULL;
52 // ============================================================================
53 // CMPI INSTANCE PROVIDER FUNCTION TABLE
54 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // Info for the class supported by the instance provider
58 // ----------------------------------------------------------------------------
60 /* Name of the class implemented by this instance provider. */
61 /*** CUSTOMIZE FOR EACH PROVIDER ***/
62 static char * _CLASSNAME = "Xen_ComputerSystemSettingData";
64 /* NULL terminated list of key properties of this class. */
65 /*** CUSTOMIZE FOR EACH PROVIDER ***/
66 const static char * _KEYNAMES[] = {"InstanceID", NULL};
68 // ----------------------------------------------------------------------------
69 // Cleanup()
70 // Perform any necessary cleanup immediately before this provider is unloaded.
71 // ----------------------------------------------------------------------------
72 static CMPIStatus Cleanup(
73 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
74 const CMPIContext * context, /* [in] Additional context info, if any. */
75 CMPIBoolean terminating) /* [in] True if MB is terminating */
76 {
77 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
79 _SBLIM_ENTER("Cleanup");
80 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
81 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
83 if (terminating)
84 fprintf(stderr, "#### cimom terminating\n");
85 else
86 fprintf(stderr, "#### cimom NOT terminating\n");
88 if (session) {
89 xen_utils_xen_close(session);
90 session = NULL;
91 }
92 _SBLIM_RETURNSTATUS(status);
93 }
95 // ----------------------------------------------------------------------------
96 // EnumInstanceNames()
97 // Return a list of all the instances names (return their object paths only).
98 // ----------------------------------------------------------------------------
99 static CMPIStatus EnumInstanceNames(
100 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
101 const CMPIContext * context, /* [in] Additional context info, if any. */
102 const CMPIResult * results, /* [out] Results of this operation. */
103 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
104 {
105 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
106 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
107 _RESOURCE * resource; /* Handle to each system resource. */
108 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
109 int found = 0; /* Found any instances? */
111 _SBLIM_ENTER("EnumInstanceNames");
112 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
113 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
114 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
115 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
117 if (!xen_utils_validate_session(&session)) {
118 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
119 goto exit;
120 }
122 /* Get a handle to the list of system resources. */
123 if (!Xen_ComputerSystemSettingData_getResources(session, &resources)) {
124 _SBLIM_TRACE(1,("--- _getResources() failed"));
125 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
126 goto exit;
127 }
129 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
130 while (Xen_ComputerSystemSettingData_getNextResource(session, resources, &resource)) {
131 /* Create a new CMPIInstance to store this resource. */
132 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
133 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
134 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
135 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
136 goto exit;
137 }
139 /* Set the instance property values from the resource data. */
140 if (!Xen_ComputerSystemSettingData_setInstanceFromResource(resource, instance, _BROKER)) {
141 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
142 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
143 goto exit;
144 }
146 /* Free the resource data. */
147 if (!Xen_ComputerSystemSettingData_freeResource(resource)) {
148 _SBLIM_TRACE(1,("--- _freeResource() failed"));
149 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
150 goto exit;
151 }
153 /* Return the CMPIObjectPath for this instance. */
154 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
155 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
156 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
157 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
158 goto exit;
159 }
160 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
162 _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
163 CMReturnObjectPath(results, objectpath);
164 found++;
165 }
167 _SBLIM_TRACE(2,("--- %d object paths found", found));
168 CMReturnDone(results);
170 exit:
171 /* Free the list of system resources. */
172 if (!Xen_ComputerSystemSettingData_freeResources(resources)) {
173 _SBLIM_TRACE(1,("--- _freeResources() failed"));
174 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
175 }
177 _SBLIM_RETURNSTATUS(status);
178 }
180 // ----------------------------------------------------------------------------
181 // EnumInstances()
182 // Return a list of all the instances (return all the instance data).
183 // ----------------------------------------------------------------------------
184 static CMPIStatus EnumInstances(
185 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
186 const CMPIContext * context, /* [in] Additional context info, if any. */
187 const CMPIResult * results, /* [out] Results of this operation. */
188 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
189 const char ** properties) /* [in] List of desired properties (NULL=all). */
190 {
191 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
192 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
193 _RESOURCE * resource; /* Handle to each system resource. */
194 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
195 int found = 0; /* Found any resource instances? */
197 _SBLIM_ENTER("EnumInstances");
198 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
199 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
200 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
201 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
203 if (!xen_utils_validate_session(&session)) {
204 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
205 goto exit;
206 }
208 /* Get a handle to the list of system resources. */
209 if (!Xen_ComputerSystemSettingData_getResources(session, &resources)) {
210 _SBLIM_TRACE(1,("--- _getResources() failed"));
211 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
212 goto exit;
213 }
215 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
216 while (Xen_ComputerSystemSettingData_getNextResource(session, resources, &resource)) {
217 /* Create a new CMPIInstance to store this resource. */
218 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
219 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
220 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
221 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
222 goto exit;
223 }
225 /* Setup a filter to only return the desired properties. */
226 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
227 if (status.rc != CMPI_RC_OK) {
228 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
229 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
230 goto exit;
231 }
233 /* Set the instance property values from the resource data. */
234 if (!Xen_ComputerSystemSettingData_setInstanceFromResource(resource, instance, _BROKER)) {
235 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
236 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
237 goto exit;
238 }
240 /* Free the resource data. */
241 if (!Xen_ComputerSystemSettingData_freeResource(resource)) {
242 _SBLIM_TRACE(1,("--- _freeResource() failed"));
243 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
244 goto exit;
245 }
247 /* Return the CMPIInstance for this instance. */
248 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
249 CMReturnInstance(results, instance);
250 found++;
251 }
253 _SBLIM_TRACE(2,("--- %d instances found", found));
254 CMReturnDone(results);
256 exit:
257 /* Free the list of system resources. */
258 if (!Xen_ComputerSystemSettingData_freeResources(resources)) {
259 _SBLIM_TRACE(1,("--- _freeResources() failed"));
260 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
261 }
263 _SBLIM_RETURNSTATUS(status);
264 }
266 // ----------------------------------------------------------------------------
267 // GetInstance()
268 // Return the instance data for the specified instance only.
269 // ----------------------------------------------------------------------------
270 static CMPIStatus GetInstance(
271 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
272 const CMPIContext * context, /* [in] Additional context info, if any. */
273 const CMPIResult * results, /* [out] Results of this operation. */
274 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
275 const char ** properties) /* [in] List of desired properties (NULL=all). */
276 {
277 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
278 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
279 _RESOURCE * resource; /* Handle to the system resource. */
280 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
281 int found = 0; /* Found the target instance? */
283 _SBLIM_ENTER("GetInstance");
284 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
285 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
286 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
287 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
289 if (!xen_utils_validate_session(&session)) {
290 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
291 goto exit;
292 }
294 /* Get a handle to the list of system resources. */
295 if (!Xen_ComputerSystemSettingData_getResources(session, &resources)) {
296 _SBLIM_TRACE(1,("--- _getResources() failed"));
297 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
298 goto exit;
299 }
301 /* Get the target resource. */
302 found = Xen_ComputerSystemSettingData_getResourceForObjectPath(session, resources, &resource, reference);
303 if (!found || (resource == NULL)) {
304 _SBLIM_TRACE(1,("--- Target instance not found"));
305 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
306 goto exit;
307 }
309 /* Create a new CMPIInstance to store this resource. */
310 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
311 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
312 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
313 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
314 goto exit;
315 }
317 /* Setup a filter to only return the desired properties. */
318 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
319 if (status.rc != CMPI_RC_OK) {
320 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
321 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
322 goto exit;
323 }
325 /* Set the instance property values from the resource data. */
326 if (!Xen_ComputerSystemSettingData_setInstanceFromResource(resource, instance, _BROKER)) {
327 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
328 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
329 goto exit;
330 }
332 /* Free the resource data. */
333 if (!Xen_ComputerSystemSettingData_freeResource(resource)) {
334 _SBLIM_TRACE(1,("--- _freeResource() failed"));
335 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
336 goto exit;
337 }
339 /* Return the CMPIInstance for this instance. */
340 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
341 CMReturnInstance(results, instance);
343 _SBLIM_TRACE(2,("--- instance found"));
344 CMReturnDone(results);
346 exit:
347 /* Free the list of system resources. */
348 if (!Xen_ComputerSystemSettingData_freeResources(resources)) {
349 _SBLIM_TRACE(1,("--- _freeResources() failed"));
350 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
351 }
353 _SBLIM_RETURNSTATUS(status);
354 }
356 // ----------------------------------------------------------------------------
357 // SetInstance()
358 // Save modified instance data for the specified instance.
359 // ----------------------------------------------------------------------------
360 static CMPIStatus SetInstance(
361 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
362 const CMPIContext * context, /* [in] Additional context info, if any. */
363 const CMPIResult * results, /* [out] Results of this operation. */
364 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
365 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
366 const char **properties)
367 {
368 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
369 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
370 _RESOURCE * resource; /* Handle to the system resource. */
371 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
372 int found = 0; /* Found the target instance? */
374 _SBLIM_ENTER("SetInstance");
375 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
376 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
377 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
378 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
379 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
381 if (!xen_utils_validate_session(&session)) {
382 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
383 goto exit;
384 }
386 /* Get a handle to the list of system resources. */
387 if (!Xen_ComputerSystemSettingData_getResources(session, &resources)) {
388 _SBLIM_TRACE(1,("--- _getResources() failed"));
389 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
390 goto exit;
391 }
393 /* Get the target resource. */
394 found = Xen_ComputerSystemSettingData_getResourceForObjectPath(session, resources, &resource, reference);
395 if (!found || (resource == NULL)) {
396 _SBLIM_TRACE(1,("--- Target instance not found"));
397 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
398 goto exit;
399 }
401 _SBLIM_TRACE(2,("--- instance found", found));
403 /* Update the target resource data with the new instance property values. */
404 int rc = Xen_ComputerSystemSettingData_setResourceFromInstance(resource, newinstance, _BROKER);
406 /* Free the resource data. */
407 if (!Xen_ComputerSystemSettingData_freeResource(resource)) {
408 _SBLIM_TRACE(1,("--- _freeResource() failed"));
409 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
410 goto exit;
411 }
413 if (rc != 1) {
414 if (rc == -1) {
415 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
416 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
417 } else {
418 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
419 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
420 }
421 goto exit;
422 }
424 exit:
425 /* Free the list of system resources. */
426 if (!Xen_ComputerSystemSettingData_freeResources(resources)) {
427 _SBLIM_TRACE(1,("--- _freeResources() failed"));
428 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
429 }
431 _SBLIM_RETURNSTATUS(status);
432 }
434 // ----------------------------------------------------------------------------
435 // CreateInstance()
436 // Create a new instance from the specified instance data.
437 // ----------------------------------------------------------------------------
438 static CMPIStatus CreateInstance(
439 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
440 const CMPIContext * context, /* [in] Additional context info, if any. */
441 const CMPIResult * results, /* [out] Results of this operation. */
442 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
443 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
444 {
445 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
446 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
447 _RESOURCE * resource; /* Handle to the system resource. */
448 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
449 int found = 0; /* Found the target instance? */
451 _SBLIM_ENTER("CreateInstance");
452 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
453 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
454 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
455 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
456 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
458 if (!xen_utils_validate_session(&session)) {
459 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
460 goto exit;
461 }
463 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
464 reference = CMGetObjectPath(newinstance, NULL);
466 /* Get a handle to the list of system resources. */
467 if (!Xen_ComputerSystemSettingData_getResources(session, &resources)) {
468 _SBLIM_TRACE(1,("--- _getResources() failed"));
469 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
470 goto exit;
471 }
473 /* Get the target resource. */
474 found = Xen_ComputerSystemSettingData_getResourceForObjectPath(session, resources, &resource, reference);
476 /* Free the resource data. */
477 if (!Xen_ComputerSystemSettingData_freeResource(resource)) {
478 _SBLIM_TRACE(1,("--- _freeResource() failed"));
479 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
480 goto exit;
481 }
483 if (found) {
484 _SBLIM_TRACE(1,("--- Target instance already exists"));
485 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
486 goto exit;
487 }
489 /* Create a new resource with the new instance property values. */
490 int rc = Xen_ComputerSystemSettingData_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
491 if (rc != 1) {
492 if (rc == -1) {
493 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
494 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
495 } else {
496 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
497 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
498 }
499 goto exit;
500 }
502 /* Return the object path for the newly created instance. */
503 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
504 CMSetNameSpace(objectpath, namespace);
505 CMReturnObjectPath(results, objectpath);
506 CMReturnDone(results);
508 exit:
509 /* Free the list of system resources. */
510 if (!Xen_ComputerSystemSettingData_freeResources(resources)) {
511 _SBLIM_TRACE(1,("--- _freeResources() failed"));
512 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
513 }
515 _SBLIM_RETURNSTATUS(status);
516 }
518 // ----------------------------------------------------------------------------
519 // DeleteInstance()
520 // Delete or remove the specified instance from the system.
521 // ----------------------------------------------------------------------------
522 static CMPIStatus DeleteInstance(
523 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
524 const CMPIContext * context, /* [in] Additional context info, if any. */
525 const CMPIResult * results, /* [out] Results of this operation. */
526 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
527 {
528 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
529 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
530 _RESOURCE * resource; /* Handle to the system resource. */
531 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
532 int found = 0; /* Found the target instance? */
534 _SBLIM_ENTER("DeleteInstance");
535 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
536 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
537 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
538 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
540 if (!xen_utils_validate_session(&session)) {
541 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
542 goto exit;
543 }
545 /* Get a handle to the list of system resources. */
546 if (!Xen_ComputerSystemSettingData_getResources(session, &resources)) {
547 _SBLIM_TRACE(1,("--- _getResources() failed"));
548 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
549 goto exit;
550 }
552 /* Get the target resource. */
553 found = Xen_ComputerSystemSettingData_getResourceForObjectPath(session, resources, &resource, reference);
554 if (!found || (resource == NULL)) {
555 _SBLIM_TRACE(1,("--- Target instance not found"));
556 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
557 goto exit;
558 }
560 _SBLIM_TRACE(2,("--- instance found", found));
562 /* Delete the target resource. */
563 int rc = Xen_ComputerSystemSettingData_deleteResource(resources, resource);
565 /* Free the resource data. */
566 if (!Xen_ComputerSystemSettingData_freeResource(resource)) {
567 _SBLIM_TRACE(1,("--- _freeResource() failed"));
568 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
569 goto exit;
570 }
572 if (rc != 1) {
573 if (rc == -1) {
574 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
575 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
576 } else {
577 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
578 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
579 }
580 goto exit;
581 }
583 exit:
584 /* Free the list of system resources. */
585 if (!Xen_ComputerSystemSettingData_freeResources(resources)) {
586 _SBLIM_TRACE(1,("--- _freeResources() failed"));
587 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
588 }
590 _SBLIM_RETURNSTATUS(status);
591 }
594 // ----------------------------------------------------------------------------
595 // ExecQuery()
596 // Return a list of all the instances that satisfy the specified query filter.
597 // ----------------------------------------------------------------------------
598 static CMPIStatus ExecQuery(
599 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
600 const CMPIContext * context, /* [in] Additional context info, if any. */
601 const CMPIResult * results, /* [out] Results of this operation. */
602 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
603 const char * language, /* [in] Name of the query language. */
604 const char * query) /* [in] Text of the query written in the query language. */
605 {
606 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
607 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
609 _SBLIM_ENTER("ExecQuery");
610 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
611 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
612 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
613 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
614 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
615 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
617 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
618 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
620 CMReturnDone(results);
622 exit:
623 _SBLIM_RETURNSTATUS(status);
624 }
626 // ----------------------------------------------------------------------------
627 // Initialize()
628 // Perform any necessary initialization immediately after this provider is
629 // first loaded.
630 // ----------------------------------------------------------------------------
631 static void Initialize(
632 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
633 const CMPIContext * context) /* [in] Additional context info, if any. */
634 {
635 _SBLIM_ENTER("Initialize");
636 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
637 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
639 /* Initialized Xen session object. */
640 if (session == NULL)
641 xen_utils_xen_init(&session);
643 _SBLIM_RETURN();
644 }
646 // ============================================================================
647 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
648 // ============================================================================
649 CMInstanceMIStub( , Xen_ComputerSystemSettingData, _BROKER, Initialize(&mi, ctx));