Francesco Romani has uploaded a new change for review. Change subject: virt: graphdev: make GraphicsDevice produce XML ......................................................................
virt: graphdev: make GraphicsDevice produce XML this patch lets the new GraphicsDevice class produce XML. Change-Id: I82e4414aa3efe7c756ba8ef9b7b47e591613a717 Signed-off-by: Francesco Romani <[email protected]> --- M tests/vmTests.py M vdsm/virt/vm.py 2 files changed, 117 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/95/26895/1 diff --git a/tests/vmTests.py b/tests/vmTests.py index 17967c2..533ea98 100644 --- a/tests/vmTests.py +++ b/tests/vmTests.py @@ -419,6 +419,15 @@ if vmConf['display'] == 'qxl': self.assertXML(domxml.dom, spiceChannelXML, 'devices/channel') + with FakeVM(vmConf) as fake: + dev = vm.GraphicsDevice.getDeviceFromConf(vmConf) + graph = vm.GraphicsDevice(vmConf, self.log, **dev) + self.assertXML(graph.getXML(), xml) + + if vmConf['display'] == 'qxl': + self.assertXML(graph.getSpiceVmcChannelsXML(), + spiceChannelXML) + def testBalloonXML(self): balloonXML = '<memballoon model="virtio"/>' dev = {'device': 'memballoon', 'type': 'balloon', diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py index 4d2594c..e0d7903 100644 --- a/vdsm/virt/vm.py +++ b/vdsm/virt/vm.py @@ -75,6 +75,7 @@ DISK_DEVICES = 'disk' NIC_DEVICES = 'interface' VIDEO_DEVICES = 'video' +GRAPHICS_DEVICES = 'graphics' SOUND_DEVICES = 'sound' CONTROLLER_DEVICES = 'controller' GENERAL_DEVICES = 'general' @@ -1376,7 +1377,32 @@ class GraphicsDevice(VmDevice): + __slots__ = ('device',) + LIBVIRT_PORT_AUTOSELECT = '-1' + + _LEGACY_MAPPING = { + 'displayPort': 'port', + 'displaySecurePort': 'tlsPort', + 'keyboardLayout': 'keymap', + 'spiceDisableTicketing': 'disableTicketing', + 'displayNetwork': 'displayNetwork', + 'spiceSecureChannels': 'spiceSecureChannels', + 'displayIp': 'displayIp', + } + + @staticmethod + def getDeviceFromConf(conf): + specParams = {} + for k, v in GraphicsDevice._LEGACY_MAPPING.iteritems(): + if k in conf: + specParams[v] = conf[k] + devType = 'spice' if conf['display'] == 'qxl' else 'vnc' + return { + 'type': GRAPHICS_DEVICES, + 'device': devType, + 'specParams': specParams + } @staticmethod def isSupportedDisplayType(vmParams): @@ -1395,6 +1421,62 @@ 'displayPort', 'displaySecurePort'): if port in dispParams: dispParams[port] = GraphicsDevice.LIBVIRT_PORT_AUTOSELECT + + def getSpiceVmcChannelsXML(self): + vmc = XMLElement('channel', type='spicevmc') + vmc.appendChildWithArgs('target', type='virtio', + name='com.redhat.spice.0') + return vmc + + 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.specParams.get('port', '-1'), + 'autoport': 'yes' + } + + for key in ('tlsPort', 'keymap'): + if key in self.specParams: + graphicsAttrs[key] = self.specParams[key] + + if not utils.tobool(self.specParams.get('disableTicketing', '')): + graphicsAttrs['passwd'] = '*****' + graphicsAttrs['passwdValidTo'] = '1970-01-01T00:00:01' + + graphics = XMLElement('graphics', **graphicsAttrs) + + # handle deprecated channel name in a smart way, + # not just chop 1st char! + if graphicsAttrs['type'] == 'spice': + if self.specParams.get('spiceSecureChannels'): + for chan in self.specParams['spiceSecureChannels'].split(','): + graphics.appendChildWithArgs('channel', name=chan[1:], + 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 BalloonDevice(VmDevice): @@ -1737,6 +1819,32 @@ 'truesize': 0}) return removables + def __legacyGraphics(self): + """ + Derives graphics device (if it's missing in vm.devices) from vm.conf. + Used for legacy engines (that don't use graphics framebuffer as a + device). + If there is a device already in vm.devices, then None is returned. + """ + graphics = None + if not self._getGraphicsDevices(): + graphics = GraphicsDevice.getDeviceFromConf(self.conf) + return graphics + + def _getGraphicsDevices(self): + """ + Returns graphics devices of a VM. If the VM has multiple devices, then + SPICE dev is returned as a first one. + """ + spice, others = [], [] + for dev in self.conf.get('devices', []): + if dev['type'] == GRAPHICS_DEVICES: + if dev['device'] == 'spice': + spice = [dev] + else: + others.append(dev) + return spice + others + def buildConfDevices(self): """ Return the "devices" section of this Vm's conf. -- To view, visit http://gerrit.ovirt.org/26895 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I82e4414aa3efe7c756ba8ef9b7b47e591613a717 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
