mirror of
https://github.com/dkmstr/openuds.git
synced 2025-08-24 09:49:52 +03:00
Several fixes so we can check availability of spice transport BEFORE
user tries to access it.
This commit is contained in:
@ -40,7 +40,7 @@ from uds.core.ui import gui
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
__updated__ = '2017-02-02'
|
__updated__ = '2017-03-28'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -214,6 +214,13 @@ class LiveService(Service):
|
|||||||
'''
|
'''
|
||||||
return self.parent().getMachineState(machineId)
|
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):
|
def startMachine(self, machineId):
|
||||||
'''
|
'''
|
||||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula.
|
Tries to start a machine. No check is done, it is simply requested to OpenNebula.
|
||||||
|
@ -50,7 +50,7 @@ import six
|
|||||||
# Python bindings for OpenNebula
|
# Python bindings for OpenNebula
|
||||||
# import oca
|
# import oca
|
||||||
|
|
||||||
__updated__ = '2016-11-24'
|
__updated__ = '2017-03-28'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -188,6 +188,12 @@ class Provider(ServiceProvider):
|
|||||||
'''
|
'''
|
||||||
return on.vm.getMachineState(self.api, machineId)
|
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):
|
def startMachine(self, machineId):
|
||||||
'''
|
'''
|
||||||
|
@ -40,10 +40,10 @@ import re
|
|||||||
import logging
|
import logging
|
||||||
import six
|
import six
|
||||||
|
|
||||||
import xmlrpclib
|
import six
|
||||||
from uds.core.util import xml2dict
|
from uds.core.util import xml2dict
|
||||||
|
|
||||||
__updated__ = '2017-03-27'
|
__updated__ = '2017-03-28'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -64,6 +64,7 @@ from . import template
|
|||||||
from . import vm
|
from . import vm
|
||||||
from . import storage
|
from . import storage
|
||||||
|
|
||||||
|
|
||||||
# Decorator
|
# Decorator
|
||||||
def ensureConnected(fnc):
|
def ensureConnected(fnc):
|
||||||
def inner(*args, **kwargs):
|
def inner(*args, **kwargs):
|
||||||
@ -71,19 +72,22 @@ def ensureConnected(fnc):
|
|||||||
return fnc(*args, **kwargs)
|
return fnc(*args, **kwargs)
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
|
||||||
# Result checker
|
# Result checker
|
||||||
def checkResult(lst, parseResult=True):
|
def checkResult(lst, parseResult=True):
|
||||||
if lst[0] == False:
|
if not lst[0]:
|
||||||
raise Exception('OpenNebula error {}: "{}"'.format(lst[2], lst[1]))
|
raise Exception('OpenNebula error {}: "{}"'.format(lst[2], lst[1]))
|
||||||
if parseResult:
|
if parseResult:
|
||||||
return xml2dict.parse(lst[1])
|
return xml2dict.parse(lst[1])
|
||||||
else:
|
else:
|
||||||
return lst[1]
|
return lst[1]
|
||||||
|
|
||||||
|
|
||||||
def asList(element):
|
def asList(element):
|
||||||
if isinstance(element, (tuple, list)):
|
if isinstance(element, (tuple, list)):
|
||||||
return element
|
return element
|
||||||
return (element,)
|
return element,
|
||||||
|
|
||||||
|
|
||||||
class OpenNebulaClient(object):
|
class OpenNebulaClient(object):
|
||||||
def __init__(self, username, password, endpoint):
|
def __init__(self, username, password, endpoint):
|
||||||
@ -111,7 +115,7 @@ class OpenNebulaClient(object):
|
|||||||
if self.connection is not None:
|
if self.connection is not None:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.connection = xmlrpclib.ServerProxy(self.endpoint)
|
self.connection = six.moves.xmlrpc_client.ServerProxy(self.endpoint) # @UndefinedVariable
|
||||||
|
|
||||||
@ensureConnected
|
@ensureConnected
|
||||||
def enumStorage(self, storageType=0):
|
def enumStorage(self, storageType=0):
|
||||||
@ -297,12 +301,20 @@ class OpenNebulaClient(object):
|
|||||||
return int(checkResult(result)['VM']['STATE'])
|
return int(checkResult(result)['VM']['STATE'])
|
||||||
|
|
||||||
@ensureConnected
|
@ensureConnected
|
||||||
def getVMLCMState(self, vmId):
|
def getVMSubstate(self, vmId):
|
||||||
'''
|
'''
|
||||||
Returns the VM State
|
Returns the VM State
|
||||||
'''
|
'''
|
||||||
result = self.connection.one.vm.info(self.sessionString, int(vmId))
|
result = self.connection.one.vm.info(self.sessionString, int(vmId))
|
||||||
return int(checkResult(result)['VM']['LCM_STATE'])
|
r = checkResult(result)
|
||||||
|
try:
|
||||||
|
if int(r['VM']['STATE']) == VmState.ACTIVE:
|
||||||
|
return int(r['VM']['LCM_STATE'])
|
||||||
|
# Substate is not available if VM state is not active
|
||||||
|
return -1
|
||||||
|
except Exception:
|
||||||
|
logger.exception('getVMSubstate')
|
||||||
|
return -1
|
||||||
|
|
||||||
@ensureConnected
|
@ensureConnected
|
||||||
def VMAction(self, vmId, action):
|
def VMAction(self, vmId, action):
|
||||||
|
@ -39,7 +39,7 @@ from defusedxml import minidom
|
|||||||
# Python bindings for OpenNebula
|
# Python bindings for OpenNebula
|
||||||
from .common import VmState
|
from .common import VmState
|
||||||
|
|
||||||
__updated__ = '2017-03-03'
|
__updated__ = '2017-03-28'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -66,6 +66,18 @@ def getMachineState(api, machineId):
|
|||||||
return VmState.UNKNOWN
|
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):
|
def startMachine(api, machineId):
|
||||||
'''
|
'''
|
||||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula.
|
Tries to start a machine. No check is done, it is simply requested to OpenNebula.
|
||||||
|
@ -44,7 +44,7 @@ from uds.services.OVirt.OVirtProvider import Provider as oVirtProvider
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
__updated__ = '2017-02-21'
|
__updated__ = '2017-03-28'
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -99,8 +99,27 @@ class BaseSpiceTransport(Transport):
|
|||||||
Checks if the transport is available for the requested destination ip
|
Checks if the transport is available for the requested destination ip
|
||||||
Override this in yours transports
|
Override this in yours transports
|
||||||
'''
|
'''
|
||||||
logger.debug('Checking availability for {0}'.format(ip))
|
ready = self.cache.get(ip)
|
||||||
return True # Spice is available, no matter what IP machine has (even if it does not have one)
|
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):
|
def processedUser(self, userService, userName):
|
||||||
v = self.processUserPassword(userService, userName, '')
|
v = self.processUserPassword(userService, userName, '')
|
||||||
|
Reference in New Issue
Block a user