Francesco Romani has uploaded a new change for review.

Change subject: virt: graphdev: introduce the GraphicsDevice class
......................................................................

virt: graphdev: introduce the GraphicsDevice class

introduce the skeleton of the GraphicsDevice class
and move the grpahics parameters validation into it.

This patch adds little value on its own, but is
a necessary step toward the full-featured
GraphicsDevice class.

Change-Id: Ic4f8e527fd48d8635b61cdc14eed31b8992e4f6c
Signed-off-by: Francesco Romani <[email protected]>
---
M vdsm/API.py
M vdsm/virt/vm.py
2 files changed, 27 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/94/26894/1

diff --git a/vdsm/API.py b/vdsm/API.py
index 94b39b6..c718a11 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -251,17 +251,15 @@
                                                   'No space on /tmp?'}}
                     return errCode['createErr']
 
-            if vmParams.get('display') not in ('vnc', 'qxl', 'qxlnc'):
+            if 'nicModel' not in vmParams:
+                vmParams['nicModel'] = config.get('vars', 'nic_model')
+            if not vm.GraphicsDevice.isSupportedDisplayType(vmParams):
                 return {'status': {'code': errCode['createErr']
                                                   ['status']['code'],
                                    'message': 'Unknown display type %s' %
                                               vmParams.get('display')}}
-            if 'nicModel' not in vmParams:
-                vmParams['nicModel'] = config.get('vars', 'nic_model')
-            vmParams['displayIp'] = self._getNetworkIp(vmParams.get(
-                                                       'displayNetwork'))
-            vmParams['displayPort'] = '-1'   # selected by libvirt
-            vmParams['displaySecurePort'] = '-1'
+            vm.GraphicsDevice.adjustDisplayParams(
+                vmParams, self._getNetworkIp(vmParams.get('displayNetwork')))
             return self._cif.createVm(vmParams)
 
         except OSError as e:
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 521e33b..4d2594c 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -1375,6 +1375,28 @@
         return diskelem
 
 
+class GraphicsDevice(VmDevice):
+    LIBVIRT_PORT_AUTOSELECT = '-1'
+
+    @staticmethod
+    def isSupportedDisplayType(vmParams):
+        return vmParams.get('display') in ('vnc', 'qxl', 'qxlnc')
+
+    @staticmethod
+    def adjustDisplayParams(dispParams, displayIp=None):
+        """
+        Adjusts parameters of graphics on vm start:
+         - resets ports to be autoselected by libvirt,
+         - sets displayNetwork value according to vm display network.
+        """
+        if displayIp is not None:
+            dispParams['displayIp'] = displayIp
+        for port in ('port', 'tlsPort',
+                     'displayPort', 'displaySecurePort'):
+            if port in dispParams:
+                dispParams[port] = GraphicsDevice.LIBVIRT_PORT_AUTOSELECT
+
+
 class BalloonDevice(VmDevice):
     __slots__ = ('address',)
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic4f8e527fd48d8635b61cdc14eed31b8992e4f6c
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

Reply via email to