os-cmpi-xen

annotate src/Xen_ComputerSystemSettingData_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 fa1ca0490794
children 28e8c94e92de
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>
jfehlig@31 18 // Contributors: Jim Fehlig, <jfehlig@novell.com>
jbulpin@0 19 // Description:
jbulpin@0 20 // ============================================================================
jbulpin@0 21
jfehlig@3 22 #include <stdlib.h>
jfehlig@3 23 #include <string.h>
jfehlig@33 24 #include <assert.h>
jfehlig@33 25
jfehlig@36 26 #include <xen_common.h>
jfehlig@36 27 #include <xen_vm.h>
jfehlig@3 28
jbulpin@0 29 #include "Xen_ComputerSystemSettingData_Resource.h"
jbulpin@0 30
jbulpin@0 31 /* Include the required CMPI data types, function headers, and macros. */
jbulpin@0 32 #include "cmpidt.h"
jbulpin@0 33 #include "cmpift.h"
jbulpin@0 34 #include "cmpimacs.h"
jbulpin@0 35
jfehlig@33 36 #include "xen_utils.h"
jfehlig@53 37 #include "provider_common.h"
jbulpin@0 38
jfehlig@93 39
jfehlig@93 40 static int get_platform_bool_val(_RESOURCE *resource, char *key)
jfehlig@93 41 {
jfehlig@93 42 int i;
jfehlig@93 43
jfehlig@93 44 xen_string_string_map *map = resource->platform;
jfehlig@93 45 for (i = 0; i < map->size; i++)
jfehlig@93 46 if (strcmp(map->contents[i].key, key) == 0)
jfehlig@93 47 if (strcmp(map->contents[i].val, "1") == 0)
jfehlig@93 48 return 1;
jfehlig@93 49
jfehlig@93 50 return 0;
jfehlig@93 51 }
jfehlig@93 52
jfehlig@94 53 static char *get_platform_string_val(_RESOURCE *resource, char *key)
jfehlig@94 54 {
jfehlig@94 55 int i;
jfehlig@94 56
jfehlig@94 57 xen_string_string_map *map = resource->platform;
jfehlig@94 58 for (i = 0; i < map->size; i++)
jfehlig@94 59 if (strcmp(map->contents[i].key, key) == 0)
jfehlig@94 60 return map->contents[i].val;
jfehlig@94 61
jfehlig@94 62 return NULL;
jfehlig@94 63 }
jfehlig@94 64
jfehlig@93 65
jbulpin@0 66 // ----------------------------------------------------------------------------
jbulpin@0 67
jbulpin@0 68 /* Get a handle to the list of all system resources for this class. */
jfehlig@47 69 int Xen_ComputerSystemSettingData_getResources(xen_utils_session *session,
jfehlig@47 70 _RESOURCES ** resources)
jbulpin@0 71 {
jfehlig@47 72 return xen_utils_get_domain_resources(session, resources);
jbulpin@0 73 }
jbulpin@0 74
jbulpin@0 75 // ----------------------------------------------------------------------------
jbulpin@0 76
jbulpin@0 77 /* Free/deallocate/cleanup the resources list after use. */
jfehlig@47 78 int Xen_ComputerSystemSettingData_freeResources(_RESOURCES * resources)
jbulpin@0 79 {
jfehlig@33 80 return xen_utils_free_domain_resources(resources);
jbulpin@0 81 }
jbulpin@0 82
jbulpin@0 83 // ----------------------------------------------------------------------------
jbulpin@0 84
jbulpin@0 85 /* Iterator to get the next resource from the resources list. */
jfehlig@47 86 int Xen_ComputerSystemSettingData_getNextResource(xen_utils_session *session,
jfehlig@47 87 _RESOURCES * resources,
jfehlig@47 88 _RESOURCE ** resource)
jbulpin@0 89 {
jfehlig@47 90 return xen_utils_get_next_domain_resource(session, resources, resource);
jbulpin@0 91 }
jbulpin@0 92
jbulpin@0 93 // ----------------------------------------------------------------------------
jbulpin@0 94
jbulpin@0 95 /* Get the specific resource that matches the CMPI object path. */
jfehlig@47 96 int Xen_ComputerSystemSettingData_getResourceForObjectPath(xen_utils_session *session,
jfehlig@47 97 _RESOURCES * resources,
jfehlig@47 98 _RESOURCE ** resource,
jfehlig@47 99 const CMPIObjectPath * objectpath)
jbulpin@0 100 {
jfehlig@53 101 char *instId;
jfehlig@53 102 char name[MAX_SYSTEM_NAME_LEN];
jbulpin@0 103 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jbulpin@0 104
jbulpin@0 105 /* Check input params are valid. */
jbulpin@0 106 if (resources == NULL) return 0;
jbulpin@0 107 if (CMIsNullObject(objectpath)) return 0;
jbulpin@0 108
jbulpin@0 109 /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
jbulpin@0 110 CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
jbulpin@0 111 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
jbulpin@0 112
jbulpin@0 113 /* Extract the id string from the CMPIString. */
jfehlig@53 114 instId = CMGetCharPtr(iddata.value.string);
jfehlig@53 115 if ((instId== NULL) || (*instId == '\0')) return 0;
jbulpin@0 116
jfehlig@53 117 /* Retrieve domain name from InstanceID. */
jfehlig@53 118 if (!_CMPIStrncpySystemNameFromID(name, instId, MAX_SYSTEM_NAME_LEN))
jfehlig@53 119 return 0;
jfehlig@53 120
jbulpin@0 121 /* Get all the resource data for the target resource. */
jfehlig@33 122 xen_vm_set *vms;
jfehlig@53 123 if (!xen_vm_get_by_name_label(session->xen, &vms, name)) {
jfehlig@33 124 /* Error is in session object! */
jfehlig@33 125 *resource = NULL;
jfehlig@33 126 return 0;
jfehlig@33 127 }
jfehlig@33 128
jfehlig@33 129 assert(vms->size == 1);
jfehlig@47 130 if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) {
jfehlig@33 131 /* Error description in session object! */
jfehlig@33 132 xen_vm_set_free(vms);
jfehlig@33 133 return 0;
jfehlig@33 134 }
jfehlig@33 135
jfehlig@33 136 xen_vm_set_free(vms);
jbulpin@0 137
jbulpin@0 138 return 1;
jbulpin@0 139 }
jbulpin@0 140
jbulpin@0 141 // ----------------------------------------------------------------------------
jbulpin@0 142
jbulpin@0 143 /* Free/deallocate/cleanup the resource after use. */
jfehlig@47 144 int Xen_ComputerSystemSettingData_freeResource(_RESOURCE * resource)
jbulpin@0 145 {
jfehlig@33 146 return xen_utils_free_domain_resource(resource);
jbulpin@0 147 }
jbulpin@0 148
jfehlig@93 149
jbulpin@0 150 // ----------------------------------------------------------------------------
jbulpin@0 151
jbulpin@0 152 /* Set the property values of a CMPI instance from a specific resource. */
jfehlig@47 153 int Xen_ComputerSystemSettingData_setInstanceFromResource(_RESOURCE * resource,
jfehlig@47 154 const CMPIInstance * instance,
jfehlig@47 155 const CMPIBroker * broker)
jbulpin@0 156 {
jfehlig@88 157 char inst_id[1024];
jfehlig@94 158 int prop_bool_val;
jfehlig@94 159 char *prop_string_val;
jfehlig@103 160 char *hvm_boot_order;
jbulpin@0 161 if (resource == NULL) return 0;
jbulpin@0 162 if (CMIsNullObject(instance)) return 0;
jbulpin@0 163
jbulpin@0 164 /* Set the CMPIInstance properties from the resource data. */
jfehlig@88 165 snprintf(inst_id, 1024, "Xen:%s", resource->name_label);
jfehlig@88 166 CMSetProperty(instance, "InstanceID",(CMPIValue *)inst_id, CMPI_chars);
jfehlig@99 167 // There must be an easier way of figuring out pv/hvm, but, until we figure that out, we will keep this - Raj
jfehlig@103 168 if ((hvm_boot_order = xen_utils_get_value_from_map(resource->hvm_boot_params, "order"))) {
jfehlig@88 169 /* HVM settings */
jfehlig@95 170 CMSetProperty(instance, "VirtualSystemType", (CMPIValue *)"hvm-3.0-unknown", CMPI_chars);
jfehlig@99 171 CMSetProperty(instance, "BootOrder", (CMPIValue *)hvm_boot_order, CMPI_chars);
jfehlig@94 172 prop_bool_val = get_platform_bool_val(resource, "stdvga");
jfehlig@94 173 CMSetProperty(instance, "stdvga", (CMPIValue *)&prop_bool_val, CMPI_boolean);
jfehlig@94 174
jfehlig@94 175 prop_bool_val = get_platform_bool_val(resource, "apic");
jfehlig@94 176 CMSetProperty(instance, "apic", (CMPIValue *)&prop_bool_val, CMPI_boolean);
jfehlig@94 177
jfehlig@94 178 prop_bool_val = get_platform_bool_val(resource, "acpi");
jfehlig@94 179 CMSetProperty(instance, "acpi", (CMPIValue *)&prop_bool_val, CMPI_boolean);
jfehlig@94 180
jfehlig@94 181 prop_bool_val = get_platform_bool_val(resource, "pae");
jfehlig@94 182 CMSetProperty(instance, "pae", (CMPIValue *)&prop_bool_val, CMPI_boolean);
jfehlig@94 183
jfehlig@94 184 prop_bool_val = get_platform_bool_val(resource, "usb");
jfehlig@94 185 CMSetProperty(instance, "usb", (CMPIValue *)&prop_bool_val, CMPI_boolean);
jfehlig@94 186
jfehlig@94 187 prop_string_val = get_platform_string_val(resource, "usbdevice");
jfehlig@94 188 if (prop_string_val != NULL)
jfehlig@94 189 CMSetProperty(instance, "usbdevice", (CMPIValue *)prop_string_val, CMPI_chars);
jfehlig@88 190 }
jfehlig@88 191 else {
jfehlig@88 192 /* PV settings */
jfehlig@95 193 CMSetProperty(instance, "VirtualSystemType", (CMPIValue *)"xen-3.0-unknown", CMPI_chars);
jfehlig@88 194
jfehlig@90 195 if (resource->pv_kernel && (resource->pv_kernel[0] != '\0'))
jfehlig@88 196 CMSetProperty(instance, "Kernel", (CMPIValue *)resource->pv_kernel, CMPI_chars);
jfehlig@90 197 if (resource->pv_ramdisk && (resource->pv_ramdisk[0] != '\0'))
jfehlig@88 198 CMSetProperty(instance, "RAMDisk", (CMPIValue *)resource->pv_ramdisk, CMPI_chars);
jfehlig@90 199 if (resource->pv_args && (resource->pv_args[0] != '\0'))
jfehlig@88 200 CMSetProperty(instance, "KernelOptions" , (CMPIValue *)resource->pv_args, CMPI_chars);
jfehlig@90 201 if (resource->pv_bootloader && (resource->pv_bootloader[0] != '\0'))
jfehlig@88 202 CMSetProperty(instance, "Bootloader", (CMPIValue *)resource->pv_bootloader, CMPI_chars);
jfehlig@90 203 if (resource->pv_bootloader_args && (resource->pv_bootloader_args[0] != '\0'))
jfehlig@88 204 CMSetProperty(instance, "BootloaderOptions", (CMPIValue *)resource->pv_bootloader_args, CMPI_chars);
jfehlig@88 205 }
jfehlig@88 206
jfehlig@88 207 /* Common settings */
jfehlig@33 208 CMSetProperty(instance, "ElementName",(CMPIValue *)resource->name_label, CMPI_chars);
jfehlig@49 209 CMSetProperty(instance, "VirtualSystemIdentifier",(CMPIValue *)resource->name_label, CMPI_chars);
jfehlig@49 210
jfehlig@90 211 if (resource->uuid && (resource->uuid[0] != '\0'))
jfehlig@49 212 CMSetProperty(instance, "UUID", (CMPIValue *)resource->uuid, CMPI_chars);
jbulpin@0 213
jfehlig@94 214 prop_bool_val = get_platform_bool_val(resource, "localtime");
jfehlig@94 215 CMSetProperty(instance, "localtime", (CMPIValue *)&prop_bool_val, CMPI_boolean);
jfehlig@88 216
jfehlig@88 217 CMSetProperty(instance, "OnPoweroff", (CMPIValue *)&(resource->actions_after_shutdown), CMPI_uint16);
jfehlig@88 218 CMSetProperty(instance, "OnReboot", (CMPIValue *)&(resource->actions_after_reboot), CMPI_uint16);
jfehlig@88 219 CMSetProperty(instance, "OnCrash", (CMPIValue *)&(resource->actions_after_crash), CMPI_uint16);
jbulpin@0 220
jbulpin@0 221 return 1;
jbulpin@0 222 }
jbulpin@0 223
jbulpin@0 224 // ----------------------------------------------------------------------------
jbulpin@0 225
jbulpin@0 226 /* Delete the specified resource from the system. */
jfehlig@47 227 int Xen_ComputerSystemSettingData_deleteResource(_RESOURCES * resources,
jfehlig@47 228 _RESOURCE * resource)
jbulpin@0 229 {
jbulpin@0 230 /* Unsupported. */
jbulpin@0 231 return -1;
jbulpin@0 232 }
jbulpin@0 233
jbulpin@0 234 // ----------------------------------------------------------------------------
jbulpin@0 235
jbulpin@0 236 /* Modify the specified resource using the property values of a CMPI instance. */
jfehlig@47 237 int Xen_ComputerSystemSettingData_setResourceFromInstance(_RESOURCE * resource,
jfehlig@47 238 const CMPIInstance * instance,
jfehlig@47 239 const CMPIBroker * broker)
jbulpin@0 240 {
jbulpin@0 241 /* Unsupported. */
jbulpin@0 242 return -1;
jbulpin@0 243 }
jbulpin@0 244
jbulpin@0 245 // ----------------------------------------------------------------------------
jbulpin@0 246
jbulpin@0 247 /* Create a new resource using the property values of a CMPI instance. */
jfehlig@47 248 int Xen_ComputerSystemSettingData_createResourceFromInstance(_RESOURCES * resources,
jfehlig@47 249 _RESOURCE ** resource,
jfehlig@47 250 const CMPIInstance * instance,
jfehlig@47 251 const CMPIBroker * broker)
jbulpin@0 252 {
jbulpin@0 253 /* Unsupported. */
jbulpin@0 254 return -1;
jbulpin@0 255 }
jbulpin@0 256