[PATCHv2 3/4] conf: add listenNetwork attribute to domain graphics element

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Once it's plugged in, listenNetwork will be an optional replacement
for the "listen" attribute. While listen can be a host name or IP
address, listenNetwork names one of the networks managed by libvirt
(with virNetwork*()/visrh net-*).
---
 docs/schemas/domain.rng                            |   33 ++++++++---
 src/conf/domain_conf.c                             |   60 +++++++++++++++++--
 src/conf/domain_conf.h                             |    3 +
 .../qemuxml2argv-graphics-listenNetwork.xml        |   30 ++++++++++
 tests/qemuxml2xmltest.c                            |    1 +
 5 files changed, 111 insertions(+), 16 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-listenNetwork.xml

diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index 07c63bd..42f3eb2 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -1241,9 +1241,14 @@
                 </attribute>
               </optional>
               <optional>
-                <attribute name="listen">
-                  <ref name="addrIPorName"/>
-                </attribute>
+                <choice>
+                  <attribute name="listen">
+                    <ref name="addrIPorName"/>
+                  </attribute>
+                  <attribute name="listenNetwork">
+                    <text/>
+                  </attribute>
+                </choice>
               </optional>
             </group>
             <group>
@@ -1300,9 +1305,14 @@
             </attribute>
           </optional>
           <optional>
-            <attribute name="listen">
-              <ref name="addrIPorName"/>
-            </attribute>
+            <choice>
+              <attribute name="listen">
+                <ref name="addrIPorName"/>
+              </attribute>
+              <attribute name="listenNetwork">
+                <text/>
+              </attribute>
+            </choice>
           </optional>
           <optional>
             <attribute name="passwd">
@@ -1461,9 +1471,14 @@
             </attribute>
           </optional>
           <optional>
-            <attribute name="listen">
-              <ref name="addrIPorName"/>
-            </attribute>
+            <choice>
+              <attribute name="listen">
+                <ref name="addrIPorName"/>
+              </attribute>
+              <attribute name="listenNetwork">
+                <text/>
+              </attribute>
+            </choice>
           </optional>
         </group>
         <group>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4c58633..035b743 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -633,6 +633,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
     switch (def->type) {
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
         VIR_FREE(def->data.vnc.listenAddr);
+        VIR_FREE(def->data.vnc.listenNetwork);
         VIR_FREE(def->data.vnc.socket);
         VIR_FREE(def->data.vnc.keymap);
         virDomainGraphicsAuthDefClear(&def->data.vnc.auth);
@@ -645,6 +646,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
 
     case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
         VIR_FREE(def->data.rdp.listenAddr);
+        VIR_FREE(def->data.rdp.listenNetwork);
         break;
 
     case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
@@ -653,6 +655,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
 
     case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
         VIR_FREE(def->data.spice.listenAddr);
+        VIR_FREE(def->data.spice.listenNetwork);
         VIR_FREE(def->data.spice.keymap);
         virDomainGraphicsAuthDefClear(&def->data.spice.auth);
         break;
@@ -4061,14 +4064,23 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, unsigned int flags)
             VIR_FREE(autoport);
         }
 
-        def->data.vnc.listenAddr = virXMLPropString(node, "listen");
         def->data.vnc.socket = virXMLPropString(node, "socket");
         def->data.vnc.keymap = virXMLPropString(node, "keymap");
 
-        if (def->data.vnc.listenAddr &&
-            !def->data.vnc.listenAddr[0])
+        def->data.vnc.listenAddr = virXMLPropString(node, "listen");
+        if (def->data.vnc.listenAddr && !def->data.vnc.listenAddr[0])
             VIR_FREE(def->data.vnc.listenAddr);
 
+        def->data.vnc.listenNetwork = virXMLPropString(node, "listenNetwork");
+        if (def->data.vnc.listenNetwork && !def->data.vnc.listenNetwork[0])
+            VIR_FREE(def->data.vnc.listenNetwork);
+
+        if (def->data.vnc.listenAddr && def->data.vnc.listenNetwork) {
+            virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+                                 "%s", _("Both listen and listenNetwork given in graphics element"));
+            goto error;
+        }
+
         if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth,
                                              def->type) < 0)
             goto error;
@@ -4138,6 +4150,17 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, unsigned int flags)
         if (def->data.rdp.listenAddr &&
             !def->data.rdp.listenAddr[0])
             VIR_FREE(def->data.rdp.listenAddr);
+
+        def->data.rdp.listenNetwork = virXMLPropString(node, "listenNetwork");
+        if (def->data.rdp.listenNetwork && !def->data.rdp.listenNetwork[0])
+            VIR_FREE(def->data.rdp.listenNetwork);
+
+        if (def->data.rdp.listenAddr && def->data.rdp.listenNetwork) {
+            virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+                                 "%s", _("Both listen and listenNetwork given in graphics element"));
+            goto error;
+        }
+
     } else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) {
         char *fullscreen = virXMLPropString(node, "fullscreen");
 
@@ -4199,13 +4222,21 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, unsigned int flags)
             VIR_FREE(autoport);
         }
 
-        def->data.spice.listenAddr = virXMLPropString(node, "listen");
         def->data.spice.keymap = virXMLPropString(node, "keymap");
-
-        if (def->data.spice.listenAddr &&
-            !def->data.spice.listenAddr[0])
+        def->data.spice.listenAddr = virXMLPropString(node, "listen");
+        if (def->data.spice.listenAddr && !def->data.spice.listenAddr[0])
             VIR_FREE(def->data.spice.listenAddr);
 
+        def->data.spice.listenNetwork = virXMLPropString(node, "listenNetwork");
+        if (def->data.spice.listenNetwork && !def->data.spice.listenNetwork[0])
+            VIR_FREE(def->data.spice.listenNetwork);
+
+        if (def->data.spice.listenAddr && def->data.spice.listenNetwork) {
+            virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+                                 "%s", _("Both listen and listenNetwork given in graphics element"));
+            goto error;
+        }
+
         if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth,
                                              def->type) < 0)
             goto error;
@@ -9431,6 +9462,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
             if (def->data.vnc.listenAddr)
                 virBufferAsprintf(buf, " listen='%s'",
                                   def->data.vnc.listenAddr);
+
+            if (def->data.vnc.listenNetwork) {
+                virBufferAsprintf(buf, " listenNetwork='%s'",
+                                  def->data.vnc.listenNetwork);
+            }
         }
 
         if (def->data.vnc.keymap)
@@ -9472,6 +9508,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
         if (def->data.rdp.listenAddr)
             virBufferAsprintf(buf, " listen='%s'", def->data.rdp.listenAddr);
 
+        if (def->data.rdp.listenNetwork) {
+            virBufferAsprintf(buf, " listenNetwork='%s'",
+                              def->data.rdp.listenNetwork);
+        }
+
         break;
 
     case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
@@ -9500,6 +9541,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
             virBufferAsprintf(buf, " listen='%s'",
                               def->data.spice.listenAddr);
 
+        if (def->data.spice.listenNetwork) {
+            virBufferAsprintf(buf, " listenNetwork='%s'",
+                              def->data.spice.listenNetwork);
+        }
+
         if (def->data.spice.keymap)
             virBufferEscapeString(buf, " keymap='%s'",
                                   def->data.spice.keymap);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9e9db41..7f05084 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -768,6 +768,7 @@ struct _virDomainGraphicsDef {
             int port;
             unsigned int autoport :1;
             char *listenAddr;
+            char *listenNetwork;
             char *keymap;
             char *socket;
             virDomainGraphicsAuthDef auth;
@@ -780,6 +781,7 @@ struct _virDomainGraphicsDef {
         struct {
             int port;
             char *listenAddr;
+            char *listenNetwork;
             unsigned int autoport :1;
             unsigned int replaceUser :1;
             unsigned int multiUser :1;
@@ -792,6 +794,7 @@ struct _virDomainGraphicsDef {
             int port;
             int tlsPort;
             char *listenAddr;
+            char *listenNetwork;
             char *keymap;
             virDomainGraphicsAuthDef auth;
             unsigned int autoport :1;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-listenNetwork.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listenNetwork.xml
new file mode 100644
index 0000000..f7757f1
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listenNetwork.xml
@@ -0,0 +1,30 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219100</memory>
+  <currentMemory>219100</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' unit='0'/>
+    </disk>
+    <controller type='ide' index='0'/>
+    <input type='mouse' bus='ps2'/>
+    <graphics type='vnc' port='5903' autoport='no' listenNetwork='Bobsnetwork'/>
+    <video>
+      <model type='cirrus' vram='9216' heads='1'/>
+    </video>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 6b1fbf5..e8b5ece 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -139,6 +139,7 @@ mymain(void)
     DO_TEST("disk-drive-cache-v1-wb");
     DO_TEST("disk-drive-cache-v1-none");
     DO_TEST("disk-scsi-device");
+    DO_TEST("graphics-listenNetwork");
     DO_TEST("graphics-vnc");
     DO_TEST("graphics-vnc-sasl");
     DO_TEST("graphics-vnc-tls");
-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]