[PATCH 0 of 2] #2 Add support for generating image XML

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1245187550 25200 # Node ID 6a1d6542f10fb0c506aca304020ac64b9e3f98d0 # Parent bf7220c52d7afecf85d7c2a6b11d9ba0f45052f9 (#2) Image Creation: add functions for generating a storage volume XML Updates from 1 to 2: -In res_to_xml() reuse message when formatting CU_DEBUG() in the switch statement Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r bf7220c52d7a -r 6a1d6542f10f libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Tue Aug 11 14:15:34 2009 -0600 +++ b/libxkutil/xmlgen.c Tue Jun 16 14:25:50 2009 -0700 @@ -39,6 +39,7 @@ typedef const char *(*devfn_t)(xmlNodePtr node, struct domain *dominfo); typedef const char *(*poolfn_t)(xmlNodePtr node, struct virt_pool *pool); +typedef const char *(*resfn_t)(xmlNodePtr node, struct virt_pool_res *res); static char *disk_block_xml(xmlNodePtr root, struct disk_device *dev) { @@ -1056,6 +1057,133 @@ return xml; } +static const char *vol_format_type_to_str(uint16_t type) +{ + switch (type) { + case VOL_FORMAT_RAW: + return "raw"; + default: + CU_DEBUG("Unsupported storage volume type"); + } + + return NULL; +} + +static const char *storage_vol_xml(xmlNodePtr root, + struct virt_pool_res *res) +{ + xmlNodePtr v = NULL; + xmlNodePtr name = NULL; + xmlNodePtr alloc = NULL; + xmlNodePtr cap = NULL; + xmlNodePtr target = NULL; + xmlNodePtr path = NULL; + xmlNodePtr format = NULL; + const char *type = NULL; + struct storage_vol *vol = &res->res.storage_vol; + char *string = NULL; + int ret; + + type = vol_format_type_to_str(vol->format_type); + if (type == NULL) + goto out; + + v = xmlNewChild(root, NULL, BAD_CAST "volume", NULL); + if (v == NULL) + goto out; + + name = xmlNewChild(v, NULL, BAD_CAST "name", BAD_CAST vol->vol_name); + if (name == NULL) + goto out; + + ret = asprintf(&string, "%" PRIu16, vol->alloc); + if (ret == -1) + return XML_ERROR; + + alloc = xmlNewChild(v, NULL, BAD_CAST "allocation", BAD_CAST string); + if (alloc == NULL) + goto out; + + free(string); + ret = asprintf(&string, "%" PRIu16, vol->cap); + if (ret == -1) + return XML_ERROR; + + cap = xmlNewChild(v, NULL, BAD_CAST "capacity", BAD_CAST string); + if (cap == NULL) + goto out; + + free(string); + + if (xmlNewProp(cap, BAD_CAST "unit", BAD_CAST vol->cap_units) == NULL) + goto out; + + target = xmlNewChild(v, NULL, BAD_CAST "target", NULL); + if (target == NULL) + goto out; + + path = xmlNewChild(target, NULL, BAD_CAST "path", BAD_CAST vol->path); + if (path == NULL) + goto out; + + format = xmlNewChild(target, NULL, BAD_CAST "format", NULL); + if (format == NULL) + goto out; + + if (xmlNewProp(format, BAD_CAST "type", BAD_CAST type) == NULL) + goto out; + + /* FIXME: Need to add permissions and label tags here */ + + return NULL; + + out: + free(string); + return XML_ERROR; + } + +char *res_to_xml(struct virt_pool_res *res) { + char *xml = NULL; + xmlNodePtr root = NULL; + int type = res->type; + const char *msg = NULL; + resfn_t func; + + root = xmlNewNode(NULL, BAD_CAST "tmp"); + if (root == NULL) { + msg = XML_ERROR; + goto out; + } + + switch (type) { + case CIM_RES_TYPE_IMAGE: + func = storage_vol_xml; + break; + default: + msg = "res_to_xml: invalid type specified"; + CU_DEBUG("%s %d", msg, type); + goto out; + } + + msg = func(root, res); + if (msg != NULL) + goto out; + + xml = tree_to_xml(root->children); + if (xml == NULL) + msg = "XML generation failed"; + out: + if (msg != NULL) { + CU_DEBUG("Failed to create res XML: %s", msg); + } else { + CU_DEBUG("Created res XML:\n%s\n", xml); + } + + xmlFreeNode(root); + + return xml; +} + /* * Local Variables: * mode: C diff -r bf7220c52d7a -r 6a1d6542f10f libxkutil/xmlgen.h --- a/libxkutil/xmlgen.h Tue Aug 11 14:15:34 2009 -0600 +++ b/libxkutil/xmlgen.h Tue Jun 16 14:25:50 2009 -0700 @@ -36,4 +36,6 @@ char *pool_to_xml(struct virt_pool *pool); +char *res_to_xml(struct virt_pool_res *res); + #endif

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1245187550 25200 # Node ID 9be84616fbb0b94c0ae1287cb0a6252873790bb3 # Parent 6a1d6542f10fb0c506aca304020ac64b9e3f98d0 Image creation: Add support for CreateResourceInPool() method Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 6a1d6542f10f -r 9be84616fbb0 src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Tue Jun 16 14:25:50 2009 -0700 +++ b/src/Virt_ResourcePoolConfigurationService.c Tue Jun 16 14:25:50 2009 -0700 @@ -784,6 +784,9 @@ CMPIObjectPath *pool; struct virt_pool_res *res = NULL; const char* msg = NULL; + const char *id = NULL; + char *pool_id = NULL; + char *xml = NULL; CU_DEBUG("CreateResourceInPool"); @@ -808,12 +811,44 @@ goto out; } + if (cu_get_str_path(pool, "InstanceID", &id) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing InstanceID in resource pool"); + goto out; + } + + pool_id = name_from_pool_id(id); + if (pool_id == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_INVALID_PARAMETER, + "Pool has invalid InstanceID"); + goto out; + } + + free(res->pool_id); + res->pool_id = strdup(pool_id); + + xml = res_to_xml(res); + if (xml == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to generate XML for new resource"); + goto out; + } + + CU_DEBUG("New resource XML:\n%s", xml); + + /*FIXME: Add resource here */ + + out: + free(pool_id); + free(xml); + if (s.rc == CMPI_RC_OK) rc = CIM_SVPC_RETURN_COMPLETED; CMReturnData(results, &rc, CMPI_uint32); - out: - return s; }

+1 On 08/12/2009 04:54 PM, Kaitlin Rupert wrote:
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel