[virt-tools-list] [PATCH 4 of 5] graphics: add spice channel configuration
Marc-André Lureau
marcandre.lureau at redhat.com
Mon Nov 15 18:16:52 UTC 2010
# HG changeset patch
# User Marc-André Lureau <marcandre.lureau at redhat.com>
# Date 1289844915 -3600
# Node ID 815ba529139a23056ad68a679bf829de5ce9230a
# Parent 299b77681910133c3c519a5aa4b196061317cce6
graphics: add spice channel configuration
diff -r 299b77681910 -r 815ba529139a tests/xmlconfig-xml/boot-many-devices.xml
--- a/tests/xmlconfig-xml/boot-many-devices.xml Mon Nov 15 11:57:50 2010 +0100
+++ b/tests/xmlconfig-xml/boot-many-devices.xml Mon Nov 15 19:15:15 2010 +0100
@@ -50,7 +50,11 @@
<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'/>
+ <graphics type='spice' port='-1' tlsPort='-1' autoport='yes' keymap='en-us'>
+ <channel name='inputs' mode='secure'/>
+ <channel name='main' mode='any'/>
+ <channel name='record' mode='insecure'/>
+ </graphics>
<serial type='null'/>
<parallel type='unix'>
<source mode='bind' path='/tmp/foobar'/>
diff -r 299b77681910 -r 815ba529139a tests/xmlconfig.py
--- a/tests/xmlconfig.py Mon Nov 15 11:57:50 2010 +0100
+++ b/tests/xmlconfig.py Mon Nov 15 19:15:15 2010 +0100
@@ -896,9 +896,13 @@
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)
+
+ gdev3 = virtinst.VirtualGraphics(conn=g.conn, type="spice")
+ gdev3.set_channel_main_mode(virtinst.VirtualGraphics.CHANNEL_MODE_ANY)
+ gdev3.set_channel_record_mode(virtinst.VirtualGraphics.CHANNEL_MODE_INSECURE)
+ gdev3.set_channel_inputs_mode(virtinst.VirtualGraphics.CHANNEL_MODE_SECURE)
g.add_device(gdev3)
g.clock.offset = "localtime"
diff -r 299b77681910 -r 815ba529139a tests/xmlparse-xml/change-graphics-in.xml
--- a/tests/xmlparse-xml/change-graphics-in.xml Mon Nov 15 11:57:50 2010 +0100
+++ b/tests/xmlparse-xml/change-graphics-in.xml Mon Nov 15 19:15:15 2010 +0100
@@ -27,6 +27,11 @@
<graphics type="sdl" xauth="/tmp/.Xauthority" display="1:2"/>
<graphics type="rdp"/>
<graphics type="vnc" port="-1"/>
+ <graphics type="spice" passwd="foobar" port="100" tlsPort="101" listen="0.0.0.0">
+ <channel name='inputs' mode='insecure'/>
+ <channel name='main' mode='secure'/>
+ <channel name='record' mode='any'/>
+ </graphics>
</devices>
<seclabel type="static" model="selinux">
<label>foolabel</label>
diff -r 299b77681910 -r 815ba529139a tests/xmlparse-xml/change-graphics-out.xml
--- a/tests/xmlparse-xml/change-graphics-out.xml Mon Nov 15 11:57:50 2010 +0100
+++ b/tests/xmlparse-xml/change-graphics-out.xml Mon Nov 15 19:15:15 2010 +0100
@@ -27,6 +27,11 @@
<graphics type="sdl" xauth="/tmp/.Xauthority" display="1:2"/>
<graphics type="rdp"/>
<graphics type="vnc" port="-1"/>
+ <graphics type="spice" passwd="newpass" port="6000" tlsPort="6001" listen="1.2.3.4">
+ <channel name="inputs" mode="secure"/>
+ <channel name="main" mode="any"/>
+ <channel name="record" mode="insecure"/>
+ </graphics>
</devices>
<seclabel type="static" model="selinux">
<label>foolabel</label>
diff -r 299b77681910 -r 815ba529139a tests/xmlparse.py
--- a/tests/xmlparse.py Mon Nov 15 11:57:50 2010 +0100
+++ b/tests/xmlparse.py Mon Nov 15 19:15:15 2010 +0100
@@ -390,6 +390,7 @@
dev2 = guest.get_devices("graphics")[1]
dev3 = guest.get_devices("graphics")[2]
dev4 = guest.get_devices("graphics")[3]
+ dev5 = guest.get_devices("graphics")[4]
check = self._make_checker(dev1)
check("type", "vnc")
@@ -407,6 +408,16 @@
check("type", "vnc")
check("port", -1)
+ check = self._make_checker(dev5)
+ check("type", "spice")
+ check("passwd", "foobar", "newpass")
+ check("port", 100, 6000)
+ check("tlsPort", 101, 6001)
+ check("listen", "0.0.0.0", "1.2.3.4")
+ check("channel_inputs_mode", "insecure", "secure")
+ check("channel_main_mode", "secure", "any")
+ check("channel_record_mode", "any", "insecure")
+
self._alter_compare(guest.get_config_xml(), outfile)
def testAlterVideos(self):
diff -r 299b77681910 -r 815ba529139a virtinst/VirtualGraphics.py
--- a/virtinst/VirtualGraphics.py Mon Nov 15 11:57:50 2010 +0100
+++ b/virtinst/VirtualGraphics.py Mon Nov 15 19:15:15 2010 +0100
@@ -23,7 +23,7 @@
import _util
import VirtualDevice
import support
-from XMLBuilderDomain import _xml_property
+from XMLBuilderDomain import _xml_property, XMLBuilderDomain
from virtinst import _virtinst as _
class VirtualGraphics(VirtualDevice.VirtualDevice):
@@ -38,9 +38,23 @@
KEYMAP_LOCAL = "local"
+ CHANNEL_TYPE_MAIN = "main"
+ CHANNEL_TYPE_DISPLAY = "display"
+ CHANNEL_TYPE_INPUTS = "inputs"
+ CHANNEL_TYPE_CURSOR = "cursor"
+ CHANNEL_TYPE_PLAYBACK = "playback"
+ CHANNEL_TYPE_RECORD = "record"
+ channel_types = [CHANNEL_TYPE_MAIN, CHANNEL_TYPE_DISPLAY, CHANNEL_TYPE_INPUTS,
+ CHANNEL_TYPE_CURSOR, CHANNEL_TYPE_PLAYBACK, CHANNEL_TYPE_RECORD]
+
+ CHANNEL_MODE_SECURE = "secure"
+ CHANNEL_MODE_INSECURE = "insecure"
+ CHANNEL_MODE_ANY = "any"
+ channel_modes = [CHANNEL_MODE_SECURE, CHANNEL_MODE_INSECURE, CHANNEL_MODE_ANY]
+
def __init__(self, type=TYPE_VNC, port=-1, listen=None, passwd=None,
keymap=None, conn=None, parsexml=None, parsexmlnode=None,
- tlsPort=-1):
+ tlsPort=-1, channels={}):
VirtualDevice.VirtualDevice.__init__(self, conn,
parsexml, parsexmlnode)
@@ -51,6 +65,7 @@
self._listen = None
self._passwd = None
self._keymap = None
+ self._channels = {}
if self._is_parse():
return
@@ -61,6 +76,8 @@
self.keymap = keymap
self.listen = listen
self.passwd = passwd
+ self.channels = channels
+
def _default_keymap(self):
if (self.conn and
@@ -160,6 +177,49 @@
get_converter=int,
xpath="./@tlsPort")
+ # TODO: find a way to factorize this code
+ def get_channel_main_mode(self):
+ return self._channels.get(VirtualGraphics.CHANNEL_TYPE_MAIN, None)
+ def set_channel_main_mode(self, val):
+ self._channels[VirtualGraphics.CHANNEL_TYPE_MAIN] = val
+ channel_main_mode = _xml_property(get_channel_main_mode, set_channel_main_mode,
+ xpath="./channel[@name='main']/@mode")
+
+ def get_channel_display_mode(self):
+ return self._channels.get(VirtualGraphics.CHANNEL_TYPE_DISPLAY, None)
+ def set_channel_display_mode(self, val):
+ self._channels[VirtualGraphics.CHANNEL_TYPE_DISPLAY] = val
+ channel_display_mode = _xml_property(get_channel_display_mode, set_channel_display_mode,
+ xpath="./channel[@name='display']/@mode")
+
+ def get_channel_inputs_mode(self):
+ return self._channels.get(VirtualGraphics.CHANNEL_TYPE_INPUTS, None)
+ def set_channel_inputs_mode(self, val):
+ self._channels[VirtualGraphics.CHANNEL_TYPE_INPUTS] = val
+ channel_inputs_mode = _xml_property(get_channel_inputs_mode, set_channel_inputs_mode,
+ xpath="./channel[@name='inputs']/@mode")
+
+ def get_channel_cursor_mode(self):
+ return self._channels.get(VirtualGraphics.CHANNEL_TYPE_CURSOR, None)
+ def set_channel_cursor_mode(self, val):
+ self._channels[VirtualGraphics.CHANNEL_TYPE_CURSOR] = val
+ channel_cursor_mode = _xml_property(get_channel_cursor_mode, set_channel_cursor_mode,
+ xpath="./channel[@name='cursor']/@mode")
+
+ def get_channel_playback_mode(self):
+ return self._channels.get(VirtualGraphics.CHANNEL_TYPE_PLAYBACK, None)
+ def set_channel_playback_mode(self, val):
+ self._channels[VirtualGraphics.CHANNEL_TYPE_PLAYBACK] = val
+ channel_playback_mode = _xml_property(get_channel_playback_mode, set_channel_playback_mode,
+ xpath="./channel[@name='playback']/@mode")
+
+ def get_channel_record_mode(self):
+ return self._channels.get(VirtualGraphics.CHANNEL_TYPE_RECORD, None)
+ def set_channel_record_mode(self, val):
+ self._channels[VirtualGraphics.CHANNEL_TYPE_RECORD] = val
+ channel_record_mode = _xml_property(get_channel_record_mode, set_channel_record_mode,
+ xpath="./channel[@name='record']/@mode")
+
def valid_keymaps(self):
"""
Return a list of valid keymap values.
@@ -206,7 +266,18 @@
"%(autoport)s" % { "autoport" : autoportxml } + \
"%(keymapxml)s" % { "keymapxml" : keymapxml } + \
"%(listenxml)s" % { "listenxml" : listenxml } + \
- "%(passwdxml)s/>" % { "passwdxml" : passwdxml }
+ "%(passwdxml)s" % { "passwdxml" : passwdxml }
+ if len(self._channels) > 0:
+ xml += ">"
+ keys = self._channels.keys()
+ keys.sort()
+ for c in keys:
+ xml += "\n <channel " + \
+ "name='%(name)s' " % { "name" : c } + \
+ "mode='%(mode)s'/>" % { "mode" : self._channels[c] }
+ xml += "\n </graphics>"
+ else:
+ xml += "/>"
return xml
def _vnc_config(self):
More information about the virt-tools-list
mailing list