os-cmpi-xen

view src/Xen_ComputerSystemCapabilities.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 0bf03964b16c
line source
1 // Copyright (C) 2006 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: A class used to represent the capabilities of a
20 // Xen_ComputerSystem, i.e. a virtual computer system.
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_ComputerSystemCapabilities_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_ComputerSystemCapabilities";
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 = NULL; /* 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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_setInstanceFromResource(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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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 = NULL; /* 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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_setInstanceFromResource(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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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 = NULL; /* 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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_getResourceForObjectPath(session, resources, &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_ComputerSystemCapabilities_setInstanceFromResource(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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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) /* [in] Contains list of modified properties. */
363 {
364 _SBLIM_ENTER("SetInstance");
366 /* Do not support modification of capabilities. */
367 CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
369 _SBLIM_RETURNSTATUS(status);
370 }
372 // ----------------------------------------------------------------------------
373 // CreateInstance()
374 // Create a new instance from the specified instance data.
375 // ----------------------------------------------------------------------------
376 static CMPIStatus CreateInstance(
377 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
378 const CMPIContext * context, /* [in] Additional context info, if any. */
379 const CMPIResult * results, /* [out] Results of this operation. */
380 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
381 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
382 {
383 _SBLIM_ENTER("CreateInstance");
385 /* Do not support explicit creation of capabilities. */
386 CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
388 _SBLIM_RETURNSTATUS(status);
389 }
391 // ----------------------------------------------------------------------------
392 // DeleteInstance()
393 // Delete or remove the specified instance from the system.
394 // ----------------------------------------------------------------------------
395 static CMPIStatus DeleteInstance(
396 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
397 const CMPIContext * context, /* [in] Additional context info, if any. */
398 const CMPIResult * results, /* [out] Results of this operation. */
399 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
400 {
401 _SBLIM_ENTER("DeleteInstance");
403 /* Do not support explicit deletion of capabilities. */
404 CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
406 _SBLIM_RETURNSTATUS(status);
407 }
410 // ----------------------------------------------------------------------------
411 // ExecQuery()
412 // Return a list of all the instances that satisfy the specified query filter.
413 // ----------------------------------------------------------------------------
414 static CMPIStatus ExecQuery(
415 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
416 const CMPIContext * context, /* [in] Additional context info, if any. */
417 const CMPIResult * results, /* [out] Results of this operation. */
418 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
419 const char * language, /* [in] Name of the query language. */
420 const char * query) /* [in] Text of the query written in the query language. */
421 {
422 _SBLIM_ENTER("ExecQuery");
424 /*
425 * TODO:
426 * Currently not supported.
427 */
428 CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
430 _SBLIM_RETURNSTATUS(status);
431 }
433 // ----------------------------------------------------------------------------
434 // Initialize()
435 // Perform any necessary initialization immediately after this provider is
436 // first loaded.
437 // ----------------------------------------------------------------------------
438 static void Initialize(
439 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
440 const CMPIContext * context) /* [in] Additional context info, if any. */
441 {
442 _SBLIM_ENTER("Initialize");
443 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
444 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
446 /* Initialized Xen session object. */
447 if (session == NULL)
448 xen_utils_xen_init(&session);
450 _SBLIM_RETURN();
451 }
453 // ============================================================================
454 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
455 // ============================================================================
456 CMInstanceMIStub( , Xen_ComputerSystemCapabilities, _BROKER, Initialize(&mi, ctx));