os-cmpi-xen

view src/Xen_VirtualSystemManagementCapabilities.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 64e363d418df
children ce72210a88c6
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: A class used to represent the capabilities of
20 // Xen_VirtualSystemManagementService, e.g. which
21 // methods are supported.
22 // ============================================================================
24 /* Common declarations for each CMPI "Cimpler" instance provider */
25 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
26 #include "cmpidt.h"
27 #include "cmpimacs.h"
28 #include "cmpilr.h"
31 static const CMPIInstanceMI* mi;
34 #define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
35 #define _CLASS (((CMPIResource*)(mi->hdl))->cn)
36 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
38 #include <stdlib.h>
40 #include <xen_common.h>
41 #include <xen_host.h>
43 #include "cmpitrace.h"
44 #include "xen_utils.h"
47 /* C struct to store the data for all resources. */
48 typedef struct {
49 int finished;
50 } _RESOURCES;
53 /* Xen session object. Initialize when the provider is loaded, close when
54 * provider unloaded. */
55 static xen_utils_session *session = NULL;
58 static int load()
59 {
60 /* Initialized Xen session object. */
61 if (!session)
62 xen_utils_xen_init(&session);
64 return 1;
65 }
68 static int unload(CMPIBoolean terminating)
69 {
70 (void) terminating;
72 if (session) {
73 xen_utils_xen_close(session);
74 session = NULL;
75 }
77 return 1;
78 }
81 static int beginEnum(void **res_list, CMPIStatus *status)
82 {
83 *res_list = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
84 if (*res_list == NULL)
85 return 0;
87 return 1;
88 }
91 static void endEnum(void *res_list)
92 {
93 free(res_list);
94 }
97 static int getNext(void *res_list, void **res, CMPIStatus *status)
98 {
99 xen_host host = NULL;
100 xen_host_record *host_rec;
102 if (res_list == NULL || ((_RESOURCES *)res_list)->finished)
103 return 0;
105 ((_RESOURCES *)res_list)->finished = 1;
107 if (!xen_utils_validate_session(&session)) {
108 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
109 ("--- Unable to establish connection with Xend"));
110 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
111 "Unable to establish connection with Xend");
112 return 0;
113 }
115 xen_session_get_this_host(session->xen, &host, session->xen);
116 xen_host_get_record(session->xen, &host_rec, host);
117 if (!session->xen->ok) {
118 /* Error description in session object. */
119 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
120 ("--- failed to retrieve host record from Xend:"));
121 _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
122 xen_utils_trace_error(session->xen));
123 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
124 "Failed to retrieve host record from Xend");
125 xen_host_free(host);
126 return 0;
127 }
129 *res = (void *)host_rec;
130 return 1;
131 }
134 static int get(void *res_list, void **res, CMPIStatus *status)
135 {
136 xen_host host = NULL;
137 xen_host_record *host_rec;
139 (void) res_list;
141 if (!xen_utils_validate_session(&session)) {
142 _SBLIM_TRACE(1, ("--- Unable to establish connection with Xend"));
143 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
144 "Unable to establish connection with Xend");
145 return 0;
146 }
148 xen_session_get_this_host(session->xen, &host, session->xen);
149 xen_host_get_record(session->xen, &host_rec, host);
150 if (!session->xen->ok) {
151 /* Error description in session object. */
152 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
153 ("--- failed to retrieve host record from Xend:"));
154 _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
155 xen_utils_trace_error(session->xen));
156 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
157 "Failed to retrieve host record from Xend");
158 xen_host_free(host);
159 return 0;
160 }
162 *res = (void *)host_rec;
163 return 1;
164 }
167 static void release(void *res)
168 {
169 xen_host_record_free(res);
170 }
173 static int add(void **res_list, void *res, CMPIStatus *status)
174 {
175 return -1; /* unsupported */
176 }
179 static int delete(void **res_list, void *res, CMPIStatus *status)
180 {
181 return -1; /* unsupported */
182 }
185 static int modify(void **res_list, void *res, CMPIStatus *status)
186 {
187 return -1; /* unsupported */
188 }
191 /* Set CMPIInstance properties from the resource data. */
192 static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status)
193 {
194 xen_host_record *host_rec;
195 int supported;
197 if (res == NULL)
198 return 0;
200 if (CMIsNullObject(inst))
201 return 0;
203 host_rec = (xen_host_record *)res;
205 /* Set the CMPIInstance properties from the resource data. */
206 if (host_rec->name_label) {
207 CMSetProperty(inst, "InstanceID",
208 (CMPIValue *)host_rec->name_label, CMPI_chars);
209 CMSetProperty(inst, "ElementName",
210 (CMPIValue *)host_rec->name_label, CMPI_chars);
211 }
212 else
213 {
214 CMSetProperty(inst, "InstanceID",
215 (CMPIValue *)"Xen Hypervisor", CMPI_chars);
216 CMSetProperty(inst, "ElementName",
217 (CMPIValue *)"Xen Hypervisor", CMPI_chars);
218 }
220 supported = 0;
221 CMSetProperty(inst, "ElementNameEditSupported",
222 (CMPIValue *)&supported, CMPI_boolean);
223 /*
224 * TODO:
225 * Do we want to support enabling and disabling the management
226 * service? I.e. starting / stopping xend.
227 */
228 CMPIArray *statesSupported = CMNewArray(_BROKER, 1, CMPI_uint16, NULL);
229 int state = 2; /* 'Enabled' */
230 CMSetArrayElementAt(statesSupported, 0, (CMPIValue *)&state, CMPI_uint16);
231 CMSetProperty(inst, "RequestedStatesSupported",
232 (CMPIValue *)&statesSupported, CMPI_uint16A);
234 /*
235 * Known VirtualSystemTypes Xen supports are:
236 *
237 * xen-3.0-x86_32, xen-3.0-x86_32p, xen-3.0-x86_64,
238 * hvm-3.0-x86_32, hvm-3.0-x86_32p, hvm-3.0-x86_64
239 *
240 */
241 xen_string_set *caps = host_rec->capabilities;
242 if (caps && caps->size > 0) {
243 CMPIValue value;
244 int ndx;
246 value.array = CMNewArray(_BROKER, caps->size, CMPI_string, NULL);
247 for (ndx = 0; ndx < caps->size; ndx++)
248 {
249 CMPIString* tmp = CMNewString(_BROKER, (caps->contents[ndx]), NULL);
250 CMSetArrayElementAt(value.array, ndx, &tmp, CMPI_string);
251 }
253 CMSetProperty(inst, "VirtualSystemTypesSupported",&value, CMPI_stringA);
254 }
256 /*
257 * TODO:
258 * We only support DefineSystem and DestroySystem at the
259 * moment. Need to add others here when they are implemented in
260 * Xen_VirtualSystemManagementService.
261 * Also need to add the asynchronous methods supported once that is
262 * implemented.
263 */
264 CMPIArray *syncMethodsSupported = CMNewArray(_BROKER, 3, CMPI_uint16, NULL);
265 supported = 2; /* 'DefineSystemSupported' */
266 CMSetArrayElementAt(syncMethodsSupported, 0,
267 (CMPIValue *)&supported, CMPI_uint16);
268 supported = 3; /* 'DestroySystemSupported */
269 CMSetArrayElementAt(syncMethodsSupported, 1,
270 (CMPIValue *)&supported, CMPI_uint16);
271 supported = 10; /* 'AddResourceSupported */
272 CMSetArrayElementAt(syncMethodsSupported, 2,
273 (CMPIValue *)&supported, CMPI_uint16);
274 CMSetProperty(inst, "SynchronousMethodsSupported",
275 (CMPIValue *)&syncMethodsSupported, CMPI_uint16A);
277 return 1;
278 }
281 /* Set resource data from the CMPIInstance properties. */
282 static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
283 {
284 xen_host host = NULL;
285 xen_host_record *host_rec;
287 (void) inst;
289 /*
290 * Since we only have one VirtualSystemManagementService on this host
291 * we'll just create the resource as usual.
292 */
293 if (!xen_utils_validate_session(&session)) {
294 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
295 ("--- Unable to establish connection with Xend"));
296 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
297 "Unable to establish connection with Xend");
298 return 0;
299 }
301 xen_session_get_this_host(session->xen, &host, session->xen);
302 xen_host_get_record(session->xen, &host_rec, host);
303 if (!session->xen->ok) {
304 /* Error description in session object. */
305 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
306 ("--- failed to retrieve host record from Xend:"));
307 _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
308 xen_utils_trace_error(session->xen));
309 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
310 "Failed to retrieve host record from Xend");
311 xen_host_free(host);
312 return 0;
313 }
315 *res = (void *)host_rec;
316 return 1;
317 }
320 /* Setup the CMPILR function tables and CMPILR instance provider entry point.*/
321 /* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */
322 CMPILRInstanceMIStub(Xen_VirtualSystemManagementCapabilities, Xen_VirtualSystemManagementCapabilities, mi)