]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Allow setting of VNC port when creating domains
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Sep 2006 01:34:26 +0000 (01:34 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Sep 2006 01:34:26 +0000 (01:34 +0000)
ChangeLog
src/xml.c
tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr
tests/xml2sexprdata/xml2sexpr-fv-vncunused.sexpr [new file with mode: 0644]
tests/xml2sexprdata/xml2sexpr-fv-vncunused.xml [new file with mode: 0644]
tests/xml2sexprtest.c

index 3cba1c9e2adc85c09b3421daf22a42f98793b760..448015a9f1f5ce2e21d8604880a0020128ca4e48 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Sep 11 20:37:28 EDT 2006 Daniel Berrange <berrange@redhat.com>
+
+       * 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 <berrange@redhat.com>
 
        * docs/Makefile.am: Added test XML files to EXTRA_DIST
index 8623a5fce025b8a7079c2f8cc50c7bd58c1855d3..d644a43d91a00eaa437081dcdb5c328baca0e4db 100644 (file)
--- 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:
+ */
index 190c2182cc8e51402d4d62eb6a97343918a8aae8..0b7736abd40157418bf095236e95f6e288e63da0 100644 (file)
@@ -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 (file)
index 0000000..9ba7ae8
--- /dev/null
@@ -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 (file)
index 0000000..b074d15
--- /dev/null
@@ -0,0 +1,36 @@
+<domain type='xen'>
+  <name>fvtest</name>
+  <uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
+  <os>
+    <type>hvm</type>
+    <loader>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='hd'/>
+  </os>
+  <memory>409600</memory>
+  <vcpu>1</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <features>
+    <acpi/>
+  </features>
+  <devices>
+    <emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
+    <interface type='bridge'>
+      <source bridge='xenbr0'/>
+      <mac address='00:16:3e:1b:b1:47'/>
+      <script path='vif-bridge'/>
+    </interface>
+    <disk type='file' device='cdrom'>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc'/>
+      <readonly/>
+    </disk>
+    <disk type='file'>
+      <source file='/root/foo.img'/>
+      <target dev='ioemu:hda'/>
+    </disk>
+    <graphics type='vnc' port='-1'/>
+  </devices>
+</domain>
+
index 90b19d25a7bdc09432a544b47c4f675816a777c0..f5b0b28773d4abb68e6012f1b8cfbe720711c61e 100644 (file)
@@ -68,6 +68,13 @@ static int testCompareFVversion2(void *data ATTRIBUTE_UNUSED) {
                          2);
 }
 
+static int testCompareFVversion2VNC(void *data ATTRIBUTE_UNUSED) {
+  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-vncunused.xml",
+                          "xml2sexprdata/xml2sexpr-fv-vncunused.sexpr",
+                          "fvtest",
+                          2);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -96,5 +103,9 @@ main(int argc, char **argv)
                    1, testCompareFVversion2, NULL) != 0)
         ret = -1;
 
+    if (virtTestRun("XML-2-SEXPR FV config (format 2, VNC unused)",
+                    1, testCompareFVversion2VNC, NULL) != 0)
+        ret = -1;
+
     exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }