os-cmpi-xen

view src/Xen_ComputerSystemSettingData_Resource.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 fa1ca0490794
children 28e8c94e92de
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 <stdlib.h>
23 #include <string.h>
24 #include <assert.h>
26 #include <xen_common.h>
27 #include <xen_vm.h>
29 #include "Xen_ComputerSystemSettingData_Resource.h"
31 /* Include the required CMPI data types, function headers, and macros. */
32 #include "cmpidt.h"
33 #include "cmpift.h"
34 #include "cmpimacs.h"
36 #include "xen_utils.h"
37 #include "provider_common.h"
40 static int get_platform_bool_val(_RESOURCE *resource, char *key)
41 {
42 int i;
44 xen_string_string_map *map = resource->platform;
45 for (i = 0; i < map->size; i++)
46 if (strcmp(map->contents[i].key, key) == 0)
47 if (strcmp(map->contents[i].val, "1") == 0)
48 return 1;
50 return 0;
51 }
53 static char *get_platform_string_val(_RESOURCE *resource, char *key)
54 {
55 int i;
57 xen_string_string_map *map = resource->platform;
58 for (i = 0; i < map->size; i++)
59 if (strcmp(map->contents[i].key, key) == 0)
60 return map->contents[i].val;
62 return NULL;
63 }
66 // ----------------------------------------------------------------------------
68 /* Get a handle to the list of all system resources for this class. */
69 int Xen_ComputerSystemSettingData_getResources(xen_utils_session *session,
70 _RESOURCES ** resources)
71 {
72 return xen_utils_get_domain_resources(session, resources);
73 }
75 // ----------------------------------------------------------------------------
77 /* Free/deallocate/cleanup the resources list after use. */
78 int Xen_ComputerSystemSettingData_freeResources(_RESOURCES * resources)
79 {
80 return xen_utils_free_domain_resources(resources);
81 }
83 // ----------------------------------------------------------------------------
85 /* Iterator to get the next resource from the resources list. */
86 int Xen_ComputerSystemSettingData_getNextResource(xen_utils_session *session,
87 _RESOURCES * resources,
88 _RESOURCE ** resource)
89 {
90 return xen_utils_get_next_domain_resource(session, resources, resource);
91 }
93 // ----------------------------------------------------------------------------
95 /* Get the specific resource that matches the CMPI object path. */
96 int Xen_ComputerSystemSettingData_getResourceForObjectPath(xen_utils_session *session,
97 _RESOURCES * resources,
98 _RESOURCE ** resource,
99 const CMPIObjectPath * objectpath)
100 {
101 char *instId;
102 char name[MAX_SYSTEM_NAME_LEN];
103 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
105 /* Check input params are valid. */
106 if (resources == NULL) return 0;
107 if (CMIsNullObject(objectpath)) return 0;
109 /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
110 CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
111 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
113 /* Extract the id string from the CMPIString. */
114 instId = CMGetCharPtr(iddata.value.string);
115 if ((instId== NULL) || (*instId == '\0')) return 0;
117 /* Retrieve domain name from InstanceID. */
118 if (!_CMPIStrncpySystemNameFromID(name, instId, MAX_SYSTEM_NAME_LEN))
119 return 0;
121 /* Get all the resource data for the target resource. */
122 xen_vm_set *vms;
123 if (!xen_vm_get_by_name_label(session->xen, &vms, name)) {
124 /* Error is in session object! */
125 *resource = NULL;
126 return 0;
127 }
129 assert(vms->size == 1);
130 if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) {
131 /* Error description in session object! */
132 xen_vm_set_free(vms);
133 return 0;
134 }
136 xen_vm_set_free(vms);
138 return 1;
139 }
141 // ----------------------------------------------------------------------------
143 /* Free/deallocate/cleanup the resource after use. */
144 int Xen_ComputerSystemSettingData_freeResource(_RESOURCE * resource)
145 {
146 return xen_utils_free_domain_resource(resource);
147 }
150 // ----------------------------------------------------------------------------
152 /* Set the property values of a CMPI instance from a specific resource. */
153 int Xen_ComputerSystemSettingData_setInstanceFromResource(_RESOURCE * resource,
154 const CMPIInstance * instance,
155 const CMPIBroker * broker)
156 {
157 char inst_id[1024];
158 int prop_bool_val;
159 char *prop_string_val;
160 char *hvm_boot_order;
161 if (resource == NULL) return 0;
162 if (CMIsNullObject(instance)) return 0;
164 /* Set the CMPIInstance properties from the resource data. */
165 snprintf(inst_id, 1024, "Xen:%s", resource->name_label);
166 CMSetProperty(instance, "InstanceID",(CMPIValue *)inst_id, CMPI_chars);
167 // There must be an easier way of figuring out pv/hvm, but, until we figure that out, we will keep this - Raj
168 if ((hvm_boot_order = xen_utils_get_value_from_map(resource->hvm_boot_params, "order"))) {
169 /* HVM settings */
170 CMSetProperty(instance, "VirtualSystemType", (CMPIValue *)"hvm-3.0-unknown", CMPI_chars);
171 CMSetProperty(instance, "BootOrder", (CMPIValue *)hvm_boot_order, CMPI_chars);
172 prop_bool_val = get_platform_bool_val(resource, "stdvga");
173 CMSetProperty(instance, "stdvga", (CMPIValue *)&prop_bool_val, CMPI_boolean);
175 prop_bool_val = get_platform_bool_val(resource, "apic");
176 CMSetProperty(instance, "apic", (CMPIValue *)&prop_bool_val, CMPI_boolean);
178 prop_bool_val = get_platform_bool_val(resource, "acpi");
179 CMSetProperty(instance, "acpi", (CMPIValue *)&prop_bool_val, CMPI_boolean);
181 prop_bool_val = get_platform_bool_val(resource, "pae");
182 CMSetProperty(instance, "pae", (CMPIValue *)&prop_bool_val, CMPI_boolean);
184 prop_bool_val = get_platform_bool_val(resource, "usb");
185 CMSetProperty(instance, "usb", (CMPIValue *)&prop_bool_val, CMPI_boolean);
187 prop_string_val = get_platform_string_val(resource, "usbdevice");
188 if (prop_string_val != NULL)
189 CMSetProperty(instance, "usbdevice", (CMPIValue *)prop_string_val, CMPI_chars);
190 }
191 else {
192 /* PV settings */
193 CMSetProperty(instance, "VirtualSystemType", (CMPIValue *)"xen-3.0-unknown", CMPI_chars);
195 if (resource->pv_kernel && (resource->pv_kernel[0] != '\0'))
196 CMSetProperty(instance, "Kernel", (CMPIValue *)resource->pv_kernel, CMPI_chars);
197 if (resource->pv_ramdisk && (resource->pv_ramdisk[0] != '\0'))
198 CMSetProperty(instance, "RAMDisk", (CMPIValue *)resource->pv_ramdisk, CMPI_chars);
199 if (resource->pv_args && (resource->pv_args[0] != '\0'))
200 CMSetProperty(instance, "KernelOptions" , (CMPIValue *)resource->pv_args, CMPI_chars);
201 if (resource->pv_bootloader && (resource->pv_bootloader[0] != '\0'))
202 CMSetProperty(instance, "Bootloader", (CMPIValue *)resource->pv_bootloader, CMPI_chars);
203 if (resource->pv_bootloader_args && (resource->pv_bootloader_args[0] != '\0'))
204 CMSetProperty(instance, "BootloaderOptions", (CMPIValue *)resource->pv_bootloader_args, CMPI_chars);
205 }
207 /* Common settings */
208 CMSetProperty(instance, "ElementName",(CMPIValue *)resource->name_label, CMPI_chars);
209 CMSetProperty(instance, "VirtualSystemIdentifier",(CMPIValue *)resource->name_label, CMPI_chars);
211 if (resource->uuid && (resource->uuid[0] != '\0'))
212 CMSetProperty(instance, "UUID", (CMPIValue *)resource->uuid, CMPI_chars);
214 prop_bool_val = get_platform_bool_val(resource, "localtime");
215 CMSetProperty(instance, "localtime", (CMPIValue *)&prop_bool_val, CMPI_boolean);
217 CMSetProperty(instance, "OnPoweroff", (CMPIValue *)&(resource->actions_after_shutdown), CMPI_uint16);
218 CMSetProperty(instance, "OnReboot", (CMPIValue *)&(resource->actions_after_reboot), CMPI_uint16);
219 CMSetProperty(instance, "OnCrash", (CMPIValue *)&(resource->actions_after_crash), CMPI_uint16);
221 return 1;
222 }
224 // ----------------------------------------------------------------------------
226 /* Delete the specified resource from the system. */
227 int Xen_ComputerSystemSettingData_deleteResource(_RESOURCES * resources,
228 _RESOURCE * resource)
229 {
230 /* Unsupported. */
231 return -1;
232 }
234 // ----------------------------------------------------------------------------
236 /* Modify the specified resource using the property values of a CMPI instance. */
237 int Xen_ComputerSystemSettingData_setResourceFromInstance(_RESOURCE * resource,
238 const CMPIInstance * instance,
239 const CMPIBroker * broker)
240 {
241 /* Unsupported. */
242 return -1;
243 }
245 // ----------------------------------------------------------------------------
247 /* Create a new resource using the property values of a CMPI instance. */
248 int Xen_ComputerSystemSettingData_createResourceFromInstance(_RESOURCES * resources,
249 _RESOURCE ** resource,
250 const CMPIInstance * instance,
251 const CMPIBroker * broker)
252 {
253 /* Unsupported. */
254 return -1;
255 }