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

Re: [virt-tools-list] [PATCH 4 of 5] graphics: add spice channel configuration



On 11/15/2010 01:16 PM, Marc-André Lureau wrote:
> # HG changeset patch
> # User Marc-André Lureau <marcandre lureau 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

Hmm, yeah, the repetition here is unfortunate. spice graphics is the
first XML device to have a repeating child element, so we don't really
have an existing example in the code to deal with it.

The 'correct' (but equally overkill) way of handling this would be to
have a separate class VirtualGraphicsChannel, and have the parent device
keep a public list or dict of Channels. It would be the most extensible,
but probably the most code.

Or you could add a hack like:

    def _get_mode_prop(self, channel_type, channel_mode=None):
        xpath = "./channel[ name='%s']/@mode" % channel_type
        def get_mode(self):
            return self._channels.get(channel_type, None)
        def set_mode(self, val):
            self._channels[channel_type] = channel_mode
        return _xml_property(get_mode, set_mode, xpath=xpath)

    def get_channel_mode(self, channel_type):
        tmpprop = self._get_mode_prop(channel_type)
        return tmpprop.fget(self)
    def set_channel_mode(self, channel_type, channel_mode):
        tmpprop = self._get_mode_prop(channel_type, channel_mode)
        return tmpprop.fset(self, channel_mode)

which I'm fine with. Lightly tested to at least pass the xmlconfig.py tests.

Thanks,
Cole

> +    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):
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list redhat com
> https://www.redhat.com/mailman/listinfo/virt-tools-list


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