[virt-tools-list] [PATCH] Add VirtualCharSpicevmcDevice

Cole Robinson crobinso at redhat.com
Thu Mar 17 15:34:03 UTC 2011


On 03/15/2011 12:22 PM, Marc-André Lureau wrote:
> Here is an example of resulting XML:
> 
>     <channel type='spicevmc'>
>       <target type='virtio' name='com.redhat.spice.0'/>
>     </channel>

Can you split this into 2 patches? 1 adding spicevmc support and one
adding the address bits.

Also, please add a small section on --channel spicevmc in
man/en/virt-install.pod.in --channel section. Please mention the default
org.redhat.spice.0

Patch itself looks fine

Thanks,
Cole

> ---
>  tests/xmlconfig-xml/boot-many-devices.xml |    3 +
>  tests/xmlconfig.py                        |    4 ++
>  virtinst/VirtualCharDevice.py             |   79 +++++++++++++++++++++++-----
>  3 files changed, 72 insertions(+), 14 deletions(-)
> 
> diff --git a/tests/xmlconfig-xml/boot-many-devices.xml b/tests/xmlconfig-xml/boot-many-devices.xml
> index 602419d..47479c6 100644
> --- a/tests/xmlconfig-xml/boot-many-devices.xml
> +++ b/tests/xmlconfig-xml/boot-many-devices.xml
> @@ -57,6 +57,9 @@
>      <parallel type='unix'>
>        <source mode='bind' path='/tmp/foobar'/>
>      </parallel>
> +    <channel type='spicevmc'>
> +      <target type='virtio' name='com.redhat.spice.0'/>
> +    </channel>
>      <sound model='sb16'/>
>      <sound model='es1370'/>
>      <video>
> diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py
> index c281fad..5692cb5 100644
> --- a/tests/xmlconfig.py
> +++ b/tests/xmlconfig.py
> @@ -892,8 +892,12 @@ class TestXMLConfig(unittest.TestCase):
>                                                     VirtualCharDevice.DEV_PARALLEL,
>                                                     VirtualCharDevice.CHAR_UNIX)
>          cdev2.source_path = "/tmp/foobar"
> +        cdev3 = VirtualCharDevice.get_dev_instance(g.conn,
> +                                                   VirtualCharDevice.DEV_CHANNEL,
> +                                                   VirtualCharDevice.CHAR_SPICEVMC)
>          g.add_device(cdev1)
>          g.add_device(cdev2)
> +        g.add_device(cdev3)
>  
>          # Video Devices
>          vdev1 = VirtualVideoDevice(g.conn)
> diff --git a/virtinst/VirtualCharDevice.py b/virtinst/VirtualCharDevice.py
> index ae4ad58..517e814 100644
> --- a/virtinst/VirtualCharDevice.py
> +++ b/virtinst/VirtualCharDevice.py
> @@ -35,18 +35,20 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>      DEV_CHANNEL  = "channel"
>      dev_types    = [ DEV_SERIAL, DEV_PARALLEL, DEV_CONSOLE, DEV_CHANNEL]
>  
> -    CHAR_PTY    = "pty"
> -    CHAR_DEV    = "dev"
> -    CHAR_STDIO  = "stdio"
> -    CHAR_PIPE   = "pipe"
> -    CHAR_FILE   = "file"
> -    CHAR_VC     = "vc"
> -    CHAR_NULL   = "null"
> -    CHAR_TCP    = "tcp"
> -    CHAR_UDP    = "udp"
> -    CHAR_UNIX   = "unix"
> +    CHAR_PTY      = "pty"
> +    CHAR_DEV      = "dev"
> +    CHAR_STDIO    = "stdio"
> +    CHAR_PIPE     = "pipe"
> +    CHAR_FILE     = "file"
> +    CHAR_VC       = "vc"
> +    CHAR_NULL     = "null"
> +    CHAR_TCP      = "tcp"
> +    CHAR_UDP      = "udp"
> +    CHAR_UNIX     = "unix"
> +    CHAR_SPICEVMC = "spicevmc"
>      char_types  = [ CHAR_PTY, CHAR_DEV, CHAR_STDIO, CHAR_FILE, CHAR_VC,
> -                    CHAR_PIPE, CHAR_NULL, CHAR_TCP, CHAR_UDP, CHAR_UNIX ]
> +                    CHAR_PIPE, CHAR_NULL, CHAR_TCP, CHAR_UDP, CHAR_UNIX,
> +                    CHAR_SPICEVMC ]
>  
>      CHAR_MODE_CONNECT = "connect"
>      CHAR_MODE_BIND = "bind"
> @@ -61,6 +63,9 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>      target_types = [ CHAR_CHANNEL_TARGET_GUESTFWD,
>                       CHAR_CHANNEL_TARGET_VIRTIO ]
>  
> +    CHAR_CHANNEL_ADDRESS_VIRTIO_SERIAL = "virtio-serial"
> +    address_types = [ CHAR_CHANNEL_ADDRESS_VIRTIO_SERIAL ]
> +
>      CHAR_CONSOLE_TARGET_SERIAL = "serial"
>      CHAR_CONSOLE_TARGET_UML = "uml"
>      CHAR_CONSOLE_TARGET_XEN = "xen"
> @@ -92,6 +97,8 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>              desc = _("UDP net console")
>          elif char_type == VirtualCharDevice.CHAR_UNIX:
>              desc = _("Unix socket")
> +        elif char_type == VirtualCharDevice.CHAR_SPICEVMC:
> +            desc = _("Spice agent")
>  
>          return desc
>      get_char_type_desc = staticmethod(get_char_type_desc)
> @@ -144,6 +151,8 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>              c = VirtualCharUnixDevice
>          elif char_type == VirtualCharDevice.CHAR_UDP:
>              c = VirtualCharUdpDevice
> +        elif char_type == VirtualCharDevice.CHAR_SPICEVMC:
> +            c = VirtualCharSpicevmcDevice
>          else:
>              raise ValueError(_("Unknown character device type '%s'.") %
>                               char_type)
> @@ -176,6 +185,7 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>          self._bind_host = None
>          self._bind_port = None
>          self._protocol = self.CHAR_PROTOCOL_RAW
> +        self._address_type = None
>  
>          if self.char_type == self.CHAR_UDP:
>              self._source_mode = self.CHAR_MODE_CONNECT
> @@ -323,6 +333,17 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>                             doc=_("Sysfs Name of virtio port in the guest"),
>                             xpath="./target/@name")
>  
> +    def get_address_type(self):
> +        return self._address_type
> +    def set_address_type(self, val):
> +        if val not in self.address_types:
> +            raise ValueError(_("Unknown address type '%s'. Must be in: ") % val,
> +                             self.address_types)
> +        self._address_type = val
> +    address_type = _xml_property(get_address_type, set_address_type,
> +                                doc=_("Channel type as exposed in the guest."),
> +                                xpath="./address/@type")
> +
>      # XML building helpers
>      def _char_empty_xml(self):
>          """
> @@ -332,7 +353,7 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>  
>      def _char_file_xml(self):
>          """
> -        Provide source xml for devs that require only a patch (dev, pipe)
> +        Provide source xml for devs that require only a path (dev, pipe)
>          """
>          file_xml = ""
>          mode_xml = ""
> @@ -375,6 +396,15 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>          xml += "/>\n"
>          return xml
>  
> +    def _get_address_xml(self):
> +        xml = ""
> +        if not self.address_type:
> +            return xml
> +
> +        xml = "      <address type='%s'" % self.address_type
> +        xml += "/>\n"
> +        return xml
> +
>  
>      def _get_xml_config(self):
>          xml  = "    <%s type='%s'" % (self._dev_type, self._char_type)
> @@ -388,7 +418,14 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>                  "Target parameters not used with '%s' devices, only '%s'" %
>                  (self._dev_type, self.DEV_CHANNEL))
>  
> -        if char_xml or target_xml:
> +        address_xml = self._get_address_xml()
> +        has_address = self._target_type == self.CHAR_CHANNEL_TARGET_VIRTIO
> +        if address_xml and not has_address:
> +            raise RuntimeError(
> +                "Address parameters not used with '%s' target, only '%s'" %
> +                (self._target_type, self.CHAR_CHANNEL_TARGET_VIRTIO))
> +
> +        if char_xml or target_xml or address_xml:
>              xml += ">"
>              if char_xml:
>                  xml += "\n%s" % char_xml
> @@ -396,6 +433,9 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
>              if target_xml:
>                  xml += "\n%s" % target_xml
>  
> +            if address_xml:
> +                xml += "\n%s" % target_xml
> +
>              xml += "    </%s>" % self._dev_type
>          else:
>              xml += "/>"
> @@ -430,7 +470,6 @@ class VirtualCharNullDevice(VirtualCharDevice):
>  class VirtualCharVcDevice(VirtualCharDevice):
>      _char_type = VirtualCharDevice.CHAR_VC
>      _char_xml = VirtualCharDevice._char_empty_xml
> -
>  class VirtualCharDevDevice(VirtualCharDevice):
>      _char_type = VirtualCharDevice.CHAR_DEV
>      _char_xml = VirtualCharDevice._char_file_xml
> @@ -530,3 +569,15 @@ class VirtualCharUdpDevice(VirtualCharDevice):
>          xml += ("      <source mode='connect'%s service='%s'/>\n" %
>                  (source_host_xml, self.source_port))
>          return xml
> +
> +class VirtualCharSpicevmcDevice(VirtualCharDevice):
> +    _char_type = VirtualCharDevice.CHAR_SPICEVMC
> +    _char_xml = VirtualCharDevice._char_empty_xml
> +    target_types = [ VirtualCharDevice.CHAR_CHANNEL_TARGET_VIRTIO ]
> +
> +    def __init__(self, conn, dev_type,
> +                 parsexml=None, parsexmlnode=None, caps=None):
> +        VirtualCharDevice.__init__(self, conn, dev_type,
> +                                   parsexml, parsexmlnode, caps)
> +        self._target_type = VirtualCharDevice.CHAR_CHANNEL_TARGET_VIRTIO
> +        self._target_name = "com.redhat.spice.0"




More information about the virt-tools-list mailing list