From 1ed4d292080115f83edf7369a928fdbb08c8c17c Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 12 Sep 2006 01:34:26 +0000 Subject: [PATCH] Allow setting of VNC port when creating domains --- ChangeLog | 7 ++++ src/xml.c | 37 ++++++++++++++++--- tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr | 2 +- .../xml2sexpr-fv-vncunused.sexpr | 1 + .../xml2sexprdata/xml2sexpr-fv-vncunused.xml | 36 ++++++++++++++++++ tests/xml2sexprtest.c | 11 ++++++ 6 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 tests/xml2sexprdata/xml2sexpr-fv-vncunused.sexpr create mode 100644 tests/xml2sexprdata/xml2sexpr-fv-vncunused.xml diff --git a/ChangeLog b/ChangeLog index 3cba1c9e2a..448015a9f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Sep 11 20:37:28 EDT 2006 Daniel Berrange + + * src/xml.c: Added support for setting VNC port when creating + domains with new (version 2) style XenD config + * tests/xml2sexprtest.c: Added test for setting VNC port + * tests/xml2sexprdata/*vncunused*: Data files for new VNC test + Tue Sep 11 20:23:42 EDT 2006 Daniel Berrange * docs/Makefile.am: Added test XML files to EXTRA_DIST diff --git a/src/xml.c b/src/xml.c index 8623a5fce0..d644a43d91 100644 --- a/src/xml.c +++ b/src/xml.c @@ -574,6 +574,7 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) * virtDomainParseXMLGraphicsDesc: * @node: node containing graphics description * @buf: a buffer for the result S-Expr + * @xendConfigVersion: xend configuration file format * * Parse the graphics part of the XML description and add it to the S-Expr * in buf. This is a temporary interface as the S-Expr interface will be @@ -582,7 +583,7 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) * * Returns 0 in case of success, -1 in case of error */ -static int virDomainParseXMLGraphicsDesc(xmlNodePtr node, virBufferPtr buf) +static int virDomainParseXMLGraphicsDesc(xmlNodePtr node, virBufferPtr buf, int xendConfigVersion) { xmlChar *graphics_type = NULL; @@ -596,8 +597,22 @@ static int virDomainParseXMLGraphicsDesc(xmlNodePtr node, virBufferPtr buf) //virBufferAdd(buf, "(display localhost:10.0)", 24); //virBufferAdd(buf, "(xauthority /root/.Xauthority)", 30); } - else if (xmlStrEqual(graphics_type, BAD_CAST "vnc")) + else if (xmlStrEqual(graphics_type, BAD_CAST "vnc")) { + xmlChar *vncport = NULL; + long port; + virBufferAdd(buf, "(vnc 1)", 7); + if (xendConfigVersion >= 2) { + vncport = xmlGetProp(node, BAD_CAST "port"); + if (vncport != NULL) { + port = strtol((const char *)vncport, NULL, 10); + if (port == -1) + virBufferAdd(buf, "(vncunused 1)", 13); + else if (port > 5900) + virBufferVSprintf(buf, "(vncdisplay %d)", port - 5900); + } + } + } xmlFree(graphics_type); } return 0; @@ -771,7 +786,7 @@ virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics[1]", ctxt); if ((obj != NULL) && (obj->type == XPATH_NODESET) && (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) { - res = virDomainParseXMLGraphicsDesc(obj->nodesetval->nodeTab[0], buf); + res = virDomainParseXMLGraphicsDesc(obj->nodesetval->nodeTab[0], buf, xendConfigVersion); if (res != 0) { goto error; } @@ -792,6 +807,7 @@ error: * @node: node containing PV OS description * @buf: a buffer for the result S-Expr * @ctxt: a path context representing the XML description + * @xendConfigVersion: xend configuration file format * * Parse the OS part of the XML description for a paravirtualized domain * and add it to the S-Expr in buf. This is a temporary interface as the @@ -801,7 +817,7 @@ error: * Returns 0 in case of success, -1 in case of error. */ static int -virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr ctxt) +virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr ctxt, int xendConfigVersion) { xmlNodePtr cur, txt; xmlXPathObjectPtr obj = NULL; @@ -872,7 +888,7 @@ virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics[1]", ctxt); if ((obj != NULL) && (obj->type == XPATH_NODESET) && (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) { - res = virDomainParseXMLGraphicsDesc(obj->nodesetval->nodeTab[0], buf); + res = virDomainParseXMLGraphicsDesc(obj->nodesetval->nodeTab[0], buf, xendConfigVersion); if (res != 0) { goto error; } @@ -1234,7 +1250,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion) } if ((tmpobj == NULL) || !xmlStrEqual(tmpobj->stringval, BAD_CAST "hvm")) { - res = virDomainParseXMLOSDescPV(obj->nodesetval->nodeTab[0], &buf, ctxt); + res = virDomainParseXMLOSDescPV(obj->nodesetval->nodeTab[0], &buf, ctxt, xendConfigVersion); } else { hvm = 1; res = virDomainParseXMLOSDescHVM(obj->nodesetval->nodeTab[0], &buf, ctxt, xendConfigVersion); @@ -1364,3 +1380,12 @@ unsigned char *virParseUUID(char **ptr, const char *uuid) { error: return(dst_uuid); } + +/* + * Local variables: + * indent-tabs-mode: nil + * c-indent-level: 4 + * c-basic-offset: 4 + * tab-width: 4 + * End: + */ diff --git a/tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr b/tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr index 190c2182cc..0b7736abd4 100644 --- a/tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr +++ b/tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr @@ -1 +1 @@ -(vm (name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(acpi 1)(vnc 1)))(device (vbd (dev 'hdc:cdrom')(uname 'file:/root/boot.iso')(mode 'r')))(device (vbd (dev 'hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu)))) \ No newline at end of file +(vm (name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(acpi 1)(vnc 1)(vncdisplay 17)))(device (vbd (dev 'hdc:cdrom')(uname 'file:/root/boot.iso')(mode 'r')))(device (vbd (dev 'hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu)))) \ No newline at end of file diff --git a/tests/xml2sexprdata/xml2sexpr-fv-vncunused.sexpr b/tests/xml2sexprdata/xml2sexpr-fv-vncunused.sexpr new file mode 100644 index 0000000000..9ba7ae83be --- /dev/null +++ b/tests/xml2sexprdata/xml2sexpr-fv-vncunused.sexpr @@ -0,0 +1 @@ +(vm (name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(acpi 1)(vnc 1)(vncunused 1)))(device (vbd (dev 'hdc:cdrom')(uname 'file:/root/boot.iso')(mode 'r')))(device (vbd (dev 'hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu)))) \ No newline at end of file diff --git a/tests/xml2sexprdata/xml2sexpr-fv-vncunused.xml b/tests/xml2sexprdata/xml2sexpr-fv-vncunused.xml new file mode 100644 index 0000000000..b074d156f4 --- /dev/null +++ b/tests/xml2sexprdata/xml2sexpr-fv-vncunused.xml @@ -0,0 +1,36 @@ + + fvtest + b5d70dd275cdaca517769660b059d8bc + + hvm + /usr/lib/xen/boot/hvmloader + + + 409600 + 1 + destroy + restart + restart + + + + + /usr/lib64/xen/bin/qemu-dm + + + +