os-cmpi-xen

view src/Xen_ComputerSystem_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 7ca3bbf0810a
children
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 // Tokunbo Adeshiyan, <tokunbo@us.ibm.com>
19 // Jim Fehlig, <jfehlig@novell.com>
20 // Contributors:
21 // Description:
22 // ============================================================================
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <assert.h>
28 #include <xen_common.h>
29 #include <xen_vm.h>
31 #include "Xen_ComputerSystem_Resource.h"
33 /* Include the required CMPI data types, function headers, and macros. */
34 #include "cmpidt.h"
35 #include "cmpift.h"
36 #include "cmpimacs.h"
38 #include "xen_utils.h"
40 // ----------------------------------------------------------------------------
42 /* Get a handle to the list of all system resources for this class. */
43 int Xen_ComputerSystem_getResources(xen_utils_session *session,
44 _RESOURCES ** resources)
45 {
46 return xen_utils_get_domain_resources(session, resources);
47 }
49 // ----------------------------------------------------------------------------
51 /* Free/deallocate/cleanup the resources list after use. */
52 int Xen_ComputerSystem_freeResources( _RESOURCES * resources )
53 {
54 return xen_utils_free_domain_resources(resources);
55 }
57 // ----------------------------------------------------------------------------
59 /* Iterator to get the next resource from the resources list. */
60 int Xen_ComputerSystem_getNextResource(xen_utils_session *session,
61 _RESOURCES * resources,
62 _RESOURCE ** resource)
63 {
64 return xen_utils_get_next_domain_resource(session, resources, resource);
65 }
67 // ----------------------------------------------------------------------------
69 /* Get the specific resource that matches the CMPI object path. */
70 int Xen_ComputerSystem_getResourceForObjectPath(xen_utils_session *session,
71 _RESOURCES * resources,
72 _RESOURCE ** resource,
73 const CMPIObjectPath * objectpath)
74 {
75 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
77 if (resources == NULL) return 0;
78 if (CMIsNullObject(objectpath)) return 0;
80 /* Obtain the target domain name from the CMPIObjectPath "Name" key. */
81 CMPIData namedata = CMGetKey(objectpath, "Name", &status);
82 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) return 0;
84 /* Extract the domain name string from the CMPIString. */
85 char * domainname = CMGetCharPtr(namedata.value.string);
86 if ((domainname == NULL) || (*domainname == '\0')) return 0;
88 /* Get the domain data for the target domain name. */
89 xen_vm_set *vms;
90 if (!xen_vm_get_by_name_label(session->xen, &vms, domainname)) {
91 /* Error is in session object! */
92 *resource = NULL;
93 return 0;
94 }
96 assert(vms->size == 1);
97 if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) {
98 /* Error description in session object! */
99 xen_vm_set_free(vms);
100 return 0;
101 }
103 xen_vm_set_free(vms);
105 return 1;
106 }
108 // ----------------------------------------------------------------------------
110 /* Free/deallocate/cleanup the resource after use. */
111 int Xen_ComputerSystem_freeResource( _RESOURCE * resource )
112 {
113 return xen_utils_free_domain_resource(resource);
114 }
116 // ----------------------------------------------------------------------------
118 /* Set the property values of a CMPI instance from a specific resource. */
119 int Xen_ComputerSystem_setInstanceFromResource(_RESOURCE * resource,
120 CMPIInstance * instance,
121 const CMPIBroker * broker)
122 {
123 CMPIArray * status = CMNewArray(broker, 1, CMPI_uint16, NULL);
124 int statusvalue;
125 int enabledStateVal;
126 int requestedStateVal = 5; // "No Change"
128 if (resource == NULL) return 0;
129 if (CMIsNullObject(instance)) return 0;
131 /* Set the CMPIInstance properties from the resource data. */
132 CMSetProperty(instance, "CreationClassName",(CMPIValue *)"Xen_ComputerSystem", CMPI_chars);
133 CMSetProperty(instance, "Name",(CMPIValue *)resource->name_label, CMPI_chars);
134 CMSetProperty(instance, "Caption",(CMPIValue *)"Xen Virtual Computer System", CMPI_chars);
135 CMSetProperty(instance, "PrimaryOwnerName",(CMPIValue *)"", CMPI_chars);
136 CMSetProperty(instance, "PrimaryOwnerContact",(CMPIValue *)"", CMPI_chars);
137 CMSetProperty(instance, "Model",(CMPIValue *)"", CMPI_chars);
138 CMSetProperty(instance, "Description",(CMPIValue *)"Xen Virtual Computer System", CMPI_chars);
140 /* Set the "Status" and "OperationalStatus" properties of
141 * CIM_ManagedSystemElement. Set the "EnabledState" and
142 * "RequestedState property of CIM_EnabledLogicalElement.
143 * See those mof files for description of the properties
144 * and their values.
145 */
146 switch (resource->power_state)
147 {
148 case XEN_VM_POWER_STATE_HALTED:
149 statusvalue = 15; // "Dormant"
150 enabledStateVal = 3; // "Disabled"
151 CMSetProperty(instance, "Status",(CMPIValue *)"Stopped", CMPI_chars);
152 break;
154 case XEN_VM_POWER_STATE_PAUSED:
155 statusvalue = 15; // "Dormant"
156 enabledStateVal = 9; // "Quiesce"
157 CMSetProperty(instance, "Status",(CMPIValue *)"Stopped", CMPI_chars);
158 break;
160 case XEN_VM_POWER_STATE_RUNNING:
161 statusvalue = 2; // "OK"
162 enabledStateVal = 2; // "Enabled"
163 CMSetProperty(instance, "Status",(CMPIValue *)"OK", CMPI_chars);
164 break;
166 case XEN_VM_POWER_STATE_SUSPENDED:
167 statusvalue = 10; // "Stopped"
168 enabledStateVal = 6; // "Enabled but Offline"
169 // Status is just a string (and deprecated), so just say Suspended
170 CMSetProperty(instance, "Status",(CMPIValue *)"Suspended", CMPI_chars);
171 break;
173 /* case :
174 statusvalue = 9; // "Stopping"
175 enabledStateVal = 4; // "Shutting Down"
176 requestedStateVal = 3; // "Disabled"
177 CMSetProperty(instance, "Status",(CMPIValue *)"Stopping", CMPI_chars);
178 break;
179 */
180 default:
181 statusvalue = 0; // "Unknown"
182 enabledStateVal = 0; // "Unknown"
183 CMSetProperty(instance, "Status",(CMPIValue *)"No Contact", CMPI_chars);
184 break;
185 }
187 CMSetArrayElementAt(status, 0, (CMPIValue *)&statusvalue, CMPI_uint16);
188 CMSetProperty(instance, "OperationalStatus",(CMPIValue *)&status, CMPI_uint16A);
189 CMSetProperty(instance, "EnabledState",(CMPIValue *)&enabledStateVal, CMPI_uint16);
190 CMSetProperty(instance, "RequestedState",(CMPIValue *)&requestedStateVal, CMPI_uint16);
192 return 1;
193 }
195 // ----------------------------------------------------------------------------
197 /* Delete the specified resource from the system. */
198 int Xen_ComputerSystem_deleteResource(xen_utils_session *session,
199 _RESOURCES * resources,
200 _RESOURCE * resource)
201 {
202 if (resources == NULL) return 0;
203 if (resource == NULL) return 0;
205 /* If the Xen domain is active then shut it down. */
207 /* TODO:
208 * Is the CIM/WBEM DeleteInstance operation synchronous? Can a job
209 * be returned? If synchronous and the domain is NOT disabled, how
210 * long do we wait for it to become disabled before nuking it?
211 *
212 * For now we'll treat this operation as synchronous and not wait
213 * for shutdown before removing the domain.
214 */
215 if (resource->power_state != XEN_VM_POWER_STATE_HALTED)
216 // (resource->power_state != XEN_VM_POWER_STATE_SHUTTINGDOWN))
217 {
218 /* Initiate an asynchronous graceful shutdown of the domain's OS.
219 Note - this will also eventually destroy the domain! */
220 if (!xen_vm_clean_shutdown(session->xen, resource->handle)) {
221 /* Error description in session object! */
222 return 0;
223 }
224 }
226 /* Remove the configuration info for the domain. */
227 if (!xen_vm_destroy(session->xen, resource->handle)) {
228 /* Error description in session object! */
229 return 0;
230 }
232 return 1;
233 }
235 // ----------------------------------------------------------------------------
237 /* Modify the specified resource using the property values of a CMPI instance. */
238 int Xen_ComputerSystem_setResourceFromInstance(_RESOURCE * resource,
239 const CMPIInstance * instance,
240 const CMPIBroker * broker)
241 {
242 /* Unsupported. */
243 return -1;
244 }
246 // ----------------------------------------------------------------------------
248 /* Create a new resource using the property values of a CMPI instance. */
249 int Xen_ComputerSystem_createResourceFromInstance(_RESOURCES * resources,
250 _RESOURCE ** resource,
251 const CMPIInstance * instance,
252 const CMPIBroker * broker)
253 {
254 /* Unsupported. */
255 return -1;
256 }