os-cmpi-xen

view src/Xen_VirtualizationCapabilities_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_VirtualizationCapabilities_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_VirtualizationCapabilities_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)->currentcapabilitynum = 0;
43 return 1;
44 }
46 // ----------------------------------------------------------------------------
48 /* Free/deallocate/cleanup the resources list after use. */
49 int Xen_VirtualizationCapabilities_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_VirtualizationCapabilities_getNextResource( _RESOURCES * resources, _RESOURCE ** resource )
63 {
64 if (resources == NULL) return 0;
65 if (resources->currentcapabilitynum == 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->currentcapabilitynum) {
72 case 0: /* Processor (shared) */
73 strcpy((*resource)->resourcetype, "Processor");
74 sprintf((*resource)->instanceid, "Xen_%sVirtualizationCapability", (*resource)->resourcetype);
75 (*resource)->shared = 1;
76 (*resource)->mutable = 0;
77 break;
79 case 1: /* Memory (dedicated) */
80 strcpy((*resource)->resourcetype, "Memory");
81 sprintf((*resource)->instanceid, "Xen_%sVirtualizationCapability", (*resource)->resourcetype);
82 (*resource)->shared = 0;
83 (*resource)->mutable = 1;
84 break;
86 case 2: /* Disk (dedicated) */
87 strcpy((*resource)->resourcetype, "Disk");
88 sprintf((*resource)->instanceid, "Xen_%sVirtualizationCapability", (*resource)->resourcetype);
89 (*resource)->shared = 1;
90 (*resource)->mutable = 0;
91 break;
93 case 3: /* NetworkPort (dedicated) */
94 strcpy((*resource)->resourcetype, "NetworkPort");
95 sprintf((*resource)->instanceid, "Xen_%sVirtualizationCapability", (*resource)->resourcetype);
96 (*resource)->shared = 0;
97 (*resource)->mutable = 0;
98 break;
100 default:
101 return 0;
102 }
104 /* Move to the next capability for next time. */
105 resources->currentcapabilitynum++;
107 return 1;
108 }
110 // ----------------------------------------------------------------------------
112 /* Get the specific resource that matches the CMPI object path. */
113 int Xen_VirtualizationCapabilities_getResourceForObjectPath( _RESOURCES * resources, _RESOURCE ** resource, const CMPIObjectPath * objectpath )
114 {
115 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
117 if (resources == NULL) return 0;
118 if (CMIsNullObject(objectpath)) return 0;
120 /* Obtain the target resource name from the CMPIObjectPath key. */
121 CMPIData namedata = CMGetKey(objectpath, "InstanceID", &status);
122 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) return 0;
124 /* Extract the name string from the CMPIString. */
125 char * name = CMGetCharPtr(namedata.value.string);
126 if ((name == NULL) || (*name == '\0')) return 0;
128 /* Generate raw data for the single resource. */
129 *resource = (_RESOURCE *)malloc(sizeof(_RESOURCE));
130 if (*resource == NULL) return 0;
132 if (strcmp(name, "Xen_ProcessorVirtualizationCapability") == 0) {
133 /* Processor (shared) */
134 strcpy((*resource)->resourcetype, "Processor");
135 sprintf((*resource)->instanceid, "Xen_%sVirtualizationCapability", (*resource)->resourcetype);
136 (*resource)->shared = 1;
137 (*resource)->mutable = 0;
138 }
139 else if (strcmp(name, "Xen_MemoryVirtualizationCapability") == 0) {
140 /* Memory (dedicated) */
141 strcpy((*resource)->resourcetype, "Memory");
142 sprintf((*resource)->instanceid, "Xen_%sVirtualizationCapability", (*resource)->resourcetype);
143 (*resource)->shared = 0;
144 (*resource)->mutable = 1;
145 }
146 else if (strcmp(name, "Xen_DiskVirtualizationCapability") == 0) {
147 /* Disk (dedicated) */
148 strcpy((*resource)->resourcetype, "Disk");
149 sprintf((*resource)->instanceid, "Xen_%sVirtualizationCapability", (*resource)->resourcetype);
150 (*resource)->shared = 1;
151 (*resource)->mutable = 0;
152 }
153 else if (strcmp(name, "Xen_NetworkPortVirtualizationCapability") == 0) {
154 /* NetworkPort (dedicated) */
155 strcpy((*resource)->resourcetype, "NetworkPort");
156 sprintf((*resource)->instanceid, "Xen_%sVirtualizationCapability", (*resource)->resourcetype);
157 (*resource)->shared = 0;
158 (*resource)->mutable = 0;
159 }
160 else {
161 return 0;
162 }
164 return 1;
165 }
167 // ----------------------------------------------------------------------------
169 /* Free/deallocate/cleanup the resource after use. */
170 int Xen_VirtualizationCapabilities_freeResource( _RESOURCE * resource )
171 {
172 if (resource != NULL) {
173 free(resource);
174 resource = NULL;
175 }
177 return 1;
178 }
180 // ----------------------------------------------------------------------------
182 /* Set the property values of a CMPI instance from a specific resource. */
183 int Xen_VirtualizationCapabilities_setInstanceFromResource( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker, _RESOURCES * resources )
184 {
185 if (resource == NULL) return 0;
186 if (CMIsNullObject(instance)) return 0;
188 /* Set the CMPIInstance properties from the resource data. */
189 CMSetProperty(instance, "InstanceID",(CMPIValue *)resource->instanceid, CMPI_chars);
190 CMSetProperty(instance, "ElementName",(CMPIValue *)resource->instanceid, CMPI_chars);
191 CMSetProperty(instance, "ResourceType",(CMPIValue *)resource->resourcetype, CMPI_chars);
192 CMSetProperty(instance, "Shared",(CMPIValue *)&(resource->shared), CMPI_boolean);
193 CMSetProperty(instance, "Mutable",(CMPIValue *)&(resource->mutable), CMPI_boolean);
195 return 1;
196 }
198 // ----------------------------------------------------------------------------
200 /* Delete the specified resource from the system. */
201 int Xen_VirtualizationCapabilities_deleteResource( _RESOURCES * resources, _RESOURCE * resource )
202 {
203 /* Unsupported. */
204 return -1;
205 }
207 // ----------------------------------------------------------------------------
209 /* Modify the specified resource using the property values of a CMPI instance. */
210 int Xen_VirtualizationCapabilities_setResourceFromInstance( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker )
211 {
212 /* Unsupported. */
213 return -1;
214 }
216 // ----------------------------------------------------------------------------
218 /* Create a new resource using the property values of a CMPI instance. */
219 int Xen_VirtualizationCapabilities_createResourceFromInstance( _RESOURCES * resources, _RESOURCE ** resource, const CMPIInstance * instance, const CMPIBroker * broker )
220 {
221 /* Unsupported. */
222 return -1;
223 }