diff --git a/server/src/uds/services/OpenNebula/LiveService.py b/server/src/uds/services/OpenNebula/LiveService.py index d4d00d4a3..0b9df432b 100644 --- a/server/src/uds/services/OpenNebula/LiveService.py +++ b/server/src/uds/services/OpenNebula/LiveService.py @@ -40,7 +40,7 @@ from uds.core.ui import gui import logging -__updated__ = '2017-02-02' +__updated__ = '2017-03-28' logger = logging.getLogger(__name__) @@ -214,6 +214,13 @@ class LiveService(Service): ''' return self.parent().getMachineState(machineId) + def getMachineSubState(self, machineId): + ''' + On OpenNebula, the machine can be "active" but not "running". + Any active machine will have a LCM_STATE, that is what we get here + ''' + return self.parent().getMachineSubState(machineId) + def startMachine(self, machineId): ''' Tries to start a machine. No check is done, it is simply requested to OpenNebula. diff --git a/server/src/uds/services/OpenNebula/Provider.py b/server/src/uds/services/OpenNebula/Provider.py index f0300d2f7..b8717afff 100644 --- a/server/src/uds/services/OpenNebula/Provider.py +++ b/server/src/uds/services/OpenNebula/Provider.py @@ -50,7 +50,7 @@ import six # Python bindings for OpenNebula # import oca -__updated__ = '2016-11-24' +__updated__ = '2017-03-28' logger = logging.getLogger(__name__) @@ -188,6 +188,12 @@ class Provider(ServiceProvider): ''' return on.vm.getMachineState(self.api, machineId) + def getMachineSubState(self, machineId): + ''' + Returns the LCM_STATE of a machine (must be ready) + ''' + return on.vm.getMachineSubstate(self.api, machineId) + def startMachine(self, machineId): ''' diff --git a/server/src/uds/services/OpenNebula/on/vm.py b/server/src/uds/services/OpenNebula/on/vm.py index 8efde47d2..6777d0964 100644 --- a/server/src/uds/services/OpenNebula/on/vm.py +++ b/server/src/uds/services/OpenNebula/on/vm.py @@ -39,7 +39,7 @@ from defusedxml import minidom # Python bindings for OpenNebula from .common import VmState -__updated__ = '2017-03-03' +__updated__ = '2017-03-28' logger = logging.getLogger(__name__) @@ -66,6 +66,18 @@ def getMachineState(api, machineId): return VmState.UNKNOWN +def getMachineSubstate(api, machineId): + ''' + Returns the lcm_state + ''' + try: + return api.getVMSubState(machineId) + except Exception as e: + logger.error('Error obtaining machine state for {} on opennebula: {}'.format(machineId, e)) + + return VmState.UNKNOWN + + def startMachine(api, machineId): ''' Tries to start a machine. No check is done, it is simply requested to OpenNebula. diff --git a/server/src/uds/transports/SPICE/BaseSPICETransport.py b/server/src/uds/transports/SPICE/BaseSPICETransport.py index c2cafddce..b7d30e64e 100644 --- a/server/src/uds/transports/SPICE/BaseSPICETransport.py +++ b/server/src/uds/transports/SPICE/BaseSPICETransport.py @@ -44,7 +44,7 @@ from uds.services.OVirt.OVirtProvider import Provider as oVirtProvider import logging import os -__updated__ = '2017-02-21' +__updated__ = '2017-03-28' logger = logging.getLogger(__name__) @@ -99,8 +99,27 @@ class BaseSpiceTransport(Transport): Checks if the transport is available for the requested destination ip Override this in yours transports ''' - logger.debug('Checking availability for {0}'.format(ip)) - return True # Spice is available, no matter what IP machine has (even if it does not have one) + ready = self.cache.get(ip) + if ready is None: + userServiceInstance = userService.getInstance() + con = userServiceInstance.getConsoleConnection() + + logger.debug('Connection data: {}'.format(con)) + + port, secure_port = con['port'], con['secure_port'] + port = -1 if port is None else port + secure_port = -1 if secure_port is None else secure_port + + # test ANY of the ports + port_to_test = port if port != -1 else secure_port + if port_to_test == -1: + logger.info('SPICE didn\'t find has any port: {}'.format(con)) + return False + + if connection.testServer(ip, port_to_test) is True: + self.cache.put(ip, 'Y', READY_CACHE_TIMEOUT) + + return ready == 'Y' def processedUser(self, userService, userName): v = self.processUserPassword(userService, userName, '')