[virt-tools-list] [virt-manager PATCH 2/4] graphics: introduce listens.{type|address|network} parameters

Pavel Hrdina phrdina at redhat.com
Wed Sep 6 08:35:59 UTC 2017


Using "listens.*" allows better configuration of listen elements for
graphics devices.  Currently the only way how to configure a listen
type is to abuse "listen" parameter and there is no way how to configure
exact "network".

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 .../compare/virt-install-many-devices.xml          |  8 ++++++++
 tests/clitest.py                                   |  2 ++
 virtinst/cli.py                                    | 22 ++++++++++++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/tests/cli-test-xml/compare/virt-install-many-devices.xml b/tests/cli-test-xml/compare/virt-install-many-devices.xml
index d0ab6eec..48b215cf 100644
--- a/tests/cli-test-xml/compare/virt-install-many-devices.xml
+++ b/tests/cli-test-xml/compare/virt-install-many-devices.xml
@@ -249,6 +249,14 @@
       <image compression="off"/>
       <listen type="none"/>
     </graphics>
+    <graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
+      <image compression="off"/>
+      <listen type="address" address="1.2.3.4"/>
+    </graphics>
+    <graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
+      <image compression="off"/>
+      <listen type="network" network="default"/>
+    </graphics>
     <serial type="tcp">
       <source mode="bind" host="127.0.0.1" service="2222"/>
       <protocol type="telnet"/>
diff --git a/tests/clitest.py b/tests/clitest.py
index 56148cc0..2373b461 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -486,6 +486,8 @@ c.add_compare(""" \
 --graphics spice,gl=yes,listen=socket \
 --graphics spice,gl=yes,listen=none \
 --graphics spice,gl=yes,listen=none,rendernode=/dev/dri/foo \
+--graphics spice,listens0.type=address,listens0.address=1.2.3.4 \
+--graphics spice,listens0.type=network,listens0.network=default \
 \
 --controller usb,model=ich9-ehci1,address=0:0:4.7,index=0 \
 --controller usb,model=ich9-uhci1,address=0:0:4.0,index=0,master=0 \
diff --git a/virtinst/cli.py b/virtinst/cli.py
index ece9b86d..9f5fd214 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -2233,6 +2233,22 @@ class ParserGraphics(VirtCLIParser):
         else:
             inst.listen = val
 
+    def listens_find_inst_cb(self, inst, val, virtarg, can_edit):
+        graphics = inst
+        num = 0
+        if re.search("\d+", virtarg.key):
+            num = int(re.search("\d+", virtarg.key).group())
+
+        if can_edit:
+            while len(graphics.listens) < (num + 1):
+                graphics.add_listen()
+        try:
+            return graphics.listens[num]
+        except IndexError:
+            if not can_edit:
+                return None
+            raise
+
     def _parse(self, inst):
         if self.optstr == "none":
             self.guest.skip_default_graphics = True
@@ -2261,6 +2277,12 @@ ParserGraphics.add_arg(None, "type", cb=ParserGraphics.set_type_cb)
 ParserGraphics.add_arg("port", "port")
 ParserGraphics.add_arg("tlsPort", "tlsport")
 ParserGraphics.add_arg("listen", "listen", cb=ParserGraphics.set_listen_cb)
+ParserGraphics.add_arg("type", "listens[0-9]*.type",
+                       find_inst_cb=ParserGraphics.listens_find_inst_cb)
+ParserGraphics.add_arg("address", "listens[0-9]*.address",
+                       find_inst_cb=ParserGraphics.listens_find_inst_cb)
+ParserGraphics.add_arg("network", "listens[0-9]*.network",
+                       find_inst_cb=ParserGraphics.listens_find_inst_cb)
 ParserGraphics.add_arg(None, "keymap", cb=ParserGraphics.set_keymap_cb)
 ParserGraphics.add_arg("passwd", "password")
 ParserGraphics.add_arg("passwdValidTo", "passwordvalidto")
-- 
2.13.5




More information about the virt-tools-list mailing list