# HG changeset patch # User root@Musashi.Miyamoto # Date 1186664468 14400 # Node ID 64f8371acb35c37fbdad71d9d69669cea5b0c74b # Parent 3ccb96bfe2066d9c8d7f30bca3b4ce70c1194d23 This patch moves the XenNetworkPort and XenNetworkportSettingData providers to the new CMPIlify provider model. Signed-off-by: Raj Subrahmanian diff -r 3ccb96bfe206 -r 64f8371acb35 src/Makefile.am --- a/src/Makefile.am Thu Aug 02 17:54:59 2007 -0600 +++ b/src/Makefile.am Thu Aug 09 09:01:08 2007 -0400 @@ -48,9 +48,7 @@ noinst_HEADERS = \ xen_utils.h \ Xen_ComputerSystem_Resource.h \ Xen_VirtualSystemManagementService_Resource.h \ - Xen_NetworkPort_Resource.h \ Xen_VirtualizationCapabilities_Resource.h \ - Xen_NetworkPortSettingData_Resource.h \ Xen_ProcessorCapabilitiesSettingData_Resource.h \ Xen_MemoryCapabilitiesSettingData_Resource.h @@ -185,7 +183,7 @@ libXen_ComputerSystemDisk_la_LIBADD = li libXen_ComputerSystemDisk_la_LIBADD = libXen_ProviderCommon.la libXen_ComputerSystemDisk_la_LDFLAGS = -module -avoid-version -no-undefined -libXen_NetworkPort_la_SOURCES = Xen_NetworkPort.c Xen_NetworkPort_Resource.c +libXen_NetworkPort_la_SOURCES = Xen_NetworkPort.c libXen_NetworkPort_la_CFLAGS = -I../ @LIBXEN_CFLAGS@ libXen_NetworkPort_la_LIBADD = libXen_ProviderCommon.la libXen_NetworkPort_la_LDFLAGS = -module -avoid-version -no-undefined @@ -260,7 +258,7 @@ libXen_MemoryElementSettingData_la_LIBAD libXen_MemoryElementSettingData_la_LIBADD = libXen_ProviderCommon.la libXen_MemoryElementSettingData_la_LDFLAGS = -module -avoid-version -no-undefined -libXen_NetworkPortSettingData_la_SOURCES = Xen_NetworkPortSettingData.c Xen_NetworkPortSettingData_Resource.c +libXen_NetworkPortSettingData_la_SOURCES = Xen_NetworkPortSettingData.c libXen_NetworkPortSettingData_la_CFLAGS = -I../ @LIBXEN_CFLAGS@ libXen_NetworkPortSettingData_la_LIBADD = libXen_ProviderCommon.la libXen_NetworkPortSettingData_la_LDFLAGS = -module -avoid-version -no-undefined diff -r 3ccb96bfe206 -r 64f8371acb35 src/Xen_DiskSettingData.c --- a/src/Xen_DiskSettingData.c Thu Aug 02 17:54:59 2007 -0600 +++ b/src/Xen_DiskSettingData.c Thu Aug 09 09:01:08 2007 -0400 @@ -105,7 +105,7 @@ static CMPIrc begin(void **res_list, con { vbd_resources *disk_resources; xen_domain_resources *domain_resources = NULL; - xen_vbd_set *all_disks = NULL; + xen_vif_set *all_disks = NULL; xen_vm_record *vm_rec = NULL; (void)properties; @@ -213,6 +213,7 @@ static CMPIrc getnext(void *res_list, vo } + static CMPIrc get(const void *res_id, void **res, const char **properties) { CMPIInstance *inst = (CMPIInstance *)res_id; @@ -264,6 +265,7 @@ static CMPIrc get(const void *res_id, vo *res = (void *)disk_resource; return CMPI_RC_OK; } + static void release(void *res) diff -r 3ccb96bfe206 -r 64f8371acb35 src/Xen_NetworkPort.c --- a/src/Xen_NetworkPort.c Thu Aug 02 17:54:59 2007 -0600 +++ b/src/Xen_NetworkPort.c Thu Aug 09 09:01:08 2007 -0400 @@ -17,607 +17,413 @@ // Authors: Dr. Gareth S. Bestor, // Tokunbo Adeshiyan, // Contributors: Jim Fehlig, +// Raj Subrahmanian, // Description: // ============================================================================ /* Include the required CMPI data types, function headers, and macros */ #include "cmpidt.h" -#include "cmpift.h" #include "cmpimacs.h" - -/* Include utility functions */ -#include "cmpiutil.h" - -/* Include _SBLIM_TRACE() logging support */ #include "cmpitrace.h" +#include "provider_common.h" +#include "cmpilify.h" /* Include Xen utilities */ -#include "xen_utils.h" - -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */ -#include "Xen_NetworkPort_Resource.h" - - -// ---------------------------------------------------------------------------- -// COMMON GLOBAL VARIABLES -// ---------------------------------------------------------------------------- - -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */ -static const CMPIBroker *_BROKER; +#include +#include +#include +#include +#include +#include +#include + + +static const CMPIInstanceMI* mi; + +#define _BROKER (((CMPILIFYInstanceMI*)(mi->hdl))->brkr) +#define _CLASS (((CMPILIFYInstanceMI*)(mi->hdl))->cn) +#define _KEYS (((CMPILIFYInstanceMI*)(mi->hdl))->kys) /* Xen session object. Initialize when the provider is loaded, close when * provider unloaded. */ static xen_utils_session *session = NULL; - - -// ============================================================================ -// CMPI INSTANCE PROVIDER FUNCTION TABLE -// ============================================================================ - -// ---------------------------------------------------------------------------- -// Info for the class supported by the instance provider -// ---------------------------------------------------------------------------- - -/* Name of the class implemented by this instance provider. */ /*** CUSTOMIZE FOR EACH PROVIDER ***/ +/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES. + THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS + LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC. + THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN + ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ +typedef struct { + xen_vif_set *vifs; + unsigned int currentvifnum; +} vif_resource_list; + static char * _CLASSNAME = "Xen_NetworkPort"; -/* NULL terminated list of key properties of this class. */ -/*** CUSTOMIZE FOR EACH PROVIDER ***/ -const static char * _KEYNAMES[] = {"SystemName", "SystemCreationClassName", "DeviceID", "CreationClassName", NULL}; - -// ---------------------------------------------------------------------------- -// Cleanup() -// Perform any necessary cleanup immediately before this provider is unloaded. -// ---------------------------------------------------------------------------- -static CMPIStatus Cleanup( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - CMPIBoolean terminating) /* [in] True if MB is terminating */ -{ - CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ - - _SBLIM_ENTER("Cleanup"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - +const static char * keys[] = {"SystemName", "SystemCreationClassName", "DeviceID", "CreationClassName", NULL}; + + +static CMPIrc load() +{ + /* Initialized Xen session object. */ + if (!session) + xen_utils_xen_init(&session); + return CMPI_RC_OK; +} + + +static CMPIrc unload(const int terminating) +{ + (void)terminating; + /* Close Xen session object. */ if (session) { xen_utils_xen_close(session); session = NULL; } - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// EnumInstanceNames() -// Return a list of all the instances names (return their object paths only). -// ---------------------------------------------------------------------------- -static CMPIStatus EnumInstanceNames( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to each system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found any instances? */ - - _SBLIM_ENTER("EnumInstanceNames"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - + return CMPI_RC_OK; +} + + +static CMPIrc begin(void **res_list, const char **properties) +{ + vif_resource_list *vif_resources; + xen_domain_resources *domain_resources = NULL; + xen_vif_set *all_vifs = NULL; + xen_vm_record *vm_rec = NULL; + + (void)properties; + + if (res_list == NULL) + return CMPI_RC_ERR_FAILED; + if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPort_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ - while (Xen_NetworkPort_getNextResource(session, resources, &resource)) { - /* Create a new CMPIInstance to store this resource. */ - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); - goto exit; + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- Unable to establish connection with Xend")); + return CMPI_RC_ERR_FAILED; + } + + vif_resources = (vif_resource_list *)calloc(1, sizeof(vif_resource_list)); + if (vif_resources == NULL) + return CMPI_RC_ERR_FAILED; + + /* Get a list of domain resources. */ + if (!xen_utils_get_domain_resources(session, &domain_resources)) + goto Error; + + /* Create list of network port resources from network ports found in each domain. */ + while (xen_utils_get_next_domain_resource(session, domain_resources, &vm_rec)) { + /* Ignore halted vms */ + if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) { + xen_vm_record_free(vm_rec); + continue; } - /* Set the instance property values from the resource data. */ - if (!Xen_NetworkPort_setInstanceFromResource(session, resource, instance, _BROKER)) { - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); - goto exit; + xen_vif_set *vif_set; + if (!xen_vm_get_vifs(session->xen, &vif_set, vm_rec->handle)) + goto Error; + + if (!xen_vif_set_concat(&all_vifs, vif_set)) + goto Error; + + xen_vm_record_free(vm_rec); + } + + xen_utils_free_domain_resources(domain_resources); + + vif_resources->vifs = all_vifs; + vif_resources->currentvifnum = 0; + + *res_list = (void *)vif_resources; + return CMPI_RC_OK; + + Error: + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- failed to retrieve vbd resources from Xend:")); + if (session && session->xen) + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + + xen_vif_set_free(all_vifs); + xen_vm_record_free(vm_rec); + xen_utils_free_domain_resources(domain_resources); + free(vif_resources); + return CMPI_RC_ERR_FAILED; +} + +static void end(void *res_list) +{ + vif_resource_list *vif_resources = (vif_resource_list *)res_list; + + if (vif_resources) { + if (vif_resources->vifs) + xen_vif_set_free(vif_resources->vifs); + free(vif_resources); + } +} + +static CMPIrc getnext(void *res_list, void **res, const char **properties) +{ + vif_resource_list *vif_resources = (vif_resource_list *)res_list; + xen_vif_record *vif_rec; + + (void)properties; + + if (vif_resources == NULL || res == NULL) + return CMPI_RC_ERR_FAILED; + + /* Are there any vifs or has end of list of vifs been reached? */ + if (vif_resources->vifs == NULL || + vif_resources->currentvifnum == vif_resources->vifs->size) + return CMPI_RC_ERR_NOT_FOUND; + + /* Get the current vif record. */ + session->xen->ok = true; + if (!xen_vif_get_record(session->xen, &vif_rec, + vif_resources->vifs->contents[vif_resources->currentvifnum])) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- failed to retrieve vbd resources from Xend:")); + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + return CMPI_RC_ERR_FAILED; + } + + vif_resources->currentvifnum++; + *res = (void *)vif_rec; + return CMPI_RC_OK; +} + + +static CMPIrc get(const void *res_id, void **res, const char **properties) +{ + CMPIInstance *inst = (CMPIInstance *)res_id; + CMPIData data; + CMPIStatus status = {CMPI_RC_OK, NULL}; + char *dev_uuid; + + (void)properties; + + if (CMIsNullObject(inst) || res == NULL) + return CMPI_RC_ERR_FAILED; + + data = CMGetProperty(inst, "DeviceID", &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) + return CMPI_RC_ERR_FAILED; + + /* Extract the domain name string from the CMPIString. */ + dev_uuid = CMGetCharPtr(data.value.string); + if ((dev_uuid == NULL) || (*dev_uuid == '\0')) + return CMPI_RC_ERR_FAILED; + + if (!xen_utils_validate_session(&session)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- Unable to establish connection with Xend")); + return CMPI_RC_ERR_FAILED; + } + + xen_vif_record *vif_rec; + if (!xen_vif_get_record(session->xen, &vif_rec, (xen_vif)dev_uuid)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- xen_vbd_get_record failed:")); + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + return CMPI_RC_ERR_FAILED; + } + + enum xen_vm_power_state pstate; + if (!xen_vm_get_power_state(session->xen, &pstate, vif_rec->vm->u.handle)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- xen_vm_get_power_state failed:")); + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + xen_vif_record_free(vif_rec); + + return CMPI_RC_ERR_FAILED; + } + + if (pstate == XEN_VM_POWER_STATE_HALTED) { + xen_vif_record_free(vif_rec); + return CMPI_RC_ERR_NOT_FOUND; + } + + *res = (void *)vif_rec; + return CMPI_RC_OK; +} + + +static void release(void *res) +{ + xen_vif_record_free((xen_vif_record *)res); +} + + +static CMPIrc add(const void *res_id, const void *res) +{ + (void)res_id; + (void)res; + + return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported*/ +} + + +static CMPIrc delete(const void *res_id) +{ + CMPIInstance *inst = (CMPIInstance *)res_id; + CMPIData data; + CMPIStatus status = {CMPI_RC_OK, NULL}; + char *dev_uuid; + + if (CMIsNullObject(inst)) + return CMPI_RC_ERR_FAILED; + + data = CMGetProperty(inst, "DeviceID", &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) + return CMPI_RC_ERR_FAILED; + + /* Extract the domain name string from the CMPIString. */ + dev_uuid = CMGetCharPtr(data.value.string); + if ((dev_uuid == NULL) || (*dev_uuid == '\0')) + return CMPI_RC_ERR_FAILED; + + if (!xen_utils_validate_session(&session)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- Unable to establish connection with Xend")); + return CMPI_RC_ERR_FAILED; + } + + if (!xen_vbd_destroy(session->xen, (xen_vbd)dev_uuid)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- xen_vbd_destroy failed:")); + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + return CMPI_RC_ERR_FAILED; + } + + return CMPI_RC_OK; +} + + +static CMPIrc modify(const void *res_id, const void *modified_res, + const char **properties) +{ + (void)res_id; + (void)modified_res; + (void)properties; + + return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */ +} + +/* Set CMPIInstance properties from the resource data. */ +static CMPIrc setproperties(CMPIInstance *inst, const void *res, + const char **properties) +{ + xen_vm_record *alloced_vm_rec = NULL; + xen_vm_record *vm_rec; + xen_vif_record *vif_rec = (xen_vif_record *)res; + char buf[MAX_INSTANCEID_LEN]; + + + if (vif_rec == NULL || CMIsNullObject(inst)) + return CMPI_RC_ERR_FAILED; + + session->xen->ok = true; + + xen_vm_record_opt *vm_rec_opt = vif_rec->vm; + if (vm_rec_opt->is_record) { + vm_rec = vm_rec_opt->u.record; + } + else { + if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- xen_vm_get_record failed:")); + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + return CMPI_RC_ERR_FAILED; } - - /* Free the resource data. */ - if (!Xen_NetworkPort_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - /* Return the CMPIObjectPath for this instance. */ - CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { - _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance"); - goto exit; - } - CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */ - - _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL)))); - CMReturnObjectPath(results, objectpath); - found++; - } - - _SBLIM_TRACE(2,("--- %d object paths found", found)); - CMReturnDone(results); - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPort_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// EnumInstances() -// Return a list of all the instances (return all the instance data). -// ---------------------------------------------------------------------------- -static CMPIStatus EnumInstances( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */ - const char ** properties) /* [in] List of desired properties (NULL=all). */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to each system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found any resource instances? */ - - _SBLIM_ENTER("EnumInstances"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPort_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ - while (Xen_NetworkPort_getNextResource(session, resources, &resource)) { - /* Create a new CMPIInstance to store this resource. */ - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); - goto exit; - } - - /* Setup a filter to only return the desired properties. */ - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); - if (status.rc != CMPI_RC_OK) { - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); - goto exit; - } - - /* Set the instance property values from the resource data. */ - if (!Xen_NetworkPort_setInstanceFromResource(session, resource, instance, _BROKER)) { - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); - goto exit; - } - - /* Free the resource data. */ - if (!Xen_NetworkPort_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - /* Return the CMPIInstance for this instance. */ - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); - CMReturnInstance(results, instance); - found++; - } - - _SBLIM_TRACE(2,("--- %d instances found", found)); - CMReturnDone(results); - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPort_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// GetInstance() -// Return the instance data for the specified instance only. -// ---------------------------------------------------------------------------- -static CMPIStatus GetInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ - const char ** properties) /* [in] List of desired properties (NULL=all). */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to the system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found the target instance? */ - - _SBLIM_ENTER("GetInstance"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPort_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Get the target resource. */ - found = Xen_NetworkPort_getResourceForObjectPath(session, &resource, reference); - if (!found || (resource == NULL)) { - _SBLIM_TRACE(1,("--- Target instance not found")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); - goto exit; - } - - /* Create a new CMPIInstance to store this resource. */ - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); - goto exit; + alloced_vm_rec = vm_rec; } /* Setup a filter to only return the desired properties. */ - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); - if (status.rc != CMPI_RC_OK) { - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); - goto exit; - } - - /* Set the instance property values from the resource data. */ - if (!Xen_NetworkPort_setInstanceFromResource(session, resource, instance, _BROKER)) { - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); - goto exit; - } - - /* Free the resource data. */ - if (!Xen_NetworkPort_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - /* Return the CMPIInstance for this instance. */ - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); - CMReturnInstance(results, instance); - - _SBLIM_TRACE(2,("--- instance found")); - CMReturnDone(results); - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPort_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// SetInstance() -// Save modified instance data for the specified instance. -// ---------------------------------------------------------------------------- -static CMPIStatus SetInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ - const CMPIInstance * newinstance, /* [in] Contains the new instance data. */ - const char **properties) -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to the system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found the target instance? */ - - _SBLIM_ENTER("SetInstance"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPort_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Get the target resource. */ - found = Xen_NetworkPort_getResourceForObjectPath(session, &resource, reference); - if (!found || (resource == NULL)) { - _SBLIM_TRACE(1,("--- Target instance not found")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); - goto exit; - } - - _SBLIM_TRACE(2,("--- instance found", found)); - - /* Update the target resource data with the new instance property values. */ - int rc = Xen_NetworkPort_setResourceFromInstance(resource, newinstance, _BROKER); - - /* Free the resource data. */ - if (!Xen_NetworkPort_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - if (rc != 1) { - if (rc == -1) { - _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); - } else { - _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties"); - } - goto exit; - } - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPort_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// CreateInstance() -// Create a new instance from the specified instance data. -// ---------------------------------------------------------------------------- -static CMPIStatus CreateInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ - const CMPIInstance * newinstance) /* [in] Contains the new instance data. */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to the system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found the target instance? */ - - _SBLIM_ENTER("CreateInstance"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */ - reference = CMGetObjectPath(newinstance, NULL); - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPort_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Get the target resource. */ - found = Xen_NetworkPort_getResourceForObjectPath(session, &resource, reference); - - /* Free the resource data. */ - if (!Xen_NetworkPort_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - if (found) { - _SBLIM_TRACE(1,("--- Target instance already exists")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists"); - goto exit; - } - - /* Create a new resource with the new instance property values. */ - int rc = Xen_NetworkPort_createResourceFromInstance(resources, &resource, newinstance, _BROKER); - if (rc != 1) { - if (rc == -1) { - _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); - } else { - _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties"); - } - goto exit; - } - - /* Return the object path for the newly created instance. */ - CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL); - CMSetNameSpace(objectpath, namespace); - CMReturnObjectPath(results, objectpath); - CMReturnDone(results); - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPort_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// DeleteInstance() -// Delete or remove the specified instance from the system. -// ---------------------------------------------------------------------------- -static CMPIStatus DeleteInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCE * resource = NULL; /* Handle to the system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found the target instance? */ - char error_msg[XEN_UTILS_ERROR_BUF_LEN]; - - _SBLIM_ENTER("DeleteInstance"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get the target resource. */ - found = Xen_NetworkPort_getResourceForObjectPath(session, &resource, reference); - if (!found || (resource == NULL)) { - _SBLIM_TRACE(1,("--- Target instance not found")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); - goto exit; - } - - _SBLIM_TRACE(2,("--- instance found", found)); - - /* Delete the target resource. */ - if (!Xen_NetworkPort_deleteResource(session, resource)) { - XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); - _SBLIM_TRACE(1,("--- deleteResource failed: %s", error_msg)); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg); - goto exit; - } - -exit: - /* Free the resource. */ - if (resource) - Xen_NetworkPort_freeResource(resource); - - _SBLIM_RETURNSTATUS(status); -} - - -// ---------------------------------------------------------------------------- -// ExecQuery() -// Return a list of all the instances that satisfy the specified query filter. -// ---------------------------------------------------------------------------- -static CMPIStatus ExecQuery( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ - const char * language, /* [in] Name of the query language. */ - const char * query) /* [in] Text of the query written in the query language. */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - - _SBLIM_ENTER("ExecQuery"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- language=\"%s\"", language)); - _SBLIM_TRACE(2, ("--- query=\"%s\"", query)); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */ - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); - - CMReturnDone(results); - -exit: - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// Initialize() -// Perform any necessary initialization immediately after this provider is -// first loaded. -// ---------------------------------------------------------------------------- -static void Initialize( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context) /* [in] Additional context info, if any. */ -{ - _SBLIM_ENTER("Initialize"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - - /* Initialized Xen session object. */ - if (session == NULL) - xen_utils_xen_init(&session); - - _SBLIM_RETURN(); -} - -// ============================================================================ -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP -// ============================================================================ -CMInstanceMIStub( , Xen_NetworkPort, _BROKER, Initialize(&mi, ctx)); + CMSetPropertyFilter(inst, properties, keys); + + /* Set the CMPIInstance properties from the resource data. */ + CMSetProperty(inst, "SystemCreationClassName",(CMPIValue *)"Xen_ComputerSystem", CMPI_chars); + CMSetProperty(inst, "SystemName",(CMPIValue *)vm_rec->name_label, CMPI_chars); + CMSetProperty(inst, "CreationClassName",(CMPIValue *)"Xen_NetworkPort", CMPI_chars); + + CMSetProperty(inst, "DeviceID",(CMPIValue *)vif_rec->uuid, CMPI_chars); + + CMSetProperty(inst, "Caption",(CMPIValue *)"Network Port", CMPI_chars); + CMSetProperty(inst, "Description",(CMPIValue *)"Network Port", CMPI_chars); + + //CMSetProperty(inst, "NICConfigInfo",(CMPIValue *)resource->vif[vifnum].params, CMPI_chars); + + int link_tech = 2; /* 2 == Ethernet */ + CMSetProperty(inst, "LinkTechnology",(CMPIValue *)&link_tech, CMPI_uint16); + + if (vif_rec->device) { + CMSetProperty(inst, "Name",(CMPIValue *)vif_rec->device, CMPI_chars); + CMSetProperty(inst, "VIFName",(CMPIValue *)vif_rec->device, CMPI_chars); + } + + if (vif_rec->mac) + CMSetProperty(inst, "PermanentAddress",(CMPIValue *)vif_rec->mac, CMPI_chars); + if (vif_rec->mtu > 0) { + CMSetProperty(inst, "SupportedMaximumTransmissionUnit",(CMPIValue *)&(vif_rec->mtu), CMPI_uint64); + CMSetProperty(inst, "ActiveMaximumTransmissionUnit",(CMPIValue *)&(vif_rec->mtu), CMPI_uint64); + } + + char nic_config_info[512]; + nic_config_info[0] = '\0'; + if (vif_rec->mac) + snprintf(nic_config_info, 512, "mac=%s", vif_rec->mac); + /*if (resource->model) { + strncat(nic_config_info, ",model=", 512 - strlen(nic_config_info)); + strncat(nic_config_info, resource->model, 512 - strlen(nic_config_info)); + } NIC config info does not have model*/ + if (nic_config_info[0] != '\0') + CMSetProperty(inst, "NICConfigInfo" , (CMPIValue *)nic_config_info, CMPI_chars); + + if (vm_rec->power_state != XEN_VM_POWER_STATE_HALTED) { + CMSetProperty(inst, "Status", (CMPIValue *)"OK", CMPI_chars); + } else { + CMSetProperty(inst, "Status", (CMPIValue *)"No Contact", CMPI_chars); + } + + if (alloced_vm_rec) + xen_vm_record_free(alloced_vm_rec); +} + + +/* + * Set resource data from the CMPIInstance properties. Only needs to + * be implemented if add() and/or modify() are supported. + */ +static CMPIrc extract(void **res, const CMPIInstance *inst, + const char **properties) +{ + (void)res; + (void)inst; + (void)properties; + + return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */ +} + + +/* Get resource id from CMPIInstance properties. */ +static CMPIrc extractid(void **res_id, const CMPIInstance* inst) +{ + *res_id = (void *)inst; + return CMPI_RC_OK; +} + + +/* Release resource id created in resId4inst(). */ +static void releaseid(void* res_id) +{ + (void)res_id; +} + + +/* Setup CMPILIFY function tables and instance provider entry point.*/ +/* CMPILIFYInstanceMIStub(,,,) */ +CMPILIFYInstanceMIStub(Xen_NetworkPort, Xen_NetworkPort, keys, mi) \ No newline at end of file diff -r 3ccb96bfe206 -r 64f8371acb35 src/Xen_NetworkPortSettingData.c --- a/src/Xen_NetworkPortSettingData.c Thu Aug 02 17:54:59 2007 -0600 +++ b/src/Xen_NetworkPortSettingData.c Thu Aug 09 09:01:08 2007 -0400 @@ -16,607 +16,424 @@ // ============================================================================ // Authors: Dr. Gareth S. Bestor, // Contributors: Jim Fehlig, +// Contributors: Raj Subrahmanian // Description: // ============================================================================ -/* Include the required CMPI data types, function headers, and macros */ -#include "cmpidt.h" -#include "cmpift.h" -#include "cmpimacs.h" - + +/* Common declarations for each CMPI "cmpilify" instance provider */ +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#include +#include + +#include "cmpilify.h" + + +static const CMPIInstanceMI* mi; + +#define _BROKER (((CMPILIFYInstanceMI*)(mi->hdl))->brkr) +#define _CLASS (((CMPILIFYInstanceMI*)(mi->hdl))->cn) +#define _KEYS (((CMPILIFYInstanceMI*)(mi->hdl))->kys) + +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /* Include utility functions */ #include "cmpiutil.h" - /* Include _SBLIM_TRACE() logging support */ #include "cmpitrace.h" - /* Include Xen utilities */ #include "xen_utils.h" -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */ -#include "Xen_NetworkPortSettingData_Resource.h" - - -// ---------------------------------------------------------------------------- -// COMMON GLOBAL VARIABLES -// ---------------------------------------------------------------------------- - -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */ -static const CMPIBroker *_BROKER; + +#include + +#include +#include +#include +#include +#include "provider_common.h" + + +/* C struct to store the data for a single resource. */ +typedef struct { + int is_vif_record; + union + { + xen_vif_record *vif_rec; + CMPIInstance *cmpi_inst; + } u; +} vif_resource; + +/* C struct to store the data for all resources. */ +typedef struct { + xen_vif_set *vifs; + unsigned int currentvifnum; +} vif_resource_list; + +/* Class keys */ +static const char *keys[] = {"InstanceID", NULL}; /* Xen session object. Initialize when the provider is loaded, close when * provider unloaded. */ static xen_utils_session *session = NULL; - -// ============================================================================ -// CMPI INSTANCE PROVIDER FUNCTION TABLE -// ============================================================================ - -// ---------------------------------------------------------------------------- -// Info for the class supported by the instance provider -// ---------------------------------------------------------------------------- - -/* Name of the class implemented by this instance provider. */ -/*** CUSTOMIZE FOR EACH PROVIDER ***/ -static char * _CLASSNAME = "Xen_NetworkPortSettingData"; - -/* NULL terminated list of key properties of this class. */ -/*** CUSTOMIZE FOR EACH PROVIDER ***/ -const static char * _KEYNAMES[] = {"InstanceID", NULL}; - -// ---------------------------------------------------------------------------- -// Cleanup() -// Perform any necessary cleanup immediately before this provider is unloaded. -// ---------------------------------------------------------------------------- -static CMPIStatus Cleanup( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - CMPIBoolean terminating) /* [in] True if MB is terminating */ -{ - CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ - - _SBLIM_ENTER("Cleanup"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - +static CMPIrc load() +{ + /* Initialized Xen session object. */ + if (!session) + xen_utils_xen_init(&session); + return CMPI_RC_OK; +} + +static CMPIrc unload(const int terminating) +{ + (void)terminating; + /* Close Xen session object. */ if (session) { xen_utils_xen_close(session); session = NULL; } - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// EnumInstanceNames() -// Return a list of all the instances names (return their object paths only). -// ---------------------------------------------------------------------------- -static CMPIStatus EnumInstanceNames( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to each system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found any instances? */ - - _SBLIM_ENTER("EnumInstanceNames"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - + return CMPI_RC_OK; +} + + +static CMPIrc begin(void **res_list, const char **properties) +{ + vif_resource_list *vif_resources; + xen_domain_resources *domain_resources = NULL; + xen_vif_set *all_vifs = NULL; + xen_vm_record *vm_rec = NULL; + + (void)properties; + + if (res_list == NULL) + return CMPI_RC_ERR_FAILED; + if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPortSettingData_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ - while (Xen_NetworkPortSettingData_getNextResource(session, resources, &resource)) { - /* Create a new CMPIInstance to store this resource. */ - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); - goto exit; - } - - /* Set the instance property values from the resource data. */ - if (!Xen_NetworkPortSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) { - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); - goto exit; - } - - /* Free the resource data. */ - if (!Xen_NetworkPortSettingData_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - /* Return the CMPIObjectPath for this instance. */ - CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { - _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance"); - goto exit; - } - CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */ - - _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL)))); - CMReturnObjectPath(results, objectpath); - found++; - } - - _SBLIM_TRACE(2,("--- %d object paths found", found)); - CMReturnDone(results); - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPortSettingData_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// EnumInstances() -// Return a list of all the instances (return all the instance data). -// ---------------------------------------------------------------------------- -static CMPIStatus EnumInstances( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */ - const char ** properties) /* [in] List of desired properties (NULL=all). */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to each system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found any resource instances? */ - - _SBLIM_ENTER("EnumInstances"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- Unable to establish connection with Xend")); + return CMPI_RC_ERR_FAILED; + } + + vif_resources = (vif_resource_list *)calloc(1, sizeof(vif_resource_list)); + if (vif_resources == NULL) + return CMPI_RC_ERR_FAILED; + + /* Get a list of domain resources. */ + if (!xen_utils_get_domain_resources(session, &domain_resources)) + goto Error; + + /* Create list of vif resources from vifs found in each domain. */ + while (xen_utils_get_next_domain_resource(session, domain_resources, &vm_rec)) { + xen_vif_set *vif_set; + if (!xen_vm_get_vifs(session->xen, &vif_set, vm_rec->handle)) + goto Error; + + if (!xen_vif_set_concat(&all_vifs, vif_set)) + goto Error; + + xen_vm_record_free(vm_rec); + } + + xen_utils_free_domain_resources(domain_resources); + + vif_resources->vifs = all_vifs; + vif_resources->currentvifnum = 0; + + *res_list = (void *)vif_resources; + return CMPI_RC_OK; + + Error: + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- failed to retrieve vbd resources from Xend:")); + if (session && session->xen) + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + + xen_vif_set_free(all_vifs); + xen_vm_record_free(vm_rec); + xen_utils_free_domain_resources(domain_resources); + free(vif_resources); + return CMPI_RC_ERR_FAILED; +} + +static void end(void *res_list) +{ + vif_resource_list *vif_resources = (vif_resource_list *)res_list; + + if (vif_resources) { + if (vif_resources->vifs) + xen_vif_set_free(vif_resources->vifs); + free(vif_resources); + } +} + +static CMPIrc getnext(void *res_list, void **res, const char **properties) +{ + vif_resource_list *vif_resources = (vif_resource_list *)res_list; + vif_resource *vif; + + (void)properties; + + if (vif_resources == NULL || res == NULL) + return CMPI_RC_ERR_FAILED; + + /* Are there any vifs or has end of list of vifs been reached? */ + if (vif_resources->vifs == NULL || + vif_resources->currentvifnum == vif_resources->vifs->size) + return CMPI_RC_ERR_NOT_FOUND; + + /* Get memory for resource. */ + vif = (vif_resource *)calloc(1, sizeof(vif_resource)); + if (vif == NULL) + return CMPI_RC_ERR_FAILED; + + vif->is_vif_record = 1; + + /* Get the current vif record. */ + session->xen->ok = true; + if (!xen_vif_get_record(session->xen, &(vif->u.vif_rec), + vif_resources->vifs->contents[vif_resources->currentvifnum])) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- failed to retrieve vbd resources from Xend:")); + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + return CMPI_RC_ERR_FAILED; + } + + vif_resources->currentvifnum++; + *res = (void *)vif; + return CMPI_RC_OK; +} + +static CMPIrc delete(const void *res_id) +{ + CMPIInstance *inst = (CMPIInstance *)res_id; + CMPIData data; + CMPIStatus status = {CMPI_RC_OK, NULL}; + char *inst_id; + char uuid[MAX_SYSTEM_NAME_LEN]; + + if (CMIsNullObject(inst)) + return CMPI_RC_ERR_FAILED; + + data = CMGetProperty(inst, "InstanceID", &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) + return CMPI_RC_ERR_FAILED; + + inst_id = CMGetCharPtr(data.value.string); + if ((inst_id == NULL) || (*inst_id == '\0')) + return CMPI_RC_ERR_FAILED; + + /* Extract the disk uuid from InstanceID property. */ + if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN)) + return CMPI_RC_ERR_FAILED; + + if (!xen_utils_validate_session(&session)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- Unable to establish connection with Xend")); + return CMPI_RC_ERR_FAILED; + } + + if (!xen_vbd_destroy(session->xen, (xen_vif)uuid)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- xen_vbd_destroy failed:")); + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + return CMPI_RC_ERR_FAILED; + } + + return CMPI_RC_OK; +} + +static CMPIrc get(const void *res_id, void **res, const char **properties) +{ + CMPIInstance *inst = (CMPIInstance *)res_id; + CMPIData data; + CMPIStatus status = {CMPI_RC_OK, NULL}; + char *inst_id; + char uuid[MAX_SYSTEM_NAME_LEN]; + vif_resource *vif; + + (void)properties; + + if (CMIsNullObject(inst) || res == NULL) + return CMPI_RC_ERR_FAILED; + + data = CMGetProperty(inst, "InstanceID", &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) + return CMPI_RC_ERR_FAILED; + + inst_id = CMGetCharPtr(data.value.string); + if ((inst_id == NULL) || (*inst_id == '\0')) + return CMPI_RC_ERR_FAILED; + + /* Extract the disk uuid from InstanceID property. */ + if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN)) + return CMPI_RC_ERR_FAILED; if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPortSettingData_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ - while (Xen_NetworkPortSettingData_getNextResource(session, resources, &resource)) { - /* Create a new CMPIInstance to store this resource. */ - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); - goto exit; - } - - /* Setup a filter to only return the desired properties. */ - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); - if (status.rc != CMPI_RC_OK) { - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); - goto exit; - } - - /* Set the instance property values from the resource data. */ - if (!Xen_NetworkPortSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) { - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); - goto exit; - } - - /* Free the resource data. */ - if (!Xen_NetworkPortSettingData_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - /* Return the CMPIInstance for this instance. */ - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); - CMReturnInstance(results, instance); - found++; - } - - _SBLIM_TRACE(2,("--- %d instances found", found)); - CMReturnDone(results); - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPortSettingData_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// GetInstance() -// Return the instance data for the specified instance only. -// ---------------------------------------------------------------------------- -static CMPIStatus GetInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ - const char ** properties) /* [in] List of desired properties (NULL=all). */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to the system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found the target instance? */ - - _SBLIM_ENTER("GetInstance"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPortSettingData_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Get the target resource. */ - found = Xen_NetworkPortSettingData_getResourceForObjectPath(session, &resource, reference); - if (!found || (resource == NULL)) { - _SBLIM_TRACE(1,("--- Target instance not found")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); - goto exit; - } - - /* Create a new CMPIInstance to store this resource. */ - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); - goto exit; + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- Unable to establish connection with Xend")); + return CMPI_RC_ERR_FAILED; + } + + /* Get memory for resource. */ + vif = (vif_resource *)calloc(1, sizeof(vif_resource)); + if (vif == NULL) + return CMPI_RC_ERR_FAILED; + + vif->is_vif_record = 1; + + if (!xen_vif_get_record(session->xen, &(vif->u.vif_rec), + (xen_vif)uuid)) { + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, + ("--- xen_vif_get_record failed:")); + _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR, + xen_utils_trace_error(session->xen)); + return CMPI_RC_ERR_FAILED; + } + + *res = (void *)vif; + return CMPI_RC_OK; +} + +static void release(void *res) +{ + if (res) { + vif_resource *vif = (vif_resource *)res; + if (vif->is_vif_record) + xen_vif_record_free(vif->u.vif_rec); + free(vif); + } +} + + +static CMPIrc add(const void *res_id, const void *res) +{ + (void)res_id; + (void)res; + + return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */ +} + + + +//Modifying the network port setting data is not supported +static CMPIrc modify(const void *res_id, const void *modified_res, + const char **properties) +{ + return CMPI_RC_ERR_NOT_SUPPORTED; +} + +static CMPIrc setproperties(CMPIInstance *inst, const void *res, + const char **properties) +{ + vif_resource *vif= (vif_resource *)res; + char buf[MAX_INSTANCEID_LEN]; + xen_vif_record *vif_rec; + + if (CMIsNullObject(inst) || vif == NULL || + !vif->is_vif_record) + return CMPI_RC_ERR_FAILED; + + vif_rec = vif->u.vif_rec; + session->xen->ok = true; + + xen_vm_record_opt *vm_rec_opt = vif_rec->vm; + if (vm_rec_opt->is_record) { + snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", + vm_rec_opt->u.record->name_label, vif_rec->uuid); + } + else { + char *name = NULL; + + if (!xen_vm_get_name_label(session->xen, &name, vm_rec_opt->u.handle)) + return CMPI_RC_ERR_FAILED; + snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", + name, vif_rec->uuid); + free(name); } /* Setup a filter to only return the desired properties. */ - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); - if (status.rc != CMPI_RC_OK) { - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); - goto exit; - } - - /* Set the instance property values from the resource data. */ - if (!Xen_NetworkPortSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) { - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); - goto exit; - } - - /* Free the resource data. */ - if (!Xen_NetworkPortSettingData_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - /* Return the CMPIInstance for this instance. */ - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); - CMReturnInstance(results, instance); - - _SBLIM_TRACE(2,("--- instance found")); - CMReturnDone(results); - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPortSettingData_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// SetInstance() -// Save modified instance data for the specified instance. -// ---------------------------------------------------------------------------- -static CMPIStatus SetInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ - const CMPIInstance * newinstance, /* [in] Contains the new instance data. */ - const char **properties) -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to the system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found the target instance? */ - - _SBLIM_ENTER("SetInstance"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPortSettingData_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Get the target resource. */ - found = Xen_NetworkPortSettingData_getResourceForObjectPath(session, &resource, reference); - if (!found || (resource == NULL)) { - _SBLIM_TRACE(1,("--- Target instance not found")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); - goto exit; - } - - _SBLIM_TRACE(2,("--- instance found", found)); - - /* Update the target resource data with the new instance property values. */ - int rc = Xen_NetworkPortSettingData_setResourceFromInstance(resource, newinstance, _BROKER); - - /* Free the resource data. */ - if (!Xen_NetworkPortSettingData_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - if (rc != 1) { - if (rc == -1) { - _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); - } else { - _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties"); - } - goto exit; - } - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPortSettingData_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// CreateInstance() -// Create a new instance from the specified instance data. -// ---------------------------------------------------------------------------- -static CMPIStatus CreateInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ - const CMPIInstance * newinstance) /* [in] Contains the new instance data. */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ - _RESOURCE * resource; /* Handle to the system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found the target instance? */ - - _SBLIM_ENTER("CreateInstance"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */ - reference = CMGetObjectPath(newinstance, NULL); - - /* Get a handle to the list of system resources. */ - if (!Xen_NetworkPortSettingData_getResources(session, &resources)) { - _SBLIM_TRACE(1,("--- _getResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); - goto exit; - } - - /* Get the target resource. */ - found = Xen_NetworkPortSettingData_getResourceForObjectPath(session, &resource, reference); - - /* Free the resource data. */ - if (!Xen_NetworkPortSettingData_freeResource(resource)) { - _SBLIM_TRACE(1,("--- _freeResource() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); - goto exit; - } - - if (found) { - _SBLIM_TRACE(1,("--- Target instance already exists")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists"); - goto exit; - } - - /* Create a new resource with the new instance property values. */ - int rc = Xen_NetworkPortSettingData_createResourceFromInstance(resources, &resource, newinstance, _BROKER); - if (rc != 1) { - if (rc == -1) { - _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); - } else { - _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties"); - } - goto exit; - } - - /* Return the object path for the newly created instance. */ - CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL); - CMSetNameSpace(objectpath, namespace); - CMReturnObjectPath(results, objectpath); - CMReturnDone(results); - -exit: - /* Free the list of system resources. */ - if (!Xen_NetworkPortSettingData_freeResources(resources)) { - _SBLIM_TRACE(1,("--- _freeResources() failed")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); - } - - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// DeleteInstance() -// Delete or remove the specified instance from the system. -// ---------------------------------------------------------------------------- -static CMPIStatus DeleteInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _RESOURCE * resource = NULL; /* Handle to the system resource. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - int found = 0; /* Found the target instance? */ - char error_msg[XEN_UTILS_ERROR_BUF_LEN]; - - _SBLIM_ENTER("DeleteInstance"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - if (!xen_utils_validate_session(&session)) { - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); - goto exit; - } - - /* Get the target resource. */ - found = Xen_NetworkPortSettingData_getResourceForObjectPath(session, &resource, reference); - if (!found || (resource == NULL)) { - _SBLIM_TRACE(1,("--- Target instance not found")); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); - goto exit; - } - - _SBLIM_TRACE(2,("--- instance found", found)); - - /* Delete the target resource. */ - if (!Xen_NetworkPortSettingData_deleteResource(session, resource)) { - XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); - _SBLIM_TRACE(1,("--- deleteResource failed: %s", error_msg)); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg); - goto exit; - } - -exit: - /* Free the resource. */ - if (resource) - Xen_NetworkPortSettingData_freeResource(resource); - - _SBLIM_RETURNSTATUS(status); -} - - -// ---------------------------------------------------------------------------- -// ExecQuery() -// Return a list of all the instances that satisfy the specified query filter. -// ---------------------------------------------------------------------------- -static CMPIStatus ExecQuery( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ - const char * language, /* [in] Name of the query language. */ - const char * query) /* [in] Text of the query written in the query language. */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ - - _SBLIM_ENTER("ExecQuery"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); - _SBLIM_TRACE(2, ("--- language=\"%s\"", language)); - _SBLIM_TRACE(2, ("--- query=\"%s\"", query)); - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); - - /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */ - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); - - CMReturnDone(results); - -exit: - _SBLIM_RETURNSTATUS(status); -} - -// ---------------------------------------------------------------------------- -// Initialize() -// Perform any necessary initialization immediately after this provider is -// first loaded. -// ---------------------------------------------------------------------------- -static void Initialize( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context) /* [in] Additional context info, if any. */ -{ - _SBLIM_ENTER("Initialize"); - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); - // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); - - /* Initialized Xen session object. */ - if (session == NULL) - xen_utils_xen_init(&session); - - _SBLIM_RETURN(); -} - -// ============================================================================ -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP -// ============================================================================ -CMInstanceMIStub( , Xen_NetworkPortSettingData, _BROKER, Initialize(&mi, ctx)); + CMSetPropertyFilter(inst, properties, keys); + + snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", vm_rec_opt->u.record->name_label, vif_rec->uuid); + CMSetProperty(inst, "InstanceID",(CMPIValue *)buf, CMPI_chars); + CMSetProperty(inst, "ElementName",(CMPIValue *)vif_rec->device, CMPI_chars); + + int type = 10; /* 10 == Ethernet Adapter */ + CMSetProperty(inst, "ResourceType",(CMPIValue *)&type, CMPI_uint16); + + int consumerVisibility = 3; /* 3 == Virtualized */ + CMSetProperty(inst, "ConsumerVisibility" , (CMPIValue *)&consumerVisibility, CMPI_uint16); + + unsigned long long nics = 1; + CMSetProperty(inst, "Reservation",(CMPIValue *)&nics, CMPI_uint64); + CMSetProperty(inst, "Limit",(CMPIValue *)&nics, CMPI_uint64); + CMSetProperty(inst, "AllocationUnits",(CMPIValue *)"Interfaces", CMPI_chars); + CMSetProperty(inst, "VirtualQuantity",(CMPIValue *)&nics, CMPI_uint64); + + int alloctype = 1; + CMSetProperty(inst, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean); + CMSetProperty(inst, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean); + + char nic_config_info[512]; + nic_config_info[0] = '\0'; + if (vif_rec->mac) + snprintf(nic_config_info, 512, "mac=%s", vif_rec->mac); +/* if (resource->model) { + strncat(nic_config_info, ",model=", 512 - strlen(nic_config_info)); + strncat(nic_config_info, resource->model, 512 - strlen(nic_config_info)); + }Nic config info does have model*/ + if (nic_config_info[0] != '\0') + CMSetProperty(inst, "NICConfigInfo" , (CMPIValue *)nic_config_info, CMPI_chars); + + /* + * TODO: + * PoolID, Weight + */ + + return CMPI_RC_OK; +} + +/* + * Set resource data from the CMPIInstance properties. Only needs to + * be implemented if add() and/or modify() are supported. + */ +static CMPIrc extract(void **res, const CMPIInstance *inst, + const char **properties) +{ + vif_resource *vif; + + (void)properties; + + /* Get memory for resource. */ + vif = (vif_resource *)calloc(1, sizeof(vif_resource)); + if (vif == NULL) + return CMPI_RC_ERR_FAILED; + + vif->u.cmpi_inst = (CMPIInstance *)inst; + *res = (void *)vif; + return CMPI_RC_OK; +} + + +/* Get resource id from CMPIInstance properties. */ +static CMPIrc extractid(void **res_id, const CMPIInstance* inst) +{ + *res_id = (void *)inst; + return CMPI_RC_OK; +} + + +/* Release resource id created in resId4inst(). */ +static void releaseid(void* res_id) +{ + (void)res_id; +} + + +/* Setup CMPILIFY function tables and instance provider entry point.*/ +/* CMPILIFYInstanceMIStub(,,,) */ +CMPILIFYInstanceMIStub(Xen_NetworkPortSettingData, Xen_NetworkPortSettingData, keys, mi) + diff -r 3ccb96bfe206 -r 64f8371acb35 src/Xen_NetworkPortSettingData_Resource.c --- a/src/Xen_NetworkPortSettingData_Resource.c Thu Aug 02 17:54:59 2007 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,300 +0,0 @@ -// Copyright (C) 2006 IBM Corporation -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ============================================================================ -// Authors: Dr. Gareth S. Bestor, -// Tokunbo Adeshiyan, -// Contributors: Jim Fehlig, -// Description: -// ============================================================================ - -#include -#include -#include - -#include -#include -#include - -#include "Xen_NetworkPortSettingData_Resource.h" - -/* Include the required CMPI data types, function headers, and macros. */ -#include "cmpidt.h" -#include "cmpift.h" -#include "cmpimacs.h" - -#include "xen_utils.h" -#include "provider_common.h" - - -// ---------------------------------------------------------------------------- - -static int concat_vif_lists(xen_vif_set **target, xen_vif_set *source) -{ - - int total_size; - int i, j; - - /* Nothing to concatenate if source is empty */ - if (source == NULL || source->size == 0) - return 1; - - /* If targe is empty, assign source to target */ - if (*target == NULL) { - *target = source; - return 1; - } - - /* realloc memory and append source to target */ - total_size = (*target)->size + source->size; - *target = realloc(*target, sizeof(xen_vif_set) + (total_size * sizeof(xen_vif))); - if (*target == NULL) - return 0; - - for (j = (*target)->size, i = 0; i < source->size; i++) { - (*target)->contents[j + i] = source->contents[i]; - source->contents[i] = NULL; - } - (*target)->size = total_size; - - /* Free source list - it has been copied to target */ - xen_vif_set_free(source); - return 1; -} - - -/* Get a handle to the list of all system resources for this class. */ -int Xen_NetworkPortSettingData_getResources(xen_utils_session *session, - _RESOURCES ** resources) -{ - xen_domain_resources *res; - xen_vif_set *all_vifs = NULL; - xen_vm_record *vm_rec = NULL; - - /* malloc a new handle for the resources list. */ - *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES)); - if (*resources == NULL) - return 0; - - /* Get a list of domain resources. */ - if (!xen_utils_get_domain_resources(session, &res)) { - *resources = NULL; - return 0; - } - - /* Create list of vif resources from vifs found in each domain. */ - while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) { - xen_vif_set *vif_set; - if (!xen_vm_get_vifs(session->xen, &vif_set, vm_rec->handle)) - goto Error; - - if (!concat_vif_lists(&all_vifs, vif_set)) - goto Error; - - xen_vm_record_free(vm_rec); - } - - (*resources)->vifs = all_vifs; - (*resources)->currentvifnum = 0; - - return 1; - - Error: - xen_vm_record_free(vm_rec); - xen_utils_free_domain_resources(res); - free(*resources); - *resources = NULL; - return 0; -} - -// ---------------------------------------------------------------------------- - -/* Free/deallocate/cleanup the resources list after use. */ -int Xen_NetworkPortSettingData_freeResources(_RESOURCES * resources) -{ - if (resources != NULL) { - if (resources->vifs != NULL) - xen_vif_set_free(resources->vifs); - free(resources); - resources = NULL; - } - - return 1; -} - -// ---------------------------------------------------------------------------- - -/* Iterator to get the next resource from the resources list. */ -int Xen_NetworkPortSettingData_getNextResource(xen_utils_session *session, - _RESOURCES * resources, - _RESOURCE ** resource) -{ - if (resources == NULL || resources->vifs == NULL) - return 0; - - /* Check if reached the end of the list of vifs. */ - if (resources->currentvifnum == resources->vifs->size) - return 0; - - /* Get the current vif record. */ - if (!xen_vif_get_record(session->xen, resource, resources->vifs->contents[resources->currentvifnum])) - return 0; - - resources->currentvifnum++; - return 1; -} - -// ---------------------------------------------------------------------------- - -/* Get the specific resource that matches the CMPI object path. */ -int Xen_NetworkPortSettingData_getResourceForObjectPath(xen_utils_session *session, - _RESOURCE ** resource, - const CMPIObjectPath * objectpath) -{ - char *instId; - char uuid[MAX_SYSTEM_NAME_LEN]; - int ccode; - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - - if (CMIsNullObject(objectpath)) return 0; - - /* Obtain the target resource identifier from the CMPIObjectPath key(s). */ - CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0; - - instId = CMGetCharPtr(iddata.value.string); - if ((instId == NULL) || (*instId == '\0')) return 0; - - /* Extract the disk uuid from InstanceID property. */ - if (!_CMPIStrncpyDeviceNameFromID(uuid, instId, MAX_SYSTEM_NAME_LEN)) - return 0; - - xen_vif vif; - if (!xen_vif_get_by_uuid(session->xen, &vif, uuid)) - return 0; - - ccode = xen_vif_get_record(session->xen, resource, vif); - xen_vif_free(vif); - return ccode; -} - -// ---------------------------------------------------------------------------- - -/* Free/deallocate/cleanup the resource after use. */ -int Xen_NetworkPortSettingData_freeResource(_RESOURCE * resource) -{ - xen_vif_record_free(resource); - return 1; -} - -// ---------------------------------------------------------------------------- - -/* Set the property values of a CMPI instance from a specific resource. */ -int Xen_NetworkPortSettingData_setInstanceFromResource(xen_utils_session *session, - _RESOURCE * resource, - const CMPIInstance * instance, - const CMPIBroker * broker) -{ - char buf[MAX_INSTANCEID_LEN]; - xen_vm_record *alloced_vm_rec = NULL; - xen_vm_record *vm_rec; - - if (resource == NULL) return 0; - if (CMIsNullObject(instance)) return 0; - - xen_vm_record_opt *vm_rec_opt = resource->vm; - if (vm_rec_opt->is_record) { - vm_rec = vm_rec_opt->u.record; - } - else { - if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) { - /* Error description in session object! */ - return 0; - } - alloced_vm_rec = vm_rec; - } - - /* Set the CMPIInstance properties from the resource data. */ - snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", vm_rec->name_label, resource->uuid); - CMSetProperty(instance, "InstanceID",(CMPIValue *)buf, CMPI_chars); - CMSetProperty(instance, "ElementName",(CMPIValue *)resource->device, CMPI_chars); - - int type = 10; /* 10 == Ethernet Adapter */ - CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16); - - int consumerVisibility = 3; /* 3 == Virtualized */ - CMSetProperty(instance, "ConsumerVisibility" , (CMPIValue *)&consumerVisibility, CMPI_uint16); - - unsigned long long nics = 1; - CMSetProperty(instance, "Reservation",(CMPIValue *)&nics, CMPI_uint64); - CMSetProperty(instance, "Limit",(CMPIValue *)&nics, CMPI_uint64); - CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Interfaces", CMPI_chars); - CMSetProperty(instance, "VirtualQuantity",(CMPIValue *)&nics, CMPI_uint64); - - int alloctype = 1; - CMSetProperty(instance, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean); - CMSetProperty(instance, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean); - - char nic_config_info[512]; - nic_config_info[0] = '\0'; - if (resource->mac) - snprintf(nic_config_info, 512, "mac=%s", resource->mac); -/* if (resource->model) { - strncat(nic_config_info, ",model=", 512 - strlen(nic_config_info)); - strncat(nic_config_info, resource->model, 512 - strlen(nic_config_info)); - }Nic config info does have model*/ - if (nic_config_info[0] != '\0') - CMSetProperty(instance, "NICConfigInfo" , (CMPIValue *)nic_config_info, CMPI_chars); - - /* - * TODO: - * PoolID, Weight - */ - - return 1; -} - -// ---------------------------------------------------------------------------- - -/* Delete the specified resource from the system. */ -int Xen_NetworkPortSettingData_deleteResource(xen_utils_session *session, - _RESOURCE * resource) -{ - return xen_vif_destroy(session->xen, resource->handle); -} - -// ---------------------------------------------------------------------------- - -/* Modify the specified resource using the property values of a CMPI instance. */ -int Xen_NetworkPortSettingData_setResourceFromInstance(_RESOURCE * resource, - const CMPIInstance * instance, - const CMPIBroker * broker) -{ - /* Unsupported. */ - return -1; -} - -// ---------------------------------------------------------------------------- - -/* Create a new resource using the property values of a CMPI instance. */ -int Xen_NetworkPortSettingData_createResourceFromInstance(_RESOURCES * resources, - _RESOURCE ** resource, - const CMPIInstance * instance, - const CMPIBroker * broker) -{ - /* Unsupported. */ - return -1; -} - diff -r 3ccb96bfe206 -r 64f8371acb35 src/Xen_NetworkPortSettingData_Resource.h --- a/src/Xen_NetworkPortSettingData_Resource.h Thu Aug 02 17:54:59 2007 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -// Copyright (C) 2006 IBM Corporation -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ============================================================================ -// Authors: Dr. Gareth S. Bestor, -// Tokunbo Adeshiyan, -// Contributors: Jim Fehlig, -// Description: -// ============================================================================ - -/* Include required libxen headers. */ -#include -#include - -#include "xen_utils.h" - -/* Include the required CMPI data types. */ -#include "cmpidt.h" - - -/*** CUSTOMIZE FOR EACH PROVIDER ***/ -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES. - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS - LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC. - THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN - ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ -typedef struct { - xen_vif_set *vifs; - unsigned int currentvifnum; -} _RESOURCES; - -/*** CUSTOMIZE FOR EACH PROVIDER ***/ -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE. - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH - RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE - PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE - ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */ -typedef xen_vif_record _RESOURCE; - - -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */ - -// ---------------------------------------------------------------------------- -// Generic resource access methods for CMPI providers. -// Return value: -// -1 = Unsupported -// 0 = Failed -// 1 = OK -// ---------------------------------------------------------------------------- - -/* Get a handle to the list of all system resources for this class. */ -int Xen_NetworkPortSettingData_getResources(xen_utils_session *session, - _RESOURCES ** resources); - -/* Free/deallocate/cleanup the resources list after use. */ -int Xen_NetworkPortSettingData_freeResources(_RESOURCES * resources); - -/* Iterator to get the next resource from the resources list. */ -int Xen_NetworkPortSettingData_getNextResource(xen_utils_session *session, - _RESOURCES * resources, - _RESOURCE ** resource); - -/* Get the specific resource that matches the CMPI object path. */ -int Xen_NetworkPortSettingData_getResourceForObjectPath(xen_utils_session *session, - _RESOURCE ** resource, - const CMPIObjectPath * objectpath); - -/* Free/deallocate/cleanup a resource after use. */ -int Xen_NetworkPortSettingData_freeResource(_RESOURCE * resource); - -/* Set the property values of a CMPI instance from a specific resource. */ -int Xen_NetworkPortSettingData_setInstanceFromResource(xen_utils_session *session, - _RESOURCE * resource, - const CMPIInstance * instance, - const CMPIBroker * broker); - -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS - -/* Delete the specified resource from the system. */ -int Xen_NetworkPortSettingData_deleteResource(xen_utils_session *session, - _RESOURCE * resource); - -/* Modify the specified resource using the property values of a CMPI instance. */ -int Xen_NetworkPortSettingData_setResourceFromInstance(_RESOURCE * resource, - const CMPIInstance * instance, - const CMPIBroker * broker); - -/* Create a new resource using the property values of a CMPI instance. */ -int Xen_NetworkPortSettingData_createResourceFromInstance(_RESOURCES * resources, - _RESOURCE ** resource, - const CMPIInstance * instance, - const CMPIBroker * broker); - diff -r 3ccb96bfe206 -r 64f8371acb35 src/Xen_NetworkPort_Resource.c --- a/src/Xen_NetworkPort_Resource.c Thu Aug 02 17:54:59 2007 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,315 +0,0 @@ -// Copyright (C) 2006 IBM Corporation -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ============================================================================ -// Authors: Dr. Gareth S. Bestor, -// Tokunbo Adeshiyan, -// Contributors: Jim Fehlig, -// Rajagopalan Subrahmanian, -// Description: -// ============================================================================ - -#include -#include -#include - -#include -#include -#include - -#include "Xen_NetworkPort_Resource.h" - -/* Include the required CMPI data types, function headers, and macros. */ -#include "cmpidt.h" -#include "cmpift.h" -#include "cmpimacs.h" - -#include "xen_utils.h" - -/* Include _SBLIM_TRACE() logging support */ -#include "cmpitrace.h" - -// ---------------------------------------------------------------------------- - -static int concat_vif_lists(xen_vif_set **target, xen_vif_set *source) -{ - - int total_size; - int i, j; - - /* Nothing to concatenate if source is empty */ - if (source == NULL || source->size == 0) - return 1; - - /* If targe is empty, assign source to target */ - if (*target == NULL) { - *target = source; - return 1; - } - - /* realloc memory and append source to target */ - total_size = (*target)->size + source->size; - *target = realloc(*target, sizeof(xen_vif_set) + (total_size * sizeof(xen_vif))); - if (*target == NULL) - return 0; - - for (j = (*target)->size, i = 0; i < source->size; i++) { - (*target)->contents[j + i] = source->contents[i]; - source->contents[i] = NULL; - } - (*target)->size = total_size; - - /* Free source list - it has been copied to target */ - xen_vif_set_free(source); - return 1; -} - - -/* Get a handle to the list of all system resources for this class. */ -int Xen_NetworkPort_getResources(xen_utils_session *session, - _RESOURCES ** resources) -{ - xen_domain_resources *res; - xen_vif_set *all_vifs = NULL; - xen_vm_record *vm_rec = NULL; - - /* malloc a new handle for the resources list. */ - *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES)); - if (*resources == NULL) - return 0; - - /* Get a list of domain resources. */ - if (!xen_utils_get_domain_resources(session, &res)) { - *resources = NULL; - return 0; - } - - /* Create list of vif resources from vifs found in each domain. */ - while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) { - /* Ignore halted vms */ - if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) { - xen_vm_record_free(vm_rec); - continue; - } - - xen_vif_set *vif_set; - if (!xen_vm_get_vifs(session->xen, &vif_set, vm_rec->handle)) - goto Error; - - if (!concat_vif_lists(&all_vifs, vif_set)) - goto Error; - - xen_vm_record_free(vm_rec); - } - - (*resources)->vifs = all_vifs; - (*resources)->currentvifnum = 0; - - return 1; - - Error: - xen_vm_record_free(vm_rec); - xen_utils_free_domain_resources(res); - free(*resources); - *resources = NULL; - return 0; -} - -// ---------------------------------------------------------------------------- - -/* Free/deallocate/cleanup the resources list after use. */ -int Xen_NetworkPort_freeResources(_RESOURCES * resources) -{ - if (resources != NULL) { - if (resources->vifs != NULL) - xen_vif_set_free(resources->vifs); - free(resources); - resources = NULL; - } - - return 1; -} - -// ---------------------------------------------------------------------------- - -/* Iterator to get the next resource from the resources list. */ -int Xen_NetworkPort_getNextResource(xen_utils_session *session, - _RESOURCES * resources, - _RESOURCE ** resource) -{ - if (resources == NULL || resources->vifs == NULL) - return 0; - - /* Check if reached the end of the list of vifs. */ - if (resources->currentvifnum == resources->vifs->size) - return 0; - - /* Get the current vif record. */ - if (!xen_vif_get_record(session->xen, resource, resources->vifs->contents[resources->currentvifnum])) - return 0; - - resources->currentvifnum++; - return 1; -} - -// ---------------------------------------------------------------------------- - -/* Get the specific resource that matches the CMPI object path. */ -int Xen_NetworkPort_getResourceForObjectPath(xen_utils_session *session, - _RESOURCE ** resource, - const CMPIObjectPath * objectpath) -{ - CMPIData namedata; - char *keyvalue; - int ccode; - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - - if (CMIsNullObject(objectpath)) return 0; - - /* Get the vif resource based on DeviceID (vif uuid) */ - namedata = CMGetKey(objectpath, "DeviceID", &status); - if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) - return 0; - - keyvalue = CMGetCharPtr(namedata.value.string); - if ((keyvalue == NULL) || (*keyvalue == '\0')) - return 0; - - xen_vif vif; - if (!xen_vif_get_by_uuid(session->xen, &vif, keyvalue)) - return 0; - - ccode = xen_vif_get_record(session->xen, resource, vif); - xen_vif_free(vif); - return ccode; -} - -// ---------------------------------------------------------------------------- - -/* Free/deallocate/cleanup the resource after use. */ -int Xen_NetworkPort_freeResource(_RESOURCE * resource) -{ - xen_vif_record_free(resource); - return 1; -} - -// ---------------------------------------------------------------------------- - -/* Set the property values of a CMPI instance from a specific resource. */ -int Xen_NetworkPort_setInstanceFromResource(xen_utils_session *session, - _RESOURCE * resource, - const CMPIInstance * instance, - const CMPIBroker * broker) -{ - xen_vm_record *alloced_vm_rec = NULL; - xen_vm_record *vm_rec; - - if (resource == NULL) return 0; - if (CMIsNullObject(instance)) return 0; - - xen_vm_record_opt *vm_rec_opt = resource->vm; - if (vm_rec_opt->is_record) { - vm_rec = vm_rec_opt->u.record; - } - else { - if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) { - /* Error description in session object! */ - return 0; - } - alloced_vm_rec = vm_rec; - } - - /* Set the CMPIInstance properties from the resource data. */ - CMSetProperty(instance, "SystemCreationClassName",(CMPIValue *)"Xen_ComputerSystem", CMPI_chars); - CMSetProperty(instance, "SystemName",(CMPIValue *)vm_rec->name_label, CMPI_chars); - CMSetProperty(instance, "CreationClassName",(CMPIValue *)"Xen_NetworkPort", CMPI_chars); - - CMSetProperty(instance, "DeviceID",(CMPIValue *)resource->uuid, CMPI_chars); - - CMSetProperty(instance, "Caption",(CMPIValue *)"Network Port", CMPI_chars); - CMSetProperty(instance, "Description",(CMPIValue *)"Network Port", CMPI_chars); - - //CMSetProperty(instance, "NICConfigInfo",(CMPIValue *)resource->vif[vifnum].params, CMPI_chars); - - int link_tech = 2; /* 2 == Ethernet */ - CMSetProperty(instance, "LinkTechnology",(CMPIValue *)&link_tech, CMPI_uint16); - - if (resource->device) { - CMSetProperty(instance, "Name",(CMPIValue *)resource->device, CMPI_chars); - CMSetProperty(instance, "VIFName",(CMPIValue *)resource->device, CMPI_chars); - } - - if (resource->mac) - CMSetProperty(instance, "PermanentAddress",(CMPIValue *)resource->mac, CMPI_chars); - if (resource->mtu > 0) { - CMSetProperty(instance, "SupportedMaximumTransmissionUnit",(CMPIValue *)&(resource->mtu), CMPI_uint64); - CMSetProperty(instance, "ActiveMaximumTransmissionUnit",(CMPIValue *)&(resource->mtu), CMPI_uint64); - } - - char nic_config_info[512]; - nic_config_info[0] = '\0'; - if (resource->mac) - snprintf(nic_config_info, 512, "mac=%s", resource->mac); - /*if (resource->model) { - strncat(nic_config_info, ",model=", 512 - strlen(nic_config_info)); - strncat(nic_config_info, resource->model, 512 - strlen(nic_config_info)); - } NIC config info does not have model*/ - if (nic_config_info[0] != '\0') - CMSetProperty(instance, "NICConfigInfo" , (CMPIValue *)nic_config_info, CMPI_chars); - - if (vm_rec->power_state != XEN_VM_POWER_STATE_HALTED) { - CMSetProperty(instance, "Status", (CMPIValue *)"OK", CMPI_chars); - } else { - CMSetProperty(instance, "Status", (CMPIValue *)"No Contact", CMPI_chars); - } - - if (alloced_vm_rec) - xen_vm_record_free(alloced_vm_rec); - - return 1; -} - -// ---------------------------------------------------------------------------- - -/* Delete the specified resource from the system. */ -int Xen_NetworkPort_deleteResource(xen_utils_session *session, - _RESOURCE * resource) -{ - return xen_vif_destroy(session->xen, resource->handle); -} - -// ---------------------------------------------------------------------------- - -/* Modify the specified resource using the property values of a CMPI instance. */ -int Xen_NetworkPort_setResourceFromInstance(_RESOURCE * resource, - const CMPIInstance * instance, - const CMPIBroker * broker) -{ - /* Unsupported. */ - return -1; -} - -// ---------------------------------------------------------------------------- - -/* Create a new resource using the property values of a CMPI instance. */ -int Xen_NetworkPort_createResourceFromInstance(_RESOURCES * resources, - _RESOURCE ** resource, - const CMPIInstance * instance, - const CMPIBroker * broker) -{ - /* Unsupported. */ - return -1; -} - diff -r 3ccb96bfe206 -r 64f8371acb35 src/Xen_NetworkPort_Resource.h --- a/src/Xen_NetworkPort_Resource.h Thu Aug 02 17:54:59 2007 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -// Copyright (C) 2006 IBM Corporation -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ============================================================================ -// Authors: Dr. Gareth S. Bestor, -// Tokunbo Adeshiyan, -// Contributors: Jim Fehlig, -// Rajagopalan Subrahmanian -// Description: -// ============================================================================ - -/* Include required libxen headers. */ -#include -#include - -#include "xen_utils.h" - -/*** CUSTOMIZE FOR EACH PROVIDER ***/ -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES. - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS - LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC. - THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN - ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ -typedef struct { - xen_vif_set *vifs; - unsigned int currentvifnum; -} _RESOURCES; - -/*** CUSTOMIZE FOR EACH PROVIDER ***/ -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE. - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH - RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE - PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE - ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */ -typedef xen_vif_record _RESOURCE; - -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */ - -/* Include the required CMPI data types. */ -#include "cmpidt.h" - -// ---------------------------------------------------------------------------- -// Generic resource access methods for CMPI providers. -// Return value: -// -1 = Unsupported -// 0 = Failed -// 1 = OK -// ---------------------------------------------------------------------------- - -/* Get a handle to the list of all system resources for this class. */ -int Xen_NetworkPort_getResources(xen_utils_session *session, - _RESOURCES ** resources); - -/* Free/deallocate/cleanup the resources list after use. */ -int Xen_NetworkPort_freeResources(_RESOURCES * resources); - -/* Iterator to get the next resource from the resources list. */ -int Xen_NetworkPort_getNextResource(xen_utils_session *session, - _RESOURCES * resources, - _RESOURCE ** resource); - -/* Get the specific resource that matches the CMPI object path. */ -int Xen_NetworkPort_getResourceForObjectPath(xen_utils_session *session, - _RESOURCE ** resource, - const CMPIObjectPath * objectpath); - -/* Free/deallocate/cleanup a resource after use. */ -int Xen_NetworkPort_freeResource(_RESOURCE * resource); - -/* Set the property values of a CMPI instance from a specific resource. */ -int Xen_NetworkPort_setInstanceFromResource(xen_utils_session *session, - _RESOURCE * resource, - const CMPIInstance * instance, - const CMPIBroker * broker); - -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS - -/* Delete the specified resource from the system. */ -int Xen_NetworkPort_deleteResource(xen_utils_session *session, - _RESOURCE * resource); - -/* Modify the specified resource using the property values of a CMPI instance. */ -int Xen_NetworkPort_setResourceFromInstance(_RESOURCE * resource, - const CMPIInstance * instance, - const CMPIBroker * broker); - -/* Create a new resource using the property values of a CMPI instance. */ -int Xen_NetworkPort_createResourceFromInstance(_RESOURCES * resources, - _RESOURCE ** resource, - const CMPIInstance * instance, - const CMPIBroker * broker); -