From 25d3b467eddedb74cdefcfe2825368a1bf8bdedd Mon Sep 17 00:00:00 2001 From: Stefan de Konink Date: Wed, 23 Jul 2008 02:17:12 +0200 Subject: [PATCH] Initial support for storageCreateVolume --- handler_virt.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++------- handler_virt.h | 2 + 2 files changed, 118 insertions(+), 14 deletions(-) diff --git a/handler_virt.c b/handler_virt.c index b3d8c16..bb08c4d 100644 --- a/handler_virt.c +++ b/handler_virt.c @@ -42,6 +42,8 @@ " " \ " " + + #define VIRT_DOMAIN_XML \ "" \ " %s_%s" \ @@ -60,7 +62,21 @@ " " \ "" - +#define VIRT_STORAGE_XML \ +"" \ +" %s" \ +" %lu" \ +" %lu" \ +" " \ +" %s/%s/images/%s" \ +" " \ +" 0744" \ +" 0744" \ +" 0744" \ +" " \ +" " \ +" " \ +"" #include "handler_virt.h" @@ -247,6 +263,11 @@ cherokee_handler_virt_init (cherokee_handler_virt_t *hdl) else if (strcmp(this+9, "DefineXML") == 0) hdl->action = domainDefineXML_args; else if (strcmp(this+9, "Undefine") == 0) hdl->action = domainUndefine; } + else if (strncmp(this, "virStorage", 10) == 0) { + if (strncmp(this+10, "Vol", 3) == 0) { + if (strcmp(this+13, "CreateXML") == 0) hdl->action = storageCreateXML_args; + } + } break; case http_post: { @@ -263,6 +284,12 @@ cherokee_handler_virt_init (cherokee_handler_virt_t *hdl) else if (strcmp(this+9, "DetachDevice") == 0) hdl->action = domainDetachDevice; else if (strcmp(this+9, "DefineXML") == 0) hdl->action = domainDefineXML; } + else if (strncmp(this, "virStorage", 10) == 0) { + if (strncmp(this+10, "Vol", 3) == 0) { + if (strcmp(this+13, "CreateXML") == 0) hdl->action = storageCreateXML; + } + } + break; } @@ -348,6 +375,7 @@ virt_virt_function(cherokee_handler_virt_t *hdl, virDomainPtr dom) { cherokee_buffer_t *buf = &HDL_AVAHI(hdl)->buffer; switch (hdl->action) { + case domainUndefine: { int result; if ((result = virDomainUndefine(dom)) != 0) { @@ -529,6 +557,58 @@ virt_virt_new(cherokee_handler_virt_t *hdl, virConnectPtr virConn) virDomainPtr result; switch (hdl->action) { + case storageCreateXML_args: { + char *temp, *type, *name, *unit, *pool_path; + unsigned long int capacity, allocation; + ret_t ret; + ret = cherokee_connection_parse_args (conn); + if (unlikely(ret < ret_ok)) + return ret; + + ret = cherokee_avl_get_ptr (conn->arguments, "pool", &temp); + if (unlikely(ret < ret_ok)) + return ret; + + virStoragePoolPtr pool = virStoragePoolLookupByName(virConn, temp); + + if (pool == NULL) + return ret_error; + + ret = cherokee_avl_get_ptr (conn->arguments, "name", &name); + if (unlikely(ret < ret_ok)) + return ret; + + ret = cherokee_avl_get_ptr (conn->arguments, "type", &type); + if (unlikely(ret < ret_ok)) + return ret; + + ret = cherokee_avl_get_ptr (conn->arguments, "type", &type); + if (unlikely(ret < ret_ok)) + return ret; + + ret = cherokee_avl_get_ptr (conn->arguments, "allocation", &temp); + if (unlikely(ret < ret_ok)) + return ret; + + allocation = strtoul(temp, NULL, 10); + /* TODO: errno check */ + + ret = cherokee_avl_get_ptr (conn->arguments, "capacity", &temp); + if (unlikely(ret < ret_ok)) + return ret; + + capacity = strtoul(temp, NULL, 10); + /* TODO: errno check */ + + pool_path = virStorageVolGetPath(pool); + if (!pool_path) + return ret_error; + + cherokee_buffer_add_va (&xml, VIRT_STORAGE_XML, type, name, allocation, unit, capacity, pool_path, hdl->user.buf, name, hdl->user.buf, name); + free(pool_path); + + } + case domainDefineXML_args: { ret_t ret; unsigned int i; @@ -589,6 +669,7 @@ virt_virt_new(cherokee_handler_virt_t *hdl, virConnectPtr virConn) break; } + case storageCreateXML: case domainDefineXML: { off_t postl; cherokee_post_get_len (&conn->post, &postl); @@ -596,23 +677,44 @@ virt_virt_new(cherokee_handler_virt_t *hdl, virConnectPtr virConn) break; } } - - result = virDomainDefineXML(virConn, (const char *) xml.buf); - printf("%s\n", xml.buf); - cherokee_buffer_mrproper(&xml); - if (result == NULL) { - /* TODO: vrij maken eventuele uitgegeven macs! */ - conn->error_code = http_internal_error; - return ret_error; - } + switch (hdl->action) { + case domainDefineXML_args: + case domainDefineXML: { + result = virDomainDefineXML(virConn, (const char *) xml.buf); + // printf("%s\n", xml.buf); + cherokee_buffer_mrproper(&xml); + + if (result == NULL) { + /* TODO: vrij maken eventuele uitgegeven macs! */ + conn->error_code = http_internal_error; + return ret_error; + } + + char *output = virDomainGetXMLDesc(result, 0); + /* TODO: store the domain on DISK! */ + FILE *fd = fopen("/mnt/netapp/%s/%s.xml", "w"); + fwrite(output, strlen(output), sizof(char), fd); + fclose(fd); + cherokee_buffer_add(buf, output, strlen(output)); + free(output); + break; + } - char *output = virDomainGetXMLDesc(result, 0); - cherokee_buffer_add(buf, output, strlen(output)); - free(output); + case storageCreateXML_args: + case storageCreateXML: { + printf("%s", &xml.buf); + virStorageVolPtr vol = virStorageVolCreateXML(pool, &xml.buf, 0); + cherokee_buffer_mrproper(&xml); + + if (vol == NULL) + return ret_error; - /* TODO: store the domain on DISK! */ + cherokee_buffer_add_long10(buf, 0); + break; + } + } return ret_ok; } diff --git a/handler_virt.h b/handler_virt.h index 6b9ea6e..e8b713b 100644 --- a/handler_virt.h +++ b/handler_virt.h @@ -78,6 +78,8 @@ typedef struct { domainShutdown, domainInterfaceStats, domainUndefine, + storageVolCreateXML, + storageVolCreateXML_args, xml, domainDefineXML_args, domainDefineXML, -- 2.11.4.GIT