os-cmpi-xen

view src/Xen_ComputerSystemSettingData_Resource.c @ 90:585665e1a296

Fixed regression in Xen_ComputerSystemSettingData.
Bootloader, BootloaderOptions, Kernel, RAMDisk, and
KernelOptions were not being displayed properly.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Mar 02 12:00:37 2007 -0700 (2007-03-02)
parents 9a96ebba2b60
children 44127f60b2da
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"
39 // ----------------------------------------------------------------------------
41 /* Get a handle to the list of all system resources for this class. */
42 int Xen_ComputerSystemSettingData_getResources(xen_utils_session *session,
43 _RESOURCES ** resources)
44 {
45 return xen_utils_get_domain_resources(session, resources);
46 }
48 // ----------------------------------------------------------------------------
50 /* Free/deallocate/cleanup the resources list after use. */
51 int Xen_ComputerSystemSettingData_freeResources(_RESOURCES * resources)
52 {
53 return xen_utils_free_domain_resources(resources);
54 }
56 // ----------------------------------------------------------------------------
58 /* Iterator to get the next resource from the resources list. */
59 int Xen_ComputerSystemSettingData_getNextResource(xen_utils_session *session,
60 _RESOURCES * resources,
61 _RESOURCE ** resource)
62 {
63 return xen_utils_get_next_domain_resource(session, resources, resource);
64 }
66 // ----------------------------------------------------------------------------
68 /* Get the specific resource that matches the CMPI object path. */
69 int Xen_ComputerSystemSettingData_getResourceForObjectPath(xen_utils_session *session,
70 _RESOURCES * resources,
71 _RESOURCE ** resource,
72 const CMPIObjectPath * objectpath)
73 {
74 char *instId;
75 char name[MAX_SYSTEM_NAME_LEN];
76 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
78 /* Check input params are valid. */
79 if (resources == NULL) return 0;
80 if (CMIsNullObject(objectpath)) return 0;
82 /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
83 CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
84 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
86 /* Extract the id string from the CMPIString. */
87 instId = CMGetCharPtr(iddata.value.string);
88 if ((instId== NULL) || (*instId == '\0')) return 0;
90 /* Retrieve domain name from InstanceID. */
91 if (!_CMPIStrncpySystemNameFromID(name, instId, MAX_SYSTEM_NAME_LEN))
92 return 0;
94 /* Get all the resource data for the target resource. */
95 xen_vm_set *vms;
96 if (!xen_vm_get_by_name_label(session->xen, &vms, name)) {
97 /* Error is in session object! */
98 *resource = NULL;
99 return 0;
100 }
102 assert(vms->size == 1);
103 if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) {
104 /* Error description in session object! */
105 xen_vm_set_free(vms);
106 return 0;
107 }
109 xen_vm_set_free(vms);
111 return 1;
112 }
114 // ----------------------------------------------------------------------------
116 /* Free/deallocate/cleanup the resource after use. */
117 int Xen_ComputerSystemSettingData_freeResource(_RESOURCE * resource)
118 {
119 return xen_utils_free_domain_resource(resource);
120 }
122 // ----------------------------------------------------------------------------
124 /* Set the property values of a CMPI instance from a specific resource. */
125 int Xen_ComputerSystemSettingData_setInstanceFromResource(_RESOURCE * resource,
126 const CMPIInstance * instance,
127 const CMPIBroker * broker)
128 {
129 char inst_id[1024];
131 if (resource == NULL) return 0;
132 if (CMIsNullObject(instance)) return 0;
134 /* Set the CMPIInstance properties from the resource data. */
135 snprintf(inst_id, 1024, "Xen:%s", resource->name_label);
136 CMSetProperty(instance, "InstanceID",(CMPIValue *)inst_id, CMPI_chars);
138 if (resource->hvm_boot && (resource->hvm_boot[0] != '\0')) {
139 /* HVM settings */
140 CMSetProperty(instance, "VirtualSystemType", (CMPIValue *)"Xen HVM", CMPI_chars);
141 CMSetProperty(instance, "BootOrder", (CMPIValue *)resource->hvm_boot, CMPI_chars);
142 CMSetProperty(instance, "stdvga", (CMPIValue *)&(resource->platform_std_vga), CMPI_boolean);
143 }
144 else {
145 /* PV settings */
146 CMSetProperty(instance, "VirtualSystemType", (CMPIValue *)"Xen Paravirtual", CMPI_chars);
148 if (resource->pv_kernel && (resource->pv_kernel[0] != '\0'))
149 CMSetProperty(instance, "Kernel", (CMPIValue *)resource->pv_kernel, CMPI_chars);
150 if (resource->pv_ramdisk && (resource->pv_ramdisk[0] != '\0'))
151 CMSetProperty(instance, "RAMDisk", (CMPIValue *)resource->pv_ramdisk, CMPI_chars);
152 if (resource->pv_args && (resource->pv_args[0] != '\0'))
153 CMSetProperty(instance, "KernelOptions" , (CMPIValue *)resource->pv_args, CMPI_chars);
154 if (resource->pv_bootloader && (resource->pv_bootloader[0] != '\0'))
155 CMSetProperty(instance, "Bootloader", (CMPIValue *)resource->pv_bootloader, CMPI_chars);
156 if (resource->pv_bootloader_args && (resource->pv_bootloader_args[0] != '\0'))
157 CMSetProperty(instance, "BootloaderOptions", (CMPIValue *)resource->pv_bootloader_args, CMPI_chars);
158 }
160 /* Common settings */
161 CMSetProperty(instance, "ElementName",(CMPIValue *)resource->name_label, CMPI_chars);
162 CMSetProperty(instance, "VirtualSystemIdentifier",(CMPIValue *)resource->name_label, CMPI_chars);
164 if (resource->uuid && (resource->uuid[0] != '\0'))
165 CMSetProperty(instance, "UUID", (CMPIValue *)resource->uuid, CMPI_chars);
167 CMSetProperty(instance, "localtime", (CMPIValue *)&(resource->platform_localtime), CMPI_boolean);
169 CMSetProperty(instance, "OnPoweroff", (CMPIValue *)&(resource->actions_after_shutdown), CMPI_uint16);
170 CMSetProperty(instance, "OnReboot", (CMPIValue *)&(resource->actions_after_reboot), CMPI_uint16);
171 CMSetProperty(instance, "OnCrash", (CMPIValue *)&(resource->actions_after_crash), CMPI_uint16);
173 return 1;
174 }
176 // ----------------------------------------------------------------------------
178 /* Delete the specified resource from the system. */
179 int Xen_ComputerSystemSettingData_deleteResource(_RESOURCES * resources,
180 _RESOURCE * resource)
181 {
182 /* Unsupported. */
183 return -1;
184 }
186 // ----------------------------------------------------------------------------
188 /* Modify the specified resource using the property values of a CMPI instance. */
189 int Xen_ComputerSystemSettingData_setResourceFromInstance(_RESOURCE * resource,
190 const CMPIInstance * instance,
191 const CMPIBroker * broker)
192 {
193 /* Unsupported. */
194 return -1;
195 }
197 // ----------------------------------------------------------------------------
199 /* Create a new resource using the property values of a CMPI instance. */
200 int Xen_ComputerSystemSettingData_createResourceFromInstance(_RESOURCES * resources,
201 _RESOURCE ** resource,
202 const CMPIInstance * instance,
203 const CMPIBroker * broker)
204 {
205 /* Unsupported. */
206 return -1;
207 }