os-cmpi-xen

view src/Xen_RegisteredProfiles.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 cc7579061be2
children
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:
20 // ============================================================================
22 #include <string.h>
24 #include "provider_common.h"
26 /* Include the required CMPI data types, function headers, and macros */
27 #include "cmpidt.h"
28 #include "cmpift.h"
29 #include "cmpimacs.h"
31 // ----------------------------------------------------------------------------
32 // COMMON GLOBAL VARIABLES
33 // ----------------------------------------------------------------------------
35 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
36 static const CMPIBroker *_BROKER;
38 /* Include utility functions */
39 #include "cmpiutil.h"
41 /* Include _SBLIM_TRACE() logging support */
42 #include "cmpitrace.h"
45 // ============================================================================
46 // CMPI INSTANCE PROVIDER FUNCTION TABLE
47 // ============================================================================
49 // ----------------------------------------------------------------------------
50 // Info for the class supported by the instance provider
51 // ----------------------------------------------------------------------------
53 /* Name of the class implemented by this instance provider. */
54 /*** CUSTOMIZE FOR EACH PROVIDER ***/
55 static char * SVP_CLASSNAME = "Xen_RegisteredSVProfile";
56 static char * VSP_CLASSNAME = "Xen_RegisteredVSProfile";
57 static char * _NAMESPACE = "Interop";
59 /* NULL terminated list of key properties of this class. */
60 /*** CUSTOMIZE FOR EACH PROVIDER ***/
61 const static char * _KEYNAMES[] = {"InstanceID", NULL};
63 /* Additional static class data */
64 const static char * SVP_NAME = "System Virtualization Profile";
65 const static char * SVP_INST_ID = "Xen:SystemVirtualizationProfile";
66 const static char * SVP_VERSION = "0.7.3";
67 const static char * VSP_NAME = "Virtual System Profile";
68 const static char * VSP_INST_ID = "Xen:VirtualSystemProfile";
69 const static char * VSP_VERSION = "0.7.7";
72 static int generateObjectPath(const char *className,
73 CMPIObjectPath **op,
74 CMPIStatus *status)
75 {
76 const char *instId;
78 if (strcmp(className, SVP_CLASSNAME) == 0)
79 instId = SVP_INST_ID;
80 else if (strcmp(className, VSP_CLASSNAME) == 0)
81 instId = VSP_INST_ID;
82 else {
83 _SBLIM_TRACE(1,("--- Invalid class - %s", className));
84 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR, "Invalid class");
85 return 1;
86 }
88 *op = CMNewObjectPath(_BROKER, _NAMESPACE, className, status);
89 if ((status->rc != CMPI_RC_OK) || CMIsNullObject(*op)) {
90 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status->msg)));
91 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR, "Cannot create new CMPIOjbectPath");
92 return 1;
93 }
95 CMAddKey(*op, "InstanceID", (CMPIValue *)instId, CMPI_chars);
96 return 0;
97 }
99 static int generateInstance(const char *className,
100 CMPIInstance **inst,
101 const char ** properties,
102 CMPIStatus *status)
103 {
104 const char *instId;
105 const char *profileName;
106 const char *profileVersion;
108 if (strcmp(className, SVP_CLASSNAME) == 0) {
109 instId = SVP_INST_ID;
110 profileName = SVP_NAME;
111 profileVersion = SVP_VERSION;
112 }
113 else if (strcmp(className, VSP_CLASSNAME) == 0) {
114 instId = VSP_INST_ID;
115 profileName = VSP_NAME;
116 profileVersion = VSP_VERSION;
117 }
118 else {
119 _SBLIM_TRACE(1,("--- Invalid class - %s", className));
120 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR, "Invalid class");
121 return 1;
122 }
124 *inst = _CMNewInstance(_BROKER, _NAMESPACE, (char *)className, status);
125 if ((status->rc != CMPI_RC_OK) || CMIsNullObject(*inst)) {
126 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status->msg)));
127 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
128 return 1;
129 }
131 /* Setup a filter to only return the desired properties. */
132 CMSetPropertyFilter(*inst, properties, _KEYNAMES);
134 CMSetProperty(*inst, "InstanceID",(CMPIValue *)instId, CMPI_chars);
135 CMSetProperty(*inst, "RegisteredName",(CMPIValue *)profileName, CMPI_chars);
137 int registeredOrg = 2; // "DMTF"
138 CMSetProperty(*inst, "RegisteredOrganization",(CMPIValue *)&registeredOrg, CMPI_uint16);
140 CMSetProperty(*inst, "RegisteredVersion",(CMPIValue *)profileVersion, CMPI_chars);
141 return 0;
142 }
145 // ----------------------------------------------------------------------------
146 // Cleanup()
147 // Perform any necessary cleanup immediately before this provider is unloaded.
148 // ----------------------------------------------------------------------------
149 static CMPIStatus Cleanup(
150 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
151 const CMPIContext * context, /* [in] Additional context info, if any. */
152 CMPIBoolean terminating) /* [in] True if MB is terminating */
153 {
154 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
156 _SBLIM_ENTER("Cleanup");
157 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
158 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
160 /* Nothing needs to be done for cleanup. */
161 _SBLIM_RETURNSTATUS(status);
162 }
164 // ----------------------------------------------------------------------------
165 // EnumInstanceNames()
166 // Return a list of all the instances names (return their object paths only).
167 // ----------------------------------------------------------------------------
168 static CMPIStatus EnumInstanceNames(
169 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
170 const CMPIContext * context, /* [in] Additional context info, if any. */
171 const CMPIResult * results, /* [out] Results of this operation. */
172 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
173 {
174 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
175 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
176 char * className = CMGetCharPtr(CMGetClassName(reference, NULL));
178 _SBLIM_ENTER("EnumInstanceNames");
179 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
180 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
181 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
182 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
183 _SBLIM_TRACE(2, ("--- class name=\"%s\"", className));
185 /* Should only exist in Interop namespace */
186 if (strcmp(namespace, "Interop") != 0) {
187 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for System Virtualization Profile", namespace));
188 goto exit;
189 }
191 CMPIObjectPath *op = NULL;
192 if (generateObjectPath(className, &op, &status))
193 goto exit;
195 _SBLIM_TRACE(2, ("--- returning object path=\"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
197 CMReturnObjectPath(results, op);
199 exit:
200 CMReturnDone(results);
201 _SBLIM_RETURNSTATUS(status);
202 }
204 // ----------------------------------------------------------------------------
205 // EnumInstances()
206 // Return a list of all the instances (return all the instance data).
207 // ----------------------------------------------------------------------------
208 static CMPIStatus EnumInstances(
209 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
210 const CMPIContext * context, /* [in] Additional context info, if any. */
211 const CMPIResult * results, /* [out] Results of this operation. */
212 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
213 const char ** properties) /* [in] List of desired properties (NULL=all). */
214 {
215 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
216 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
217 char * className = CMGetCharPtr(CMGetClassName(reference, NULL));
219 _SBLIM_ENTER("EnumInstances");
220 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
221 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
222 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
223 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
224 _SBLIM_TRACE(2, ("--- class name=\"%s\"", className));
226 /* Should only exist in Interop namespace */
227 if (strcmp(namespace, "Interop") != 0) {
228 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for System Virtualization Profile", namespace));
229 goto exit;
230 }
232 CMPIInstance *instance = NULL;
233 if (generateInstance(className, &instance, properties, &status))
234 goto exit;
236 CMReturnInstance(results, instance);
238 exit:
239 CMReturnDone(results);
240 _SBLIM_RETURNSTATUS(status);
241 }
243 // ----------------------------------------------------------------------------
244 // GetInstance()
245 // Return the instance data for the specified instance only.
246 // ----------------------------------------------------------------------------
247 static CMPIStatus GetInstance(
248 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
249 const CMPIContext * context, /* [in] Additional context info, if any. */
250 const CMPIResult * results, /* [out] Results of this operation. */
251 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
252 const char ** properties) /* [in] List of desired properties (NULL=all). */
253 {
254 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
255 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
256 char * className = CMGetCharPtr(CMGetClassName(reference, NULL));
258 _SBLIM_ENTER("GetInstance");
259 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
260 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
261 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
262 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
263 _SBLIM_TRACE(2, ("--- class name=\"%s\"", className));
265 /* Should only exist in Interop namespace */
266 if (strcmp(namespace, "Interop") != 0) {
267 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for System Virtualization Profile", namespace));
268 goto exit;
269 }
271 /* Verify InstanceID is what we expect. */
272 CMPIData data = CMGetKey(reference, "InstanceID", &status);
273 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) {
274 _SBLIM_TRACE(1,("--- Unable to extract InstanceID key from object path"));
275 goto exit;
276 }
278 char *instId = CMGetCharPtr(data.value.string);
279 if (instId == NULL ||
280 (strcmp(instId, SVP_INST_ID) && strcmp(instId, VSP_INST_ID))) {
281 _SBLIM_TRACE(1,("--- \"%s\" is not a valid InstanceID value", (instId ? instId : "NULL")));
282 goto exit;
283 }
285 CMPIInstance *instance = NULL;
286 if (generateInstance(className, &instance, properties, &status))
287 goto exit;
289 CMReturnInstance(results, instance);
291 _SBLIM_TRACE(2,("--- instance found"));
293 exit:
294 CMReturnDone(results);
295 _SBLIM_RETURNSTATUS(status);
296 }
298 // ----------------------------------------------------------------------------
299 // SetInstance()
300 // Save modified instance data for the specified instance.
301 // ----------------------------------------------------------------------------
302 static CMPIStatus SetInstance(
303 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
304 const CMPIContext * context, /* [in] Additional context info, if any. */
305 const CMPIResult * results, /* [out] Results of this operation. */
306 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
307 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
308 const char **properties)
309 {
310 CMPIStatus status; /* Return status of CIM operations. */
312 CMSetStatus(&status, CMPI_RC_ERR_NOT_SUPPORTED);
313 CMReturnDone(results);
315 return (status);
316 }
318 // ----------------------------------------------------------------------------
319 // CreateInstance()
320 // Create a new instance from the specified instance data.
321 // ----------------------------------------------------------------------------
322 static CMPIStatus CreateInstance(
323 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
324 const CMPIContext * context, /* [in] Additional context info, if any. */
325 const CMPIResult * results, /* [out] Results of this operation. */
326 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
327 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
328 {
329 CMPIStatus status; /* Return status of CIM operations. */
331 CMSetStatus(&status, CMPI_RC_ERR_NOT_SUPPORTED);
332 CMReturnDone(results);
334 return (status);
335 }
337 // ----------------------------------------------------------------------------
338 // DeleteInstance()
339 // Delete or remove the specified instance from the system.
340 // ----------------------------------------------------------------------------
341 static CMPIStatus DeleteInstance(
342 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
343 const CMPIContext * context, /* [in] Additional context info, if any. */
344 const CMPIResult * results, /* [out] Results of this operation. */
345 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
346 {
347 CMPIStatus status; /* Return status of CIM operations. */
349 CMSetStatus(&status, CMPI_RC_ERR_NOT_SUPPORTED);
350 CMReturnDone(results);
352 return (status);
353 }
356 // ----------------------------------------------------------------------------
357 // ExecQuery()
358 // Return a list of all the instances that satisfy the specified query filter.
359 // ----------------------------------------------------------------------------
360 static CMPIStatus ExecQuery(
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 and classname. */
365 const char * language, /* [in] Name of the query language. */
366 const char * query) /* [in] Text of the query written in the query language. */
367 {
368 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
369 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
371 _SBLIM_ENTER("ExecQuery");
372 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
373 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
374 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
375 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
376 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
377 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
379 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
380 CMSetStatus(&status, CMPI_RC_ERR_NOT_SUPPORTED);
382 CMReturnDone(results);
384 exit:
385 _SBLIM_RETURNSTATUS(status);
386 }
388 // ----------------------------------------------------------------------------
389 // Initialize()
390 // Perform any necessary initialization immediately after this provider is
391 // first loaded.
392 // ----------------------------------------------------------------------------
393 static void Initialize(
394 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
395 const CMPIContext * context) /* [in] Additional context info, if any. */
396 {
397 CMPIString *temp;
399 _SBLIM_ENTER("Initialize");
400 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
401 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
403 /* Nothing needs to be done to initialize this provider */
404 _SBLIM_RETURN();
405 }
407 // ============================================================================
408 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
409 // ============================================================================
410 CMInstanceMIStub( , Xen_RegisteredProfiles, _BROKER, Initialize(&mi, ctx));