os-cmpi-xen

view src/Xen_ComputerSystemCapabilities_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 e0f068d0632a
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: Encapsulates the resources used instrument
20 // Xen_ComputerSystemCapabilities.
21 // ============================================================================
23 #include <string.h>
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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_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, "InstanceID", &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_ComputerSystemCapabilities_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_ComputerSystemCapabilities_setInstanceFromResource(_RESOURCE * resource,
120 const CMPIInstance * instance,
121 const CMPIBroker * broker)
122 {
123 CMPIArray *statesSupported = CMNewArray(broker, 6, CMPI_uint16, NULL);
125 if (resource == NULL) return 0;
126 if (CMIsNullObject(instance)) return 0;
128 /* Set the CMPIInstance properties from the resource data. */
129 CMSetProperty(instance, "InstanceID",(CMPIValue *)resource->name_label, CMPI_chars);
130 CMSetProperty(instance, "ElementName",(CMPIValue *)resource->name_label, CMPI_chars);
132 /*
133 * TODO:
134 * Do we want to support changing the name of a domain?
135 */
136 int nameEditSupported = 0;
137 CMSetProperty(instance, "ElementNameEditSupported",(CMPIValue *)&nameEditSupported, CMPI_boolean);
139 int state = 2; /* 'Enabled' */
140 CMSetArrayElementAt(statesSupported, 0, (CMPIValue *)&state, CMPI_uint16);
141 state = 3; /* 'Disabled' */
142 CMSetArrayElementAt(statesSupported, 1, (CMPIValue *)&state, CMPI_uint16);
143 state = 6; /* 'Offline' aka 'Suspend' */
144 CMSetArrayElementAt(statesSupported, 2, (CMPIValue *)&state, CMPI_uint16);
145 state = 9; /* 'Quiesce' */
146 CMSetArrayElementAt(statesSupported, 3, (CMPIValue *)&state, CMPI_uint16);
147 state = 10; /* 'Reboot' */
148 CMSetArrayElementAt(statesSupported, 4, (CMPIValue *)&state, CMPI_uint16);
149 state = 11; /* 'Reset' */
150 CMSetArrayElementAt(statesSupported, 5, (CMPIValue *)&state, CMPI_uint16);
152 CMSetProperty(instance, "RequestedStatesSupported",(CMPIValue *)&statesSupported, CMPI_uint16A);
154 return 1;
155 }
157 // ----------------------------------------------------------------------------
159 /* Delete the specified resource from the system. */
160 int Xen_ComputerSystemCapabilities_deleteResource(_RESOURCES * resources,
161 _RESOURCE * resource)
162 {
163 /* Unsupported. */
164 return -1;
165 }
167 // ----------------------------------------------------------------------------
169 /* Modify the specified resource using the property values of a CMPI instance. */
170 int Xen_ComputerSystemCapabilities_setResourceFromInstance(_RESOURCE * resource,
171 const CMPIInstance * instance,
172 const CMPIBroker * broker)
173 {
174 /* Unsupported. */
175 return -1;
176 }
178 // ----------------------------------------------------------------------------
180 /* Create a new resource using the property values of a CMPI instance. */
181 int Xen_ComputerSystemCapabilities_createResourceFromInstance(_RESOURCES * resources,
182 _RESOURCE ** resource,
183 const CMPIInstance * instance,
184 const CMPIBroker * broker)
185 {
186 /* Unsupported. */
187 return -1;
188 }