[virt-tools-list] [PATCH 1 of 4] graphics: add SPICE VirtualGraphics support

Marc-André Lureau marcandre.lureau at redhat.com
Wed Nov 17 15:54:56 UTC 2010


# HG changeset patch
# User Marc-André Lureau <marcandre.lureau at redhat.com>
# Date 1289995630 -3600
# Node ID 653af636a8d8062dae6783e1c0b9e51dea85e28e
# Parent  b2eec170e9fab6d1c920fd8e2f29cc7c3299d59d
graphics: add SPICE VirtualGraphics support

diff -r b2eec170e9fa -r 653af636a8d8 tests/xmlconfig-xml/boot-many-devices.xml
--- a/tests/xmlconfig-xml/boot-many-devices.xml	Wed Oct 27 13:11:47 2010 -0400
+++ b/tests/xmlconfig-xml/boot-many-devices.xml	Wed Nov 17 13:07:10 2010 +0100
@@ -50,6 +50,7 @@
     <graphics type='sdl' display=':3.4' xauth='/tmp/.Xauthority'/>
     <graphics type='vnc' port='-1' keymap='en-us'/>
     <graphics type='sdl' display=':3.4' xauth='/tmp/.Xauthority'/>
+    <graphics type='spice' port='-1' tlsPort='-1' autoport='yes' keymap='en-us'/>
     <serial type='null'/>
     <parallel type='unix'>
       <source mode='bind' path='/tmp/foobar'/>
diff -r b2eec170e9fa -r 653af636a8d8 tests/xmlconfig.py
--- a/tests/xmlconfig.py	Wed Oct 27 13:11:47 2010 -0400
+++ b/tests/xmlconfig.py	Wed Nov 17 13:07:10 2010 +0100
@@ -892,8 +892,10 @@
         gdev1 = virtinst.VirtualGraphics(conn=g.conn, type="vnc")
         gdev1.keymap = "en-us"
         gdev2 = virtinst.VirtualGraphics(conn=g.conn, type="sdl")
+        gdev3 = virtinst.VirtualGraphics(conn=g.conn, type="spice")
         g.add_device(gdev1)
         g.add_device(gdev2)
+        g.add_device(gdev3)
 
         g.clock.offset = "localtime"
 
diff -r b2eec170e9fa -r 653af636a8d8 virtinst/VirtualGraphics.py
--- a/virtinst/VirtualGraphics.py	Wed Oct 27 13:11:47 2010 -0400
+++ b/virtinst/VirtualGraphics.py	Wed Nov 17 13:07:10 2010 +0100
@@ -33,18 +33,21 @@
     TYPE_SDL = "sdl"
     TYPE_VNC = "vnc"
     TYPE_RDP = "rdp"
-    types = [TYPE_VNC, TYPE_SDL, TYPE_RDP]
+    TYPE_SPICE = "spice"
+    types = [TYPE_VNC, TYPE_SDL, TYPE_RDP, TYPE_SPICE]
 
     KEYMAP_LOCAL = "local"
 
     def __init__(self, type=TYPE_VNC, port=-1, listen=None, passwd=None,
-                 keymap=None, conn=None, parsexml=None, parsexmlnode=None):
+                 keymap=None, conn=None, parsexml=None, parsexmlnode=None,
+                 tlsPort=-1):
 
         VirtualDevice.VirtualDevice.__init__(self, conn,
                                              parsexml, parsexmlnode)
 
         self._type   = None
         self._port   = None
+        self._tlsPort= None
         self._listen = None
         self._passwd = None
         self._keymap = None
@@ -54,6 +57,7 @@
 
         self.type = type
         self.port = port
+        self.tlsPort = tlsPort
         self.keymap = keymap
         self.listen = listen
         self.passwd = passwd
@@ -136,6 +140,26 @@
     passwd = _xml_property(get_passwd, set_passwd,
                            xpath="./@passwd")
 
+    def get_tlsPort(self):
+        return self._tlsPort
+    def set_tlsPort(self, val):
+        if val is None:
+            val = -1
+
+        try:
+            val = int(val)
+        except:
+            pass
+
+        if (type(val) is not int or
+            (val != -1 and (val < 5900 or val > 65535))):
+            raise ValueError(_("TLS port must be a number between "
+                               "5900 and 65535, or -1 for auto allocation"))
+        self._tlsPort = val
+    tlsPort = _xml_property(get_tlsPort, set_tlsPort,
+                            get_converter=int,
+                            xpath="./@tlsPort")
+
     def valid_keymaps(self):
         """
         Return a list of valid keymap values.
@@ -162,9 +186,30 @@
         return """    <graphics type='sdl' display='%s' xauth='%s'/>""" % \
                (disp, xauth)
 
-    def _get_xml_config(self):
-        if self._type == self.TYPE_SDL:
-            return self._sdl_config()
+    def _spice_config(self):
+        autoportxml = ""
+        keymapxml = ""
+        listenxml = ""
+        passwdxml = ""
+        if self._port == -1 or self._tlsPort == -1:
+            autoportxml = "autoport='yes'"
+        if self.keymap:
+            keymapxml = " keymap='%s'" % self._keymap
+        if self.listen:
+            listenxml = " listen='%s'" % self._listen
+        if self.passwd:
+            passwdxml = " passwd='%s'" % self._passwd
+
+        xml = "    <graphics type='spice' " + \
+                   "port='%(port)d' " % { "port" : self._port } + \
+                   "tlsPort='%(tlsPort)d' " % { "tlsPort" : self._tlsPort } + \
+                   "%(autoport)s" % { "autoport" : autoportxml } + \
+                   "%(keymapxml)s" % { "keymapxml" : keymapxml } + \
+                   "%(listenxml)s" % { "listenxml" : listenxml } + \
+                   "%(passwdxml)s/>" % { "passwdxml" : passwdxml }
+        return xml
+
+    def _vnc_config(self):
         keymapxml = ""
         listenxml = ""
         passwdxml = ""
@@ -181,3 +226,13 @@
                    "%(passwdxml)s"   % { "passwdxml" : passwdxml } + \
                    "/>"
         return xml
+
+    def _get_xml_config(self):
+        if self._type == self.TYPE_SDL:
+            return self._sdl_config()
+        if self._type == self.TYPE_SPICE:
+            return self._spice_config()
+        if self._type == self.TYPE_VNC:
+            return self._vnc_config()
+        else:
+            raise ValueError(_("Unknown graphics type"))




More information about the virt-tools-list mailing list