os-cmpi-xen

annotate src/Xen_NetworkPortSettingData_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
rev   line source
jbulpin@0 1 // Copyright (C) 2006 IBM Corporation
jbulpin@0 2 //
jbulpin@0 3 // This library is free software; you can redistribute it and/or
jbulpin@0 4 // modify it under the terms of the GNU Lesser General Public
jbulpin@0 5 // License as published by the Free Software Foundation; either
jbulpin@0 6 // version 2.1 of the License, or (at your option) any later version.
jbulpin@0 7 //
jbulpin@0 8 // This library is distributed in the hope that it will be useful,
jbulpin@0 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
jbulpin@0 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
jbulpin@0 11 // Lesser General Public License for more details.
jbulpin@0 12 //
jbulpin@0 13 // You should have received a copy of the GNU Lesser General Public
jbulpin@0 14 // License along with this library; if not, write to the Free Software
jbulpin@0 15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
jbulpin@0 16 // ============================================================================
jbulpin@0 17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
jbulpin@0 18 // Tokunbo Adeshiyan, <tokunbo@us.ibm.com>
jfehlig@31 19 // Contributors: Jim Fehlig, <jfehlig@novell.com>
jbulpin@0 20 // Description:
jbulpin@0 21 // ============================================================================
jbulpin@0 22
jfehlig@3 23 #include <stdlib.h>
jfehlig@3 24 #include <string.h>
jfehlig@33 25 #include <assert.h>
jfehlig@33 26
jfehlig@36 27 #include <xen_common.h>
jfehlig@36 28 #include <xen_vm.h>
jfehlig@36 29 #include <xen_vif.h>
jfehlig@3 30
jbulpin@0 31 #include "Xen_NetworkPortSettingData_Resource.h"
jbulpin@0 32
jbulpin@0 33 /* Include the required CMPI data types, function headers, and macros. */
jbulpin@0 34 #include "cmpidt.h"
jbulpin@0 35 #include "cmpift.h"
jbulpin@0 36 #include "cmpimacs.h"
jbulpin@0 37
jfehlig@33 38 #include "xen_utils.h"
jfehlig@53 39 #include "provider_common.h"
jfehlig@53 40
jbulpin@0 41
jbulpin@0 42 // ----------------------------------------------------------------------------
jbulpin@0 43
jfehlig@66 44 static int concat_vif_lists(xen_vif_set **target, xen_vif_set *source)
jfehlig@66 45 {
jfehlig@66 46
jfehlig@66 47 int total_size;
jfehlig@66 48 int i, j;
jfehlig@66 49
jfehlig@66 50 /* Nothing to concatenate if source is empty */
jfehlig@66 51 if (source == NULL || source->size == 0)
jfehlig@66 52 return 1;
jfehlig@66 53
jfehlig@66 54 /* If targe is empty, assign source to target */
jfehlig@66 55 if (*target == NULL) {
jfehlig@66 56 *target = source;
jfehlig@66 57 return 1;
jfehlig@66 58 }
jfehlig@66 59
jfehlig@66 60 /* realloc memory and append source to target */
jfehlig@66 61 total_size = (*target)->size + source->size;
jfehlig@66 62 *target = realloc(*target, sizeof(xen_vif_set) + (total_size * sizeof(xen_vif)));
jfehlig@66 63 if (*target == NULL)
jfehlig@66 64 return 0;
jfehlig@66 65
jfehlig@66 66 for (j = (*target)->size, i = 0; i < source->size; i++) {
jfehlig@66 67 (*target)->contents[j + i] = source->contents[i];
jfehlig@66 68 source->contents[i] = NULL;
jfehlig@66 69 }
jfehlig@66 70 (*target)->size = total_size;
jfehlig@66 71
jfehlig@66 72 /* Free source list - it has been copied to target */
jfehlig@66 73 xen_vif_set_free(source);
jfehlig@66 74 return 1;
jfehlig@66 75 }
jfehlig@66 76
jfehlig@66 77
jbulpin@0 78 /* Get a handle to the list of all system resources for this class. */
jfehlig@47 79 int Xen_NetworkPortSettingData_getResources(xen_utils_session *session,
jfehlig@47 80 _RESOURCES ** resources)
jbulpin@0 81 {
jfehlig@66 82 xen_domain_resources *res;
jfehlig@66 83 xen_vif_set *all_vifs = NULL;
jfehlig@66 84 xen_vm_record *vm_rec = NULL;
jfehlig@66 85
jfehlig@53 86 /* malloc a new handle for the resources list. */
jfehlig@53 87 *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
jfehlig@66 88 if (*resources == NULL)
jfehlig@66 89 return 0;
jfehlig@53 90
jfehlig@66 91 /* Get a list of domain resources. */
jfehlig@66 92 if (!xen_utils_get_domain_resources(session, &res)) {
jfehlig@53 93 *resources = NULL;
jfehlig@53 94 return 0;
jfehlig@53 95 }
jfehlig@66 96
jfehlig@66 97 /* Create list of vif resources from vifs found in each domain. */
jfehlig@66 98 while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) {
jfehlig@66 99 xen_vif_set *vif_set;
jfehlig@66 100 if (!xen_vm_get_vifs(session->xen, &vif_set, vm_rec->handle))
jfehlig@66 101 goto Error;
jfehlig@66 102
jfehlig@66 103 if (!concat_vif_lists(&all_vifs, vif_set))
jfehlig@66 104 goto Error;
jfehlig@66 105
jfehlig@66 106 xen_vm_record_free(vm_rec);
jfehlig@66 107 }
jfehlig@53 108
jfehlig@66 109 (*resources)->vifs = all_vifs;
jfehlig@53 110 (*resources)->currentvifnum = 0;
jfehlig@66 111
jfehlig@53 112 return 1;
jfehlig@66 113
jfehlig@66 114 Error:
jfehlig@66 115 xen_vm_record_free(vm_rec);
jfehlig@66 116 xen_utils_free_domain_resources(res);
jfehlig@66 117 free(*resources);
jfehlig@66 118 *resources = NULL;
jfehlig@66 119 return 0;
jbulpin@0 120 }
jbulpin@0 121
jbulpin@0 122 // ----------------------------------------------------------------------------
jbulpin@0 123
jbulpin@0 124 /* Free/deallocate/cleanup the resources list after use. */
jfehlig@47 125 int Xen_NetworkPortSettingData_freeResources(_RESOURCES * resources)
jbulpin@0 126 {
jfehlig@53 127 if (resources != NULL) {
jfehlig@66 128 if (resources->vifs != NULL)
jfehlig@66 129 xen_vif_set_free(resources->vifs);
jfehlig@53 130 free(resources);
jfehlig@53 131 resources = NULL;
jfehlig@53 132 }
jfehlig@53 133
jfehlig@53 134 return 1;
jbulpin@0 135 }
jbulpin@0 136
jbulpin@0 137 // ----------------------------------------------------------------------------
jbulpin@0 138
jbulpin@0 139 /* Iterator to get the next resource from the resources list. */
jfehlig@47 140 int Xen_NetworkPortSettingData_getNextResource(xen_utils_session *session,
jfehlig@47 141 _RESOURCES * resources,
jfehlig@47 142 _RESOURCE ** resource)
jbulpin@0 143 {
jfehlig@66 144 if (resources == NULL || resources->vifs == NULL)
jfehlig@53 145 return 0;
jfehlig@53 146
jfehlig@66 147 /* Check if reached the end of the list of vifs. */
jfehlig@66 148 if (resources->currentvifnum == resources->vifs->size)
jfehlig@53 149 return 0;
jfehlig@53 150
jfehlig@66 151 /* Get the current vif record. */
jfehlig@66 152 if (!xen_vif_get_record(session->xen, resource, resources->vifs->contents[resources->currentvifnum]))
jfehlig@53 153 return 0;
jfehlig@66 154
jfehlig@66 155 resources->currentvifnum++;
jfehlig@53 156 return 1;
jbulpin@0 157 }
jbulpin@0 158
jbulpin@0 159 // ----------------------------------------------------------------------------
jbulpin@0 160
jbulpin@0 161 /* Get the specific resource that matches the CMPI object path. */
jfehlig@47 162 int Xen_NetworkPortSettingData_getResourceForObjectPath(xen_utils_session *session,
jfehlig@47 163 _RESOURCE ** resource,
jfehlig@47 164 const CMPIObjectPath * objectpath)
jbulpin@0 165 {
jfehlig@53 166 char *instId;
jfehlig@66 167 char uuid[MAX_SYSTEM_NAME_LEN];
jfehlig@66 168 int ccode;
jbulpin@0 169 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jbulpin@0 170
jbulpin@0 171 if (CMIsNullObject(objectpath)) return 0;
jbulpin@0 172
jbulpin@0 173 /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
jbulpin@0 174 CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
jbulpin@0 175 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
jbulpin@0 176
jfehlig@53 177 instId = CMGetCharPtr(iddata.value.string);
jfehlig@53 178 if ((instId == NULL) || (*instId == '\0')) return 0;
jfehlig@53 179
jfehlig@66 180 /* Extract the disk uuid from InstanceID property. */
jfehlig@66 181 if (!_CMPIStrncpyDeviceNameFromID(uuid, instId, MAX_SYSTEM_NAME_LEN))
jfehlig@53 182 return 0;
jbulpin@0 183
jfehlig@66 184 xen_vif vif;
jfehlig@66 185 if (!xen_vif_get_by_uuid(session->xen, &vif, uuid))
jfehlig@53 186 return 0;
jfehlig@63 187
jfehlig@66 188 ccode = xen_vif_get_record(session->xen, resource, vif);
jfehlig@66 189 xen_vif_free(vif);
jfehlig@66 190 return ccode;
jbulpin@0 191 }
jbulpin@0 192
jbulpin@0 193 // ----------------------------------------------------------------------------
jbulpin@0 194
jbulpin@0 195 /* Free/deallocate/cleanup the resource after use. */
jfehlig@47 196 int Xen_NetworkPortSettingData_freeResource(_RESOURCE * resource)
jbulpin@0 197 {
jfehlig@66 198 xen_vif_record_free(resource);
jfehlig@66 199 return 1;
jbulpin@0 200 }
jbulpin@0 201
jbulpin@0 202 // ----------------------------------------------------------------------------
jbulpin@0 203
jbulpin@0 204 /* Set the property values of a CMPI instance from a specific resource. */
jfehlig@53 205 int Xen_NetworkPortSettingData_setInstanceFromResource(xen_utils_session *session,
jfehlig@53 206 _RESOURCE * resource,
jfehlig@47 207 const CMPIInstance * instance,
jfehlig@67 208 const CMPIBroker * broker)
jbulpin@0 209 {
jfehlig@66 210 char buf[MAX_INSTANCEID_LEN];
jfehlig@66 211 xen_vm_record *alloced_vm_rec = NULL;
jfehlig@66 212 xen_vm_record *vm_rec;
jfehlig@66 213
jbulpin@0 214 if (resource == NULL) return 0;
jbulpin@0 215 if (CMIsNullObject(instance)) return 0;
jbulpin@0 216
jfehlig@66 217 xen_vm_record_opt *vm_rec_opt = resource->vm;
jfehlig@66 218 if (vm_rec_opt->is_record) {
jfehlig@66 219 vm_rec = vm_rec_opt->u.record;
jfehlig@53 220 }
jfehlig@66 221 else {
jfehlig@66 222 if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) {
jfehlig@53 223 /* Error description in session object! */
jfehlig@53 224 return 0;
jfehlig@53 225 }
jfehlig@66 226 alloced_vm_rec = vm_rec;
jfehlig@53 227 }
jfehlig@3 228
jfehlig@53 229 /* Set the CMPIInstance properties from the resource data. */
jfehlig@66 230 snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", vm_rec->name_label, resource->uuid);
jfehlig@53 231 CMSetProperty(instance, "InstanceID",(CMPIValue *)buf, CMPI_chars);
jfehlig@66 232 CMSetProperty(instance, "ElementName",(CMPIValue *)resource->device, CMPI_chars);
jfehlig@3 233
jfehlig@3 234 int type = 10; /* 10 == Ethernet Adapter */
jfehlig@3 235 CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
jbulpin@0 236
jfehlig@33 237 int consumerVisibility = 3; /* 3 == Virtualized */
jfehlig@33 238 CMSetProperty(instance, "ConsumerVisibility" , (CMPIValue *)&consumerVisibility, CMPI_uint16);
jbulpin@0 239
jbulpin@0 240 unsigned long long nics = 1;
jbulpin@0 241 CMSetProperty(instance, "Reservation",(CMPIValue *)&nics, CMPI_uint64);
jbulpin@0 242 CMSetProperty(instance, "Limit",(CMPIValue *)&nics, CMPI_uint64);
jbulpin@0 243 CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Interfaces", CMPI_chars);
jfehlig@3 244 CMSetProperty(instance, "VirtualQuantity",(CMPIValue *)&nics, CMPI_uint64);
jbulpin@0 245
jfehlig@3 246 int alloctype = 1;
jfehlig@3 247 CMSetProperty(instance, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean);
jfehlig@3 248 CMSetProperty(instance, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean);
jfehlig@3 249
jfehlig@97 250 char nic_config_info[512];
jfehlig@97 251 nic_config_info[0] = '\0';
jfehlig@97 252 if (resource->mac)
jfehlig@97 253 snprintf(nic_config_info, 512, "mac=%s", resource->mac);
jfehlig@99 254 /* if (resource->model) {
jfehlig@97 255 strncat(nic_config_info, ",model=", 512 - strlen(nic_config_info));
jfehlig@97 256 strncat(nic_config_info, resource->model, 512 - strlen(nic_config_info));
jfehlig@99 257 }Nic config info does have model*/
jfehlig@97 258 if (nic_config_info[0] != '\0')
jfehlig@97 259 CMSetProperty(instance, "NICConfigInfo" , (CMPIValue *)nic_config_info, CMPI_chars);
jfehlig@97 260
jfehlig@3 261 /*
jfehlig@3 262 * TODO:
jfehlig@3 263 * PoolID, Weight
jfehlig@3 264 */
jbulpin@0 265
jbulpin@0 266 return 1;
jbulpin@0 267 }
jbulpin@0 268
jbulpin@0 269 // ----------------------------------------------------------------------------
jbulpin@0 270
jbulpin@0 271 /* Delete the specified resource from the system. */
jfehlig@74 272 int Xen_NetworkPortSettingData_deleteResource(xen_utils_session *session,
jfehlig@47 273 _RESOURCE * resource)
jbulpin@0 274 {
jfehlig@74 275 return xen_vif_destroy(session->xen, resource->handle);
jbulpin@0 276 }
jbulpin@0 277
jbulpin@0 278 // ----------------------------------------------------------------------------
jbulpin@0 279
jbulpin@0 280 /* Modify the specified resource using the property values of a CMPI instance. */
jfehlig@47 281 int Xen_NetworkPortSettingData_setResourceFromInstance(_RESOURCE * resource,
jfehlig@47 282 const CMPIInstance * instance,
jfehlig@47 283 const CMPIBroker * broker)
jbulpin@0 284 {
jbulpin@0 285 /* Unsupported. */
jbulpin@0 286 return -1;
jbulpin@0 287 }
jbulpin@0 288
jbulpin@0 289 // ----------------------------------------------------------------------------
jbulpin@0 290
jbulpin@0 291 /* Create a new resource using the property values of a CMPI instance. */
jfehlig@47 292 int Xen_NetworkPortSettingData_createResourceFromInstance(_RESOURCES * resources,
jfehlig@47 293 _RESOURCE ** resource,
jfehlig@47 294 const CMPIInstance * instance,
jfehlig@47 295 const CMPIBroker * broker)
jbulpin@0 296 {
jbulpin@0 297 /* Unsupported. */
jbulpin@0 298 return -1;
jbulpin@0 299 }
jbulpin@0 300