os-cmpi-xen

view src/Xen_ProcessorSettingData_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 b66e845be7e4
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 // Contributors: Jim Fehlig, <jfehlig@novell.com>
19 // Raj Subrahmanian <raj.subrahmanian@unisys.com>
20 // Description:
21 // ============================================================================
23 #include <stdlib.h>
24 #include <string.h>
25 #include <assert.h>
27 #include <xen_common.h>
28 #include <xen_vm.h>
29 #include <xen_vm_metrics.h>
31 #include "Xen_ProcessorSettingData_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"
39 #include "provider_common.h"
41 // ----------------------------------------------------------------------------
43 /* Get a handle to the list of all system resources for this class. */
44 int Xen_ProcessorSettingData_getResources(xen_utils_session *session,
45 _RESOURCES ** resources)
46 {
47 return xen_utils_get_domain_resources(session, resources);
48 }
50 // ----------------------------------------------------------------------------
52 /* Free/deallocate/cleanup the resources list after use. */
53 int Xen_ProcessorSettingData_freeResources(_RESOURCES * resources)
54 {
55 return xen_utils_free_domain_resources(resources);
56 }
58 // ----------------------------------------------------------------------------
60 /* Iterator to get the next resource from the resources list. */
61 int Xen_ProcessorSettingData_getNextResource(xen_utils_session *session,
62 _RESOURCES * resources,
63 _RESOURCE ** resource)
64 {
65 return xen_utils_get_next_domain_resource(session, resources, resource);
66 }
68 // ----------------------------------------------------------------------------
70 /* Get the specific resource that matches the CMPI object path. */
71 int Xen_ProcessorSettingData_getResourceForObjectPath(xen_utils_session *session,
72 _RESOURCES * resources,
73 _RESOURCE ** resource,
74 const CMPIObjectPath * objectpath)
75 {
76 char *instId;
77 char name[MAX_SYSTEM_NAME_LEN];
78 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
80 /* Check input params are valid. */
81 if (resources == NULL) return 0;
82 if (CMIsNullObject(objectpath)) return 0;
84 /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
85 CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
86 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
88 /* Extract the id string from the CMPIString. */
89 instId = CMGetCharPtr(iddata.value.string);
90 if ((instId == NULL) || (*instId == '\0')) return 0;
92 /* Extract the system name from InstanceID property. */
93 if (!_CMPIStrncpySystemNameFromID(name, instId, MAX_SYSTEM_NAME_LEN))
94 return 0;
96 /* Get the domain data for the target domain name. */
97 xen_vm_set *vms;
98 if (!xen_vm_get_by_name_label(session->xen, &vms, name)) {
99 /* Error is in session object! */
100 *resource = NULL;
101 return 0;
102 }
104 assert(vms->size == 1);
105 if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) {
106 /* Error description in session object! */
107 xen_vm_set_free(vms);
108 return 0;
109 }
111 xen_vm_set_free(vms);
113 return 1;
114 }
116 // ----------------------------------------------------------------------------
118 /* Free/deallocate/cleanup the resource after use. */
119 int Xen_ProcessorSettingData_freeResource(_RESOURCE * resource)
120 {
121 return xen_utils_free_domain_resource(resource);
122 }
124 // ----------------------------------------------------------------------------
126 /* Set the property values of a CMPI instance from a specific resource.
127 We also pass in the session object so that the metrics class can be accessed when required.
128 */
129 int Xen_ProcessorSettingData_setInstanceFromResource(xen_utils_session *session,
130 _RESOURCE * resource,
131 const CMPIInstance * instance,
132 const CMPIBroker * broker)
133 {
134 char buf[1024];
136 if (resource == NULL) return 0;
137 if (CMIsNullObject(instance)) return 0;
139 /* Set the CMPIInstance properties from the resource data. */
140 snprintf(buf, 1024, "Xen:%s:Processor", resource->name_label);
141 CMSetProperty(instance, "InstanceID",(CMPIValue *)buf, CMPI_chars);
143 CMSetProperty(instance, "ElementName",(CMPIValue *)"Processor", CMPI_chars);
145 int type = 3; /* 3 == CPU */
146 CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
148 int consumerVisibility = 3; /* 3 == Virtualized */
149 CMSetProperty(instance, "ConsumerVisibility" , (CMPIValue *)&consumerVisibility, CMPI_uint16);
151 int64_t cpus = 1;
152 CMSetProperty(instance, "Reservation",(CMPIValue *)&cpus, CMPI_uint64);
153 CMSetProperty(instance, "Limit",(CMPIValue *)&cpus, CMPI_uint64);
154 CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Cores", CMPI_chars);
155 CMSetProperty(instance, "VirtualQuantity",(CMPIValue *)&(resource->vcpus_at_startup), CMPI_uint64);
157 int alloctype = 1;
158 CMSetProperty(instance, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean);
159 CMSetProperty(instance, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean);
161 /*
162 * TODO:
163 * PoolID, Weight, HostResource when cpus pinned
164 */
166 return 1;
167 }
169 // ----------------------------------------------------------------------------
171 /* Delete the specified resource from the system. */
172 int Xen_ProcessorSettingData_deleteResource(_RESOURCES * resources,
173 _RESOURCE * resource)
174 {
175 /* Unsupported. */
176 return -1;
177 }
179 // ----------------------------------------------------------------------------
181 /* Modify the specified resource using the property values of a CMPI instance. */
182 int Xen_ProcessorSettingData_setResourceFromInstance(_RESOURCE * resource,
183 const CMPIInstance * instance,
184 const CMPIBroker * broker)
185 {
186 /* Unsupported. */
187 return -1;
188 }
190 // ----------------------------------------------------------------------------
192 /* Create a new resource using the property values of a CMPI instance. */
193 int Xen_ProcessorSettingData_createResourceFromInstance(_RESOURCES * resources,
194 _RESOURCE ** resource,
195 const CMPIInstance * instance,
196 const CMPIBroker * broker)
197 {
198 /* Unsupported. */
199 return -1;
200 }