os-cmpi-xen

view src/Xen_MemoryCapabilitiesSettingData_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 33d4316c01a2
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 // Description:
20 // ============================================================================
22 #include <string.h>
23 #include <stdlib.h>
25 #include "Xen_MemoryCapabilitiesSettingData_Resource.h"
27 /* Include the required CMPI data types, function headers, and macros. */
28 #include "cmpidt.h"
29 #include "cmpift.h"
30 #include "cmpimacs.h"
32 // ----------------------------------------------------------------------------
34 /* Get a handle to the list of all system resources for this class. */
35 int Xen_MemoryCapabilitiesSettingData_getResources( _RESOURCES ** resources )
36 {
37 /* malloc a new handle for the resources list. */
38 *resources = (_RESOURCES *)calloc(1,sizeof(_RESOURCES));
39 if (*resources == NULL) return 0;
41 (*resources)->currentsettingdatanum = 0;
43 return 1;
44 }
46 // ----------------------------------------------------------------------------
48 /* Free/deallocate/cleanup the resources list after use. */
49 int Xen_MemoryCapabilitiesSettingData_freeResources( _RESOURCES * resources )
50 {
51 if (resources != NULL) {
52 free(resources);
53 resources = NULL;
54 }
56 return 1;
57 }
59 // ----------------------------------------------------------------------------
61 /* Iterator to get the next resource from the resources list. */
62 int Xen_MemoryCapabilitiesSettingData_getNextResource( _RESOURCES * resources, _RESOURCE ** resource )
63 {
64 if (resources == NULL) return 0;
65 if (resources->currentsettingdatanum == 4) return 0;
67 /* Generate raw data for the single resource. */
68 *resource = (_RESOURCE *)calloc(1,sizeof(_RESOURCE));
69 if (*resource == NULL) return 0;
71 switch (resources->currentsettingdatanum) {
72 case 0: /* Minimum */
73 strcpy((*resource)->instanceid, "Minimum");
74 (*resource)->reservation = 16 << 20; /* 16MB */
75 (*resource)->limit = 16 << 20;
76 (*resource)->quantity = 16 << 20;
77 // (*resource)->weight = 1;
78 break;
80 case 1: /* Maximum */
81 strcpy((*resource)->instanceid, "Maximum");
82 (*resource)->reservation = 1024 << 20; /* 1GB */
83 (*resource)->limit = 1024 << 20;
84 (*resource)->quantity = 1024 << 20;
85 // (*resource)->weight = 1;
86 break;
88 case 2: /* Increment */
89 strcpy((*resource)->instanceid, "Increment");
90 (*resource)->reservation = 1;
91 (*resource)->limit = 1;
92 (*resource)->quantity = 1;
93 // (*resource)->weight = 1;
94 break;
96 case 3: /* Default */
97 strcpy((*resource)->instanceid, "Default");
98 (*resource)->reservation = 64 << 20; /* 64MB */
99 (*resource)->limit = 64 << 20;
100 (*resource)->quantity = 64 << 20;
101 // (*resource)->weight = 1;
102 break;
104 default:
105 return 0;
106 }
108 /* Move to the next setting data for next time. */
109 resources->currentsettingdatanum++;
111 return 1;
112 }
114 // ----------------------------------------------------------------------------
116 /* Get the specific resource that matches the CMPI object path. */
117 int Xen_MemoryCapabilitiesSettingData_getResourceForObjectPath( _RESOURCES * resources, _RESOURCE ** resource, const CMPIObjectPath * objectpath )
118 {
119 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
121 if (resources == NULL) return 0;
122 if (CMIsNullObject(objectpath)) return 0;
124 /* Obtain the target resource name from the CMPIObjectPath key. */
125 CMPIData namedata = CMGetKey(objectpath, "InstanceID", &status);
126 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) return 0;
128 /* Extract the name string from the CMPIString. */
129 char * name = CMGetCharPtr(namedata.value.string);
130 if ((name == NULL) || (*name == '\0')) return 0;
132 /* Generate raw data for the single resource. */
133 *resource = (_RESOURCE *)malloc(sizeof(_RESOURCE));
134 if (*resource == NULL) return 0;
136 if (strcmp(name, "Minimum") == 0) {
137 strcpy((*resource)->instanceid, "Minimum");
138 (*resource)->reservation = 16 << 20; /* 16MB */
139 (*resource)->limit = 16 << 20;
140 (*resource)->quantity = 16 << 20;
141 // (*resource)->weight = 1;
142 }
143 else if (strcmp(name, "Maximum") == 0) {
144 strcpy((*resource)->instanceid, "Maximum");
145 (*resource)->reservation = 1024 << 20; /* 1GB */
146 (*resource)->limit = 1024 << 20;
147 (*resource)->quantity = 1024 << 20;
148 // (*resource)->weight = 1;
149 }
150 else if (strcmp(name, "Increment") == 0) {
151 strcpy((*resource)->instanceid, "Increment");
152 (*resource)->reservation = 1;
153 (*resource)->limit = 1;
154 (*resource)->quantity = 1;
155 // (*resource)->weight = 1;
156 }
157 else if (strcmp(name, "Default") == 0) {
158 strcpy((*resource)->instanceid, "Default");
159 (*resource)->reservation = 64 << 20; /* 64MB */
160 (*resource)->limit = 64 << 20;
161 (*resource)->quantity = 64 << 20;
162 // (*resource)->weight = 1;
163 }
164 else {
165 return 0;
166 }
168 return 1;
169 }
171 // ----------------------------------------------------------------------------
173 /* Free/deallocate/cleanup the resource after use. */
174 int Xen_MemoryCapabilitiesSettingData_freeResource( _RESOURCE * resource )
175 {
176 if (resource != NULL) {
177 free(resource);
178 resource = NULL;
179 }
181 return 1;
182 }
184 // ----------------------------------------------------------------------------
186 /* Set the property values of a CMPI instance from a specific resource. */
187 int Xen_MemoryCapabilitiesSettingData_setInstanceFromResource( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker, _RESOURCES * resources )
188 {
189 if (resource == NULL) return 0;
190 if (CMIsNullObject(instance)) return 0;
192 /* Set the CMPIInstance properties from the resource data. */
193 CMSetProperty(instance, "InstanceID",(CMPIValue *)resource->instanceid, CMPI_chars);
194 unsigned long long cpus;
196 CMSetProperty(instance, "Reservation",(CMPIValue *)&(resource->reservation), CMPI_uint64);
197 CMSetProperty(instance, "Limit",(CMPIValue *)&(resource->limit), CMPI_uint64);
198 CMSetProperty(instance, "Quantity",(CMPIValue *)&(resource->quantity), CMPI_uint64);
199 // CMSetProperty(instance, "Weight",(CMPIValue *)&(resource->weight), CMPI_uint32);
201 int type = 3; /* 3 == Memory */
202 CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
203 int virtualized = 0;
204 CMSetProperty(instance, "Virtualized" , (CMPIValue *)&virtualized, CMPI_boolean);
205 CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Bytes", CMPI_chars);
206 int mutable = 1;
207 CMSetProperty(instance, "Mutable" , (CMPIValue *)&mutable, CMPI_boolean);
209 return 1;
210 }
212 // ----------------------------------------------------------------------------
214 /* Delete the specified resource from the system. */
215 int Xen_MemoryCapabilitiesSettingData_deleteResource( _RESOURCES * resources, _RESOURCE * resource )
216 {
217 /* Unsupported. */
218 return -1;
219 }
221 // ----------------------------------------------------------------------------
223 /* Modify the specified resource using the property values of a CMPI instance. */
224 int Xen_MemoryCapabilitiesSettingData_setResourceFromInstance( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker )
225 {
226 /* Unsupported. */
227 return -1;
228 }
230 // ----------------------------------------------------------------------------
232 /* Create a new resource using the property values of a CMPI instance. */
233 int Xen_MemoryCapabilitiesSettingData_createResourceFromInstance( _RESOURCES * resources, _RESOURCE ** resource, const CMPIInstance * instance, const CMPIBroker * broker )
234 {
235 /* Unsupported. */
236 return -1;
237 }