diff --git a/ChangeLog b/ChangeLog index bc895dd9944a4321425646589d2b51be6b539e8e..b5303364255e42f3ba11f96ec28e61a2e65c2c9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Feb 20 12:20:32 EST 2006 Daniel Veillard + + * TODO: updated + * include/libvirt.h include/libvirt.h.in: cleanup + * src/libvirt.c: remove debugging output + * src/xend_internal.c src/xml.c src/xml.h: reimplement + virDomainGetXMLDesc() based on xend interface, now work as user too. + Fri Feb 17 08:17:36 EST 2006 Daniel Veillard * python/tests/create.py: trying to make test more generic, but it's diff --git a/TODO b/TODO index beadf81c5fd10a4ff945d14353da7fcb72d95509..c3c82a2ddd817f61e311a647be730231fbe5cfce 100644 --- a/TODO +++ b/TODO @@ -4,6 +4,7 @@ Absolute TODOs: - thread protection, reentrancy, refcounting, etc ... - documentation and examples on using the toolkit - Error API. probably similar to libxml2 structured API +- extract error messages from the Xend rpc TODO: - track change of xend API, XML-RPC, UUID based lookup and naming @@ -18,6 +19,10 @@ Would-be-nice TODO: - man page for virsh and the libraries entry points - support for QEmu and other virtualization engines +Cleanup: +- now that libxml2 is linked in, drop hash.[ch] and get back to libxml2 ones ? + same for the buffers + Done: - make dist and make rpm targets - set a no public by default policy for libvir symbols diff --git a/include/libvirt.h b/include/libvirt.h index b6951868b654a720bc83fed34be30f1f6ae90675..30269299ff110670ae994c7969195874219fc425 100644 --- a/include/libvirt.h +++ b/include/libvirt.h @@ -239,10 +239,12 @@ char * virDomainGetOSType (virDomainPtr domain); unsigned long virDomainGetMaxMemory (virDomainPtr domain); int virDomainSetMaxMemory (virDomainPtr domain, unsigned long memory); + /* * XML domain description */ -char * virDomainGetXMLDesc (virDomainPtr domain, int flags); +char * virDomainGetXMLDesc (virDomainPtr domain, + int flags); #ifdef __cplusplus } diff --git a/include/libvirt.h.in b/include/libvirt.h.in index 6655c388e5566b3ae16163bb99d07b981bcb8119..1fe50152322811f97dd9e0d3f37a73b8e240f1dc 100644 --- a/include/libvirt.h.in +++ b/include/libvirt.h.in @@ -242,7 +242,8 @@ int virDomainSetMaxMemory (virDomainPtr domain, /* * XML domain description */ -char * virDomainGetXMLDesc (virDomainPtr domain, int flags); +char * virDomainGetXMLDesc (virDomainPtr domain, + int flags); #ifdef __cplusplus } diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index b6951868b654a720bc83fed34be30f1f6ae90675..30269299ff110670ae994c7969195874219fc425 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -239,10 +239,12 @@ char * virDomainGetOSType (virDomainPtr domain); unsigned long virDomainGetMaxMemory (virDomainPtr domain); int virDomainSetMaxMemory (virDomainPtr domain, unsigned long memory); + /* * XML domain description */ -char * virDomainGetXMLDesc (virDomainPtr domain, int flags); +char * virDomainGetXMLDesc (virDomainPtr domain, + int flags); #ifdef __cplusplus } diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 6655c388e5566b3ae16163bb99d07b981bcb8119..1fe50152322811f97dd9e0d3f37a73b8e240f1dc 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -242,7 +242,8 @@ int virDomainSetMaxMemory (virDomainPtr domain, /* * XML domain description */ -char * virDomainGetXMLDesc (virDomainPtr domain, int flags); +char * virDomainGetXMLDesc (virDomainPtr domain, + int flags); #ifdef __cplusplus } diff --git a/src/libvirt.c b/src/libvirt.c index 604882cfd7304e4b31f80ee66333268d549aba05..55506ae064799140073d9690b088b5540c367548 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -427,8 +427,6 @@ virDomainCreateLinux(virConnectPtr conn, return(NULL); } - printf("%s\n", sexpr); - ret = xend_create_sexpr(conn, sexpr); free(sexpr); if (ret != 0) { diff --git a/src/xend_internal.c b/src/xend_internal.c index 36045fc49244a5c15b70172fb8d3993d9f605ab2..caa04a7d93e0f7f7cc491a1fa130729d5a81da87 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -30,6 +30,7 @@ #include "libvirt.h" #include "internal.h" #include "sexpr.h" +#include "xml.h" #include "xend_internal.h" /** @@ -2102,3 +2103,181 @@ xend_log(virConnectPtr xend, char *buffer, size_t n_buffer) { return http2unix(xend_get(xend, "/xend/node/log", buffer, n_buffer)); } + +/** + * virDomainParseSExprDesc: + * @root: the root of the parsed S-Expression + * @name: output name of the domain + * + * Parse the xend sexp description and turn it into the XML format similar + * to the one unsed for creation. + * + * Returns the 0 terminated XML string or NULL in case of error. + * the caller must free() the returned value. + */ +static char * +virDomainParseSExprDesc(struct sexpr *root) { + char *ret; + struct sexpr *cur, *node; + const char *tmp; + virBuffer buf; + + if (root == NULL) { + /* ERROR */ + return(NULL); + } + ret = malloc(1000); + if (ret == NULL) + return(NULL); + buf.content = ret; + buf.size = 1000; + buf.use = 0; + + virBufferVSprintf(&buf, "\n", + sexpr_int(root, "domain/domid")); + tmp = sexpr_node(root, "domain/name"); + if (tmp == NULL) { + /* VIR_ERR_NO_NAME */ + goto error; + } + virBufferVSprintf(&buf, " %s\n", tmp); + tmp = sexpr_node(root, "domain/image/linux/kernel"); + if (tmp == NULL) { + /* + * TODO: we will need some fallback here for other guest OSes + */ + /* VIR_ERR_NO_KERNEL */ + goto error; + } + virBufferAdd(&buf, " \n", 7); + virBufferVSprintf(&buf, " linux\n"); + virBufferVSprintf(&buf, " %s\n", tmp); + tmp = sexpr_node(root, "domain/image/linux/ramdisk"); + if ((tmp != NULL) && (tmp[0] != 0)) + virBufferVSprintf(&buf, " %s\n", tmp); + tmp = sexpr_node(root, "domain/image/linux/root"); + if ((tmp != NULL) && (tmp[0] != 0)) + virBufferVSprintf(&buf, " %s\n", tmp); + tmp = sexpr_node(root, "domain/image/linux/args"); + if ((tmp != NULL) && (tmp[0] != 0)) + virBufferVSprintf(&buf, " %s\n", tmp); + virBufferAdd(&buf, " \n", 8); + virBufferVSprintf(&buf, " %d\n", + (int) (sexpr_u64(root, "domain/maxmem") << 10)); + virBufferVSprintf(&buf, " %d\n", + sexpr_int(root, "domain/vcpus")); + virBufferAdd(&buf, " \n", 12); + for (cur = root; cur->kind == SEXPR_CONS; cur = cur->cdr) { + node = cur->car; + if (sexpr_lookup(node, "device/vbd")) { + tmp = sexpr_node(node, "device/vbd/uname"); + if (tmp == NULL) + continue; + if (!memcmp(tmp, "file:", 5)) { + tmp += 5; + virBufferVSprintf(&buf, " \n"); + virBufferVSprintf(&buf, " \n", tmp); + tmp = sexpr_node(node, "device/vbd/dev"); + if (tmp == NULL) { + /* VIR_ERR_NO_DEV */ + goto error; + } + virBufferVSprintf(&buf, " \n", tmp); + tmp = sexpr_node(node, "device/vbd/mode"); + if ((tmp != NULL) && (!strcmp(tmp, "r"))) + virBufferVSprintf(&buf, " \n"); + virBufferAdd(&buf, " \n", 12); + } else if (!memcmp(tmp, "phy:", 4)) { + tmp += 4; + virBufferVSprintf(&buf, " \n"); + virBufferVSprintf(&buf, " \n", tmp); + tmp = sexpr_node(node, "device/vbd/dev"); + if (tmp == NULL) { + /* VIR_ERR_NO_DEV */ + goto error; + } + virBufferVSprintf(&buf, " \n", tmp); + tmp = sexpr_node(node, "device/vbd/mode"); + if ((tmp != NULL) && (!strcmp(tmp, "r"))) + virBufferVSprintf(&buf, " \n"); + virBufferAdd(&buf, " \n", 12); + } else { + char serial[1000]; + + TODO + sexpr2string(node, serial, 1000); + virBufferVSprintf(&buf, "\n", + serial); + TODO + } + } else if (sexpr_lookup(node, "device/vif")) { + tmp = sexpr_node(node, "device/vif/bridge"); + if (tmp != NULL) { + virBufferVSprintf(&buf, " \n"); + virBufferVSprintf(&buf, " \n", tmp); + tmp = sexpr_node(node, "device/vif/vifname"); + if (tmp != NULL) + virBufferVSprintf(&buf, " \n", tmp); + tmp = sexpr_node(node, "device/vif/mac"); + if (tmp != NULL) + virBufferVSprintf(&buf, " \n", tmp); + tmp = sexpr_node(node, "device/vif/ip"); + if (tmp != NULL) + virBufferVSprintf(&buf, " \n", tmp); + tmp = sexpr_node(node, "device/vif/script"); + if (tmp != NULL) + virBufferVSprintf(&buf, "