os-cmpi-xen

view src/Xen_ConsoleSettingData.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 75019e01e546
children da5a3ccd0c25
line source
1 // Copyright (C) 2007 Novell, Inc.
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: Jim Fehlig <jfehlig@novell.com>
18 // Contributors:
19 // Description: This file implements the WBEM operations for Xen console
20 // setting data.
21 // ============================================================================
23 /* Include the required CMPI data types, function headers, and macros */
24 #include "cmpidt.h"
25 #include "cmpift.h"
26 #include "cmpimacs.h"
28 /* Include utility functions */
29 #include "cmpiutil.h"
31 /* Include _SBLIM_TRACE() logging support */
32 #include "cmpitrace.h"
34 /* Include Xen utilities */
35 #include "xen_utils.h"
37 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
38 #include "Xen_ConsoleSettingData_Resource.h"
41 // ----------------------------------------------------------------------------
42 // COMMON GLOBAL VARIABLES
43 // ----------------------------------------------------------------------------
45 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
46 static const CMPIBroker *_BROKER;
48 /* Xen session object. Initialize when the provider is loaded, close when
49 * provider unloaded. */
50 static xen_utils_session *session = NULL;
53 // ============================================================================
54 // CMPI INSTANCE PROVIDER FUNCTION TABLE
55 // ============================================================================
57 // ----------------------------------------------------------------------------
58 // Info for the class supported by the instance provider
59 // ----------------------------------------------------------------------------
61 /* Name of the class implemented by this instance provider. */
62 /*** CUSTOMIZE FOR EACH PROVIDER ***/
63 static char * _CLASSNAME = "Xen_ConsoleSettingData";
65 /* NULL terminated list of key properties of this class. */
66 /*** CUSTOMIZE FOR EACH PROVIDER ***/
67 const static char * _KEYNAMES[] = {"InstanceID", NULL};
69 // ----------------------------------------------------------------------------
70 // Cleanup()
71 // Perform any necessary cleanup immediately before this provider is unloaded.
72 // ----------------------------------------------------------------------------
73 static CMPIStatus Cleanup(
74 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
75 const CMPIContext * context, /* [in] Additional context info, if any. */
76 CMPIBoolean terminating) /* [in] True if MB is terminating */
77 {
78 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
80 _SBLIM_ENTER("Cleanup");
81 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
82 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
84 if (session) {
85 xen_utils_xen_close(session);
86 session = NULL;
87 }
88 _SBLIM_RETURNSTATUS(status);
89 }
91 // ----------------------------------------------------------------------------
92 // EnumInstanceNames()
93 // Return a list of all the instances names (return their object paths only).
94 // ----------------------------------------------------------------------------
95 static CMPIStatus EnumInstanceNames(
96 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
97 const CMPIContext * context, /* [in] Additional context info, if any. */
98 const CMPIResult * results, /* [out] Results of this operation. */
99 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
100 {
101 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
102 _RESOURCES * resources; /* Handle to the list of system resources. */
103 _RESOURCE * resource; /* Handle to each system resource. */
104 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
105 int found = 0; /* Found any instances? */
107 _SBLIM_ENTER("EnumInstanceNames");
108 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
109 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
110 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
111 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
113 if (!xen_utils_validate_session(&session)) {
114 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
115 goto exit;
116 }
118 /* Get a handle to the list of system resources. */
119 if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
120 _SBLIM_TRACE(1,("--- _getResources() failed"));
121 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
122 goto exit;
123 }
125 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
126 while (Xen_ConsoleSettingData_getNextResource(session, resources, &resource)) {
127 /* Create a new CMPIInstance to store this resource. */
128 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
129 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
130 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
131 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
132 goto exit;
133 }
135 /* Set the instance property values from the resource data. */
136 if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
137 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
138 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
139 goto exit;
140 }
142 /* Free the resource data. */
143 if (!Xen_ConsoleSettingData_freeResource(resource)) {
144 _SBLIM_TRACE(1,("--- _freeResource() failed"));
145 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
146 goto exit;
147 }
149 /* Return the CMPIObjectPath for this instance. */
150 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
151 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
152 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
153 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
154 goto exit;
155 }
156 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
158 _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
159 CMReturnObjectPath(results, objectpath);
160 found++;
161 }
163 _SBLIM_TRACE(2,("--- %d object paths found", found));
164 CMReturnDone(results);
166 exit:
167 /* Free the list of system resources. */
168 if (!Xen_ConsoleSettingData_freeResources(resources)) {
169 _SBLIM_TRACE(1,("--- _freeResources() failed"));
170 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
171 }
173 _SBLIM_RETURNSTATUS(status);
174 }
176 // ----------------------------------------------------------------------------
177 // EnumInstances()
178 // Return a list of all the instances (return all the instance data).
179 // ----------------------------------------------------------------------------
180 static CMPIStatus EnumInstances(
181 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
182 const CMPIContext * context, /* [in] Additional context info, if any. */
183 const CMPIResult * results, /* [out] Results of this operation. */
184 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
185 const char ** properties) /* [in] List of desired properties (NULL=all). */
186 {
187 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
188 _RESOURCES * resources; /* Handle to the list of system resources. */
189 _RESOURCE * resource; /* Handle to each system resource. */
190 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
191 int found = 0; /* Found any resource instances? */
193 _SBLIM_ENTER("EnumInstances");
194 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
195 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
196 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
197 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
199 if (!xen_utils_validate_session(&session)) {
200 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
201 goto exit;
202 }
204 /* Get a handle to the list of system resources. */
205 if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
206 _SBLIM_TRACE(1,("--- _getResources() failed"));
207 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
208 goto exit;
209 }
211 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
212 while (Xen_ConsoleSettingData_getNextResource(session, resources, &resource)) {
213 /* Create a new CMPIInstance to store this resource. */
214 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
215 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
216 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
217 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
218 goto exit;
219 }
221 /* Setup a filter to only return the desired properties. */
222 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
223 if (status.rc != CMPI_RC_OK) {
224 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
225 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
226 goto exit;
227 }
229 /* Set the instance property values from the resource data. */
230 if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
231 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
232 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
233 goto exit;
234 }
236 /* Free the resource data. */
237 if (!Xen_ConsoleSettingData_freeResource(resource)) {
238 _SBLIM_TRACE(1,("--- _freeResource() failed"));
239 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
240 goto exit;
241 }
243 /* Return the CMPIInstance for this instance. */
244 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
245 CMReturnInstance(results, instance);
246 found++;
247 }
249 _SBLIM_TRACE(2,("--- %d instances found", found));
250 CMReturnDone(results);
252 exit:
253 /* Free the list of system resources. */
254 if (!Xen_ConsoleSettingData_freeResources(resources)) {
255 _SBLIM_TRACE(1,("--- _freeResources() failed"));
256 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
257 }
259 _SBLIM_RETURNSTATUS(status);
260 }
262 // ----------------------------------------------------------------------------
263 // GetInstance()
264 // Return the instance data for the specified instance only.
265 // ----------------------------------------------------------------------------
266 static CMPIStatus GetInstance(
267 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
268 const CMPIContext * context, /* [in] Additional context info, if any. */
269 const CMPIResult * results, /* [out] Results of this operation. */
270 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
271 const char ** properties) /* [in] List of desired properties (NULL=all). */
272 {
273 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
274 _RESOURCES * resources; /* Handle to the list of system resources. */
275 _RESOURCE * resource; /* Handle to the system resource. */
276 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
277 int found = 0; /* Found the target instance? */
279 _SBLIM_ENTER("GetInstance");
280 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
281 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
282 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
283 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
285 if (!xen_utils_validate_session(&session)) {
286 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
287 goto exit;
288 }
290 /* Get a handle to the list of system resources. */
291 if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
292 _SBLIM_TRACE(1,("--- _getResources() failed"));
293 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
294 goto exit;
295 }
297 /* Get the target resource. */
298 found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
299 if (!found || (resource == NULL)) {
300 _SBLIM_TRACE(1,("--- Target instance not found"));
301 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
302 goto exit;
303 }
305 /* Create a new CMPIInstance to store this resource. */
306 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
307 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
308 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
309 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
310 goto exit;
311 }
313 /* Setup a filter to only return the desired properties. */
314 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
315 if (status.rc != CMPI_RC_OK) {
316 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
317 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
318 goto exit;
319 }
321 /* Set the instance property values from the resource data. */
322 if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
323 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
324 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
325 goto exit;
326 }
328 /* Free the resource data. */
329 if (!Xen_ConsoleSettingData_freeResource(resource)) {
330 _SBLIM_TRACE(1,("--- _freeResource() failed"));
331 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
332 goto exit;
333 }
335 /* Return the CMPIInstance for this instance. */
336 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
337 CMReturnInstance(results, instance);
339 _SBLIM_TRACE(2,("--- instance found"));
340 CMReturnDone(results);
342 exit:
343 /* Free the list of system resources. */
344 if (!Xen_ConsoleSettingData_freeResources(resources)) {
345 _SBLIM_TRACE(1,("--- _freeResources() failed"));
346 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
347 }
349 _SBLIM_RETURNSTATUS(status);
350 }
352 // ----------------------------------------------------------------------------
353 // SetInstance()
354 // Save modified instance data for the specified instance.
355 // ----------------------------------------------------------------------------
356 static CMPIStatus SetInstance(
357 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
358 const CMPIContext * context, /* [in] Additional context info, if any. */
359 const CMPIResult * results, /* [out] Results of this operation. */
360 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
361 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
362 const char **properties)
363 {
364 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
365 _RESOURCES * resources; /* Handle to the list of system resources. */
366 _RESOURCE * resource; /* Handle to the system resource. */
367 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
368 int found = 0; /* Found the target instance? */
370 _SBLIM_ENTER("SetInstance");
371 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
372 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
373 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
374 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
375 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
377 if (!xen_utils_validate_session(&session)) {
378 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
379 goto exit;
380 }
382 /* Get a handle to the list of system resources. */
383 if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
384 _SBLIM_TRACE(1,("--- _getResources() failed"));
385 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
386 goto exit;
387 }
389 /* Get the target resource. */
390 found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
391 if (!found || (resource == NULL)) {
392 _SBLIM_TRACE(1,("--- Target instance not found"));
393 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
394 goto exit;
395 }
397 _SBLIM_TRACE(2,("--- instance found", found));
399 /* Update the target resource data with the new instance property values. */
400 int rc = Xen_ConsoleSettingData_setResourceFromInstance(resource, newinstance, _BROKER);
402 /* Free the resource data. */
403 if (!Xen_ConsoleSettingData_freeResource(resource)) {
404 _SBLIM_TRACE(1,("--- _freeResource() failed"));
405 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
406 goto exit;
407 }
409 if (rc != 1) {
410 if (rc == -1) {
411 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
412 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
413 } else {
414 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
415 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
416 }
417 goto exit;
418 }
420 exit:
421 /* Free the list of system resources. */
422 if (!Xen_ConsoleSettingData_freeResources(resources)) {
423 _SBLIM_TRACE(1,("--- _freeResources() failed"));
424 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
425 }
427 _SBLIM_RETURNSTATUS(status);
428 }
430 // ----------------------------------------------------------------------------
431 // CreateInstance()
432 // Create a new instance from the specified instance data.
433 // ----------------------------------------------------------------------------
434 static CMPIStatus CreateInstance(
435 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
436 const CMPIContext * context, /* [in] Additional context info, if any. */
437 const CMPIResult * results, /* [out] Results of this operation. */
438 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
439 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
440 {
441 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
442 _RESOURCES * resources; /* Handle to the list of system resources. */
443 _RESOURCE * resource; /* Handle to the system resource. */
444 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
445 int found = 0; /* Found the target instance? */
447 _SBLIM_ENTER("CreateInstance");
448 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
449 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
450 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
451 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
452 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
454 if (!xen_utils_validate_session(&session)) {
455 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
456 goto exit;
457 }
459 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
460 reference = CMGetObjectPath(newinstance, NULL);
462 /* Get a handle to the list of system resources. */
463 if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
464 _SBLIM_TRACE(1,("--- _getResources() failed"));
465 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
466 goto exit;
467 }
469 /* Get the target resource. */
470 found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
472 /* Free the resource data. */
473 if (!Xen_ConsoleSettingData_freeResource(resource)) {
474 _SBLIM_TRACE(1,("--- _freeResource() failed"));
475 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
476 goto exit;
477 }
479 if (found) {
480 _SBLIM_TRACE(1,("--- Target instance already exists"));
481 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
482 goto exit;
483 }
485 /* Create a new resource with the new instance property values. */
486 int rc = Xen_ConsoleSettingData_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
487 if (rc != 1) {
488 if (rc == -1) {
489 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
490 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
491 } else {
492 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
493 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
494 }
495 goto exit;
496 }
498 /* Return the object path for the newly created instance. */
499 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
500 CMSetNameSpace(objectpath, namespace);
501 CMReturnObjectPath(results, objectpath);
502 CMReturnDone(results);
504 exit:
505 /* Free the list of system resources. */
506 if (!Xen_ConsoleSettingData_freeResources(resources)) {
507 _SBLIM_TRACE(1,("--- _freeResources() failed"));
508 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
509 }
511 _SBLIM_RETURNSTATUS(status);
512 }
514 // ----------------------------------------------------------------------------
515 // DeleteInstance()
516 // Delete or remove the specified instance from the system.
517 // ----------------------------------------------------------------------------
518 static CMPIStatus DeleteInstance(
519 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
520 const CMPIContext * context, /* [in] Additional context info, if any. */
521 const CMPIResult * results, /* [out] Results of this operation. */
522 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
523 {
524 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
525 _RESOURCES * resources; /* Handle to the list of system resources. */
526 _RESOURCE * resource; /* Handle to the system resource. */
527 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
528 int found = 0; /* Found the target instance? */
530 _SBLIM_ENTER("DeleteInstance");
531 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
532 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
533 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
534 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
536 if (!xen_utils_validate_session(&session)) {
537 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
538 goto exit;
539 }
541 /* Get a handle to the list of system resources. */
542 if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
543 _SBLIM_TRACE(1,("--- _getResources() failed"));
544 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
545 goto exit;
546 }
548 /* Get the target resource. */
549 found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
550 if (!found || (resource == NULL)) {
551 _SBLIM_TRACE(1,("--- Target instance not found"));
552 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
553 goto exit;
554 }
556 _SBLIM_TRACE(2,("--- instance found", found));
558 /* Delete the target resource. */
559 int rc = Xen_ConsoleSettingData_deleteResource(resources, resource);
561 /* Free the resource data. */
562 if (!Xen_ConsoleSettingData_freeResource(resource)) {
563 _SBLIM_TRACE(1,("--- _freeResource() failed"));
564 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
565 goto exit;
566 }
568 if (rc != 1) {
569 if (rc == -1) {
570 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
571 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
572 } else {
573 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
574 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
575 }
576 goto exit;
577 }
579 exit:
580 /* Free the list of system resources. */
581 if (!Xen_ConsoleSettingData_freeResources(resources)) {
582 _SBLIM_TRACE(1,("--- _freeResources() failed"));
583 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
584 }
586 _SBLIM_RETURNSTATUS(status);
587 }
590 // ----------------------------------------------------------------------------
591 // ExecQuery()
592 // Return a list of all the instances that satisfy the specified query filter.
593 // ----------------------------------------------------------------------------
594 static CMPIStatus ExecQuery(
595 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
596 const CMPIContext * context, /* [in] Additional context info, if any. */
597 const CMPIResult * results, /* [out] Results of this operation. */
598 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
599 const char * language, /* [in] Name of the query language. */
600 const char * query) /* [in] Text of the query written in the query language. */
601 {
602 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
603 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
605 _SBLIM_ENTER("ExecQuery");
606 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
607 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
608 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
609 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
610 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
611 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
613 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
614 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
616 CMReturnDone(results);
618 exit:
619 _SBLIM_RETURNSTATUS(status);
620 }
622 // ----------------------------------------------------------------------------
623 // Initialize()
624 // Perform any necessary initialization immediately after this provider is
625 // first loaded.
626 // ----------------------------------------------------------------------------
627 static void Initialize(
628 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
629 const CMPIContext * context) /* [in] Additional context info, if any. */
630 {
631 _SBLIM_ENTER("Initialize");
632 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
633 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
635 /* Initialized Xen session object. */
636 if (session == NULL)
637 xen_utils_xen_init(&session);
639 _SBLIM_RETURN();
640 }
642 // ============================================================================
643 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
644 // ============================================================================
645 CMInstanceMIStub( , Xen_ConsoleSettingData, _BROKER, Initialize(&mi, ctx));