Change in vdsm[master]: virt: move vm.GraphicsDevice -> vmdevices.Graphics

fromani at redhat.com fromani at redhat.com
Tue Oct 28 14:17:48 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: virt: move vm.GraphicsDevice -> vmdevices.Graphics
......................................................................

virt: move vm.GraphicsDevice -> vmdevices.Graphics

No code changes besides the renaming.
No changes in behaviour.

Change-Id: I8597ce1896b308204974b60f60a19cc52fca8e0b
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/vmTests.py
M vdsm/API.py
M vdsm/virt/vm.py
M vdsm/virt/vmdevices.py
4 files changed, 140 insertions(+), 132 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/57/34557/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index 8f3564c..9acbbc1 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -491,7 +491,7 @@
         with fake.VM(vmConf) as testvm:
             dev = (testvm.getConfGraphics() if isLegacy
                    else vmConf['devices'])[0]
-            graph = vm.GraphicsDevice(vmConf, self.log, **dev)
+            graph = vmdevices.Graphics(vmConf, self.log, **dev)
             self.assertXML(graph.getXML(), xml)
 
             if graph.device == 'spice':
@@ -1291,7 +1291,7 @@
             graphConf = {
                 'type': vmdevices.GRAPHICS, 'device': 'spice',
                 'port': '-1', 'tlsPort': '-1'}
-            graphDev = vm.GraphicsDevice(
+            graphDev = vmdevices.Graphics(
                 testvm.conf, testvm.log,
                 device='spice', port='-1', tlsPort='-1')
 
@@ -1635,18 +1635,18 @@
     def testGraphicsDeviceSanityLegacy(self):
         for conf in self.confDisplay:
             conf.update(self.conf)
-            self.assertTrue(vm.GraphicsDevice.isSupportedDisplayType(conf))
+            self.assertTrue(vmdevices.Graphics.isSupportedDisplayType(conf))
 
     def testGraphicsDeviceSanity(self):
         for dev in self.confDeviceGraphics:
             conf = {'display': 'qxl', 'devices': list(dev)}
             conf.update(self.conf)
-            self.assertTrue(vm.GraphicsDevice.isSupportedDisplayType(conf))
+            self.assertTrue(vmdevices.Graphics.isSupportedDisplayType(conf))
 
     def testGraphicDeviceUnsupported(self):
         conf = {'display': 'rdp'}
         conf.update(self.conf)
-        self.assertFalse(vm.GraphicsDevice.isSupportedDisplayType(conf))
+        self.assertFalse(vmdevices.Graphics.isSupportedDisplayType(conf))
 
     def testHasSpiceLegacy(self):
         for conf in self.confDisplaySpice:
diff --git a/vdsm/API.py b/vdsm/API.py
index 0e34f9b..f7d81dc 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -43,7 +43,6 @@
 import storage.volume
 import storage.sd
 import storage.image
-from virt import vm
 from virt import vmdevices
 from virt import vmstatus
 from vdsm.compat import pickle
@@ -252,7 +251,7 @@
                                                   'No space on /tmp?'}}
                     return errCode['createErr']
 
-            if not vm.GraphicsDevice.isSupportedDisplayType(vmParams):
+            if not vmdevices.Graphics.isSupportedDisplayType(vmParams):
                 return {'status': {'code': errCode['createErr']
                                                   ['status']['code'],
                                    'message': 'Unknown display type %s' %
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 3074f3d..f9e334a 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -1050,111 +1050,6 @@
         return diskelem
 
 
-class GraphicsDevice(vmdevices.Base):
-    __slots__ = ('device', 'port', 'tlsPort')
-
-    LIBVIRT_PORT_AUTOSELECT = '-1'
-
-    LEGACY_MAP = {
-        'keyboardLayout': 'keyMap',
-        'spiceDisableTicketing': 'disableTicketing',
-        'displayNetwork': 'displayNetwork',
-        'spiceSecureChannels': 'spiceSecureChannels',
-        'copyPasteEnable': 'copyPasteEnable'}
-
-    SPICE_CHANNEL_NAMES = (
-        'main', 'display', 'inputs', 'cursor', 'playback',
-        'record', 'smartcard', 'usbredir')
-
-    @staticmethod
-    def isSupportedDisplayType(vmParams):
-        if vmParams.get('display') not in ('vnc', 'qxl', 'qxlnc'):
-            return False
-        for dev in vmParams.get('devices', ()):
-            if dev['type'] == vmdevices.GRAPHICS:
-                if dev['device'] not in ('spice', 'vnc'):
-                    return False
-        return True
-
-    def __init__(self, conf, log, **kwargs):
-        super(GraphicsDevice, self).__init__(conf, log, **kwargs)
-        self.port = self.LIBVIRT_PORT_AUTOSELECT
-        self.tlsPort = self.LIBVIRT_PORT_AUTOSELECT
-        self.specParams['displayIp'] = _getNetworkIp(
-            self.specParams.get('displayNetwork'))
-
-    def getSpiceVmcChannelsXML(self):
-        vmc = vmxml.Element('channel', type='spicevmc')
-        vmc.appendChildWithArgs('target', type='virtio',
-                                name='com.redhat.spice.0')
-        return vmc
-
-    def _getSpiceChannels(self):
-        for name in self.specParams['spiceSecureChannels'].split(','):
-            if name in GraphicsDevice.SPICE_CHANNEL_NAMES:
-                yield name
-            elif (name[0] == 's' and name[1:] in
-                  GraphicsDevice.SPICE_CHANNEL_NAMES):
-                # legacy, deprecated channel names
-                yield name[1:]
-            else:
-                self.log.error('unsupported spice channel name "%s"', name)
-
-    def getXML(self):
-        """
-        Create domxml for a graphics framebuffer.
-
-        <graphics type='spice' port='5900' tlsPort='5901' autoport='yes'
-                  listen='0' keymap='en-us'
-                  passwdValidTo='1970-01-01T00:00:01'>
-          <listen type='address' address='0'/>
-          <clipboard copypaste='no'/>
-        </graphics>
-        OR
-        <graphics type='vnc' port='5900' autoport='yes' listen='0'
-                  keymap='en-us' passwdValidTo='1970-01-01T00:00:01'>
-          <listen type='address' address='0'/>
-        </graphics>
-
-        """
-
-        graphicsAttrs = {
-            'type': self.device,
-            'port': self.port,
-            'autoport': 'yes'}
-
-        if self.device == 'spice':
-            graphicsAttrs['tlsPort'] = self.tlsPort
-
-        if not utils.tobool(self.specParams.get('disableTicketing', False)):
-            graphicsAttrs['passwd'] = '*****'
-            graphicsAttrs['passwdValidTo'] = '1970-01-01T00:00:01'
-
-        if 'keyMap' in self.specParams:
-            graphicsAttrs['keymap'] = self.specParams['keyMap']
-
-        graphics = vmxml.Element('graphics', **graphicsAttrs)
-
-        if not utils.tobool(self.specParams.get('copyPasteEnable', True)):
-            clipboard = vmxml.Element('clipboard', copypaste='no')
-            graphics.appendChild(clipboard)
-
-        if (self.device == 'spice' and
-           'spiceSecureChannels' in self.specParams):
-            for chan in self._getSpiceChannels():
-                graphics.appendChildWithArgs('channel', name=chan,
-                                             mode='secure')
-
-        if self.specParams.get('displayNetwork'):
-            graphics.appendChildWithArgs('listen', type='network',
-                                         network=netinfo.LIBVIRT_NET_PREFIX +
-                                         self.specParams.get('displayNetwork'))
-        else:
-            graphics.setAttrs(listen='0')
-
-        return graphics
-
-
 class MigrationError(Exception):
     pass
 
@@ -1185,7 +1080,7 @@
                      (vmdevices.NIC, NetworkInterfaceDevice),
                      (vmdevices.SOUND, vmdevices.Sound),
                      (vmdevices.VIDEO, vmdevices.VideoDevice),
-                     (vmdevices.GRAPHICS, GraphicsDevice),
+                     (vmdevices.GRAPHICS, vmdevices.Graphics),
                      (vmdevices.CONTROLLER, vmdevices.Controller),
                      (vmdevices.GENERAL, vmdevices.Generic),
                      (vmdevices.BALLOON, vmdevices.Balloon),
@@ -1489,7 +1384,8 @@
         def makeSpecParams(conf):
             return dict(
                 (newName, conf[oldName])
-                for oldName, newName in GraphicsDevice.LEGACY_MAP.iteritems()
+                for oldName, newName in (
+                    vmdevices.Graphics.LEGACY_MAP.iteritems())
                 if oldName in conf)
 
         return [{
@@ -2330,9 +2226,9 @@
             return {
                 'type': dev['device'],
                 'port': dev.get(
-                    'port', GraphicsDevice.LIBVIRT_PORT_AUTOSELECT),
+                    'port', vmdevices.Graphics.LIBVIRT_PORT_AUTOSELECT),
                 'tlsPort': dev.get(
-                    'tlsPort', GraphicsDevice.LIBVIRT_PORT_AUTOSELECT),
+                    'tlsPort', vmdevices.Graphics.LIBVIRT_PORT_AUTOSELECT),
                 'ipAddress': dev.get('specParams', {}).get('displayIp', 0)}
 
         return {
@@ -5306,10 +5202,10 @@
         device['volumeChain'] = drive.volumeChain = newChain
 
     def _initLegacyConf(self):
-        self.conf['displayPort'] = GraphicsDevice.LIBVIRT_PORT_AUTOSELECT
+        self.conf['displayPort'] = vmdevices.Graphics.LIBVIRT_PORT_AUTOSELECT
         self.conf['displaySecurePort'] = \
-            GraphicsDevice.LIBVIRT_PORT_AUTOSELECT
-        self.conf['displayIp'] = _getNetworkIp(
+            vmdevices.Graphics.LIBVIRT_PORT_AUTOSELECT
+        self.conf['displayIp'] = vmdevices._getNetworkIp(
             self.conf.get('displayNetwork'))
 
         dev = self._getFirstGraphicsDevice()
@@ -5418,16 +5314,3 @@
 
 def _devicesWithAlias(domXML):
     return vmxml.filter_devices_with_alias(vmxml.all_devices(domXML))
-
-
-def _getNetworkIp(network):
-    try:
-        nets = netinfo.networks()
-        device = nets[network].get('iface', network)
-        ip, _, _, _ = netinfo.getIpInfo(device)
-    except (libvirt.libvirtError, KeyError, IndexError):
-        ip = config.get('addresses', 'guests_gateway_ip')
-        if ip == '':
-            ip = '0'
-        logging.info('network %s: using %s', network, ip)
-    return ip
diff --git a/vdsm/virt/vmdevices.py b/vdsm/virt/vmdevices.py
index 33baca5..3c3303c 100644
--- a/vdsm/virt/vmdevices.py
+++ b/vdsm/virt/vmdevices.py
@@ -18,6 +18,14 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
+import logging
+
+import libvirt
+
+from vdsm import netinfo
+from vdsm import utils
+from vdsm.config import config
+
 import caps
 
 from . import vmxml
@@ -248,3 +256,121 @@
         m.setAttrs(model=self.specParams.get('model', 'i6300esb'),
                    action=self.specParams.get('action', 'none'))
         return m
+
+
+class Graphics(Base):
+    __slots__ = ('device', 'port', 'tlsPort')
+
+    LIBVIRT_PORT_AUTOSELECT = '-1'
+
+    LEGACY_MAP = {
+        'keyboardLayout': 'keyMap',
+        'spiceDisableTicketing': 'disableTicketing',
+        'displayNetwork': 'displayNetwork',
+        'spiceSecureChannels': 'spiceSecureChannels',
+        'copyPasteEnable': 'copyPasteEnable'}
+
+    SPICE_CHANNEL_NAMES = (
+        'main', 'display', 'inputs', 'cursor', 'playback',
+        'record', 'smartcard', 'usbredir')
+
+    @staticmethod
+    def isSupportedDisplayType(vmParams):
+        if vmParams.get('display') not in ('vnc', 'qxl', 'qxlnc'):
+            return False
+        for dev in vmParams.get('devices', ()):
+            if dev['type'] == GRAPHICS:
+                if dev['device'] not in ('spice', 'vnc'):
+                    return False
+        return True
+
+    def __init__(self, conf, log, **kwargs):
+        super(Graphics, self).__init__(conf, log, **kwargs)
+        self.port = self.LIBVIRT_PORT_AUTOSELECT
+        self.tlsPort = self.LIBVIRT_PORT_AUTOSELECT
+        self.specParams['displayIp'] = _getNetworkIp(
+            self.specParams.get('displayNetwork'))
+
+    def getSpiceVmcChannelsXML(self):
+        vmc = vmxml.Element('channel', type='spicevmc')
+        vmc.appendChildWithArgs('target', type='virtio',
+                                name='com.redhat.spice.0')
+        return vmc
+
+    def _getSpiceChannels(self):
+        for name in self.specParams['spiceSecureChannels'].split(','):
+            if name in Graphics.SPICE_CHANNEL_NAMES:
+                yield name
+            elif (name[0] == 's' and name[1:] in
+                  Graphics.SPICE_CHANNEL_NAMES):
+                # legacy, deprecated channel names
+                yield name[1:]
+            else:
+                self.log.error('unsupported spice channel name "%s"', name)
+
+    def getXML(self):
+        """
+        Create domxml for a graphics framebuffer.
+
+        <graphics type='spice' port='5900' tlsPort='5901' autoport='yes'
+                  listen='0' keymap='en-us'
+                  passwdValidTo='1970-01-01T00:00:01'>
+          <listen type='address' address='0'/>
+          <clipboard copypaste='no'/>
+        </graphics>
+        OR
+        <graphics type='vnc' port='5900' autoport='yes' listen='0'
+                  keymap='en-us' passwdValidTo='1970-01-01T00:00:01'>
+          <listen type='address' address='0'/>
+        </graphics>
+
+        """
+
+        graphicsAttrs = {
+            'type': self.device,
+            'port': self.port,
+            'autoport': 'yes'}
+
+        if self.device == 'spice':
+            graphicsAttrs['tlsPort'] = self.tlsPort
+
+        if not utils.tobool(self.specParams.get('disableTicketing', False)):
+            graphicsAttrs['passwd'] = '*****'
+            graphicsAttrs['passwdValidTo'] = '1970-01-01T00:00:01'
+
+        if 'keyMap' in self.specParams:
+            graphicsAttrs['keymap'] = self.specParams['keyMap']
+
+        graphics = vmxml.Element('graphics', **graphicsAttrs)
+
+        if not utils.tobool(self.specParams.get('copyPasteEnable', True)):
+            clipboard = vmxml.Element('clipboard', copypaste='no')
+            graphics.appendChild(clipboard)
+
+        if (self.device == 'spice' and
+           'spiceSecureChannels' in self.specParams):
+            for chan in self._getSpiceChannels():
+                graphics.appendChildWithArgs('channel', name=chan,
+                                             mode='secure')
+
+        if self.specParams.get('displayNetwork'):
+            graphics.appendChildWithArgs('listen', type='network',
+                                         network=netinfo.LIBVIRT_NET_PREFIX +
+                                         self.specParams.get('displayNetwork'))
+        else:
+            graphics.setAttrs(listen='0')
+
+        return graphics
+
+
+def _getNetworkIp(network):
+    try:
+        nets = netinfo.networks()
+        device = nets[network].get('iface', network)
+        ip, _, _, _ = netinfo.getIpInfo(device)
+    except (libvirt.libvirtError, KeyError, IndexError):
+        ip = config.get('addresses', 'guests_gateway_ip')
+        if ip == '':
+            ip = '0'
+        logging.info('network %s: using %s', network, ip)
+    return ip


-- 
To view, visit http://gerrit.ovirt.org/34557
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8597ce1896b308204974b60f60a19cc52fca8e0b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list