mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Added reset to vdi
This commit is contained in:
parent
1d3d79c562
commit
4641fde008
@ -38,8 +38,7 @@ from .OVirtJobs import OVirtDeferredRemoval
|
||||
import pickle
|
||||
import logging
|
||||
|
||||
__updated__ = '2017-03-22'
|
||||
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -185,6 +184,13 @@ class OVirtLinkedDeployment(UserDeployment):
|
||||
self.cache.put('ready', '1')
|
||||
return State.FINISHED
|
||||
|
||||
def reset(self):
|
||||
'''
|
||||
o oVirt, reset operation just shutdowns it until v3 support is removed
|
||||
'''
|
||||
if self._vmid != '':
|
||||
self.service().stopMachine(self._vmid)
|
||||
|
||||
def getConsoleConnection(self):
|
||||
return self.service().getConsoleConnection(self._vmid)
|
||||
|
||||
|
@ -41,7 +41,7 @@ from uds.core.ui import gui
|
||||
|
||||
import logging
|
||||
|
||||
__updated__ = '2017-11-07'
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -88,6 +88,7 @@ class OVirtLinkedService(Service):
|
||||
# : If true, the system can't do an automatic assignation of a deployed user
|
||||
# : service from this service
|
||||
mustAssignManually = False
|
||||
canReset = True
|
||||
|
||||
# : Types of publications (preparated data for deploys)
|
||||
# : In our case, we do no need a publication, so this is None
|
||||
|
@ -39,8 +39,7 @@ from . import on
|
||||
import pickle
|
||||
import logging
|
||||
|
||||
__updated__ = '2017-03-27'
|
||||
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -181,6 +180,10 @@ class LiveDeployment(UserDeployment):
|
||||
self.cache.put('ready', '1')
|
||||
return State.FINISHED
|
||||
|
||||
def reset(self):
|
||||
if self._vmid != '':
|
||||
self.service().resetMachine(self._vmid)
|
||||
|
||||
def getConsoleConnection(self):
|
||||
return self.service().getConsoleConnection(self._vmid)
|
||||
|
||||
|
@ -40,7 +40,7 @@ from uds.core.ui import gui
|
||||
|
||||
import logging
|
||||
|
||||
__updated__ = '2017-03-28'
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -81,6 +81,7 @@ class LiveService(Service):
|
||||
# : If true, the system can't do an automatic assignation of a deployed user
|
||||
# : service from this service
|
||||
mustAssignManually = False
|
||||
canReset = True
|
||||
|
||||
# : Types of publications (preparated data for deploys)
|
||||
# : In our case, we do no need a publication, so this is None
|
||||
@ -107,7 +108,6 @@ class LiveService(Service):
|
||||
required=True
|
||||
)
|
||||
|
||||
|
||||
baseName = gui.TextField(
|
||||
label=_('Machine Names'),
|
||||
rdonly=False,
|
||||
@ -236,7 +236,7 @@ class LiveService(Service):
|
||||
|
||||
def stopMachine(self, machineId):
|
||||
'''
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula
|
||||
Tries to stop a machine. No check is done, it is simply requested to OpenNebula
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
@ -247,7 +247,7 @@ class LiveService(Service):
|
||||
|
||||
def suspendMachine(self, machineId):
|
||||
'''
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula
|
||||
Tries to suspend machine. No check is done, it is simply requested to OpenNebula
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
@ -256,6 +256,9 @@ class LiveService(Service):
|
||||
'''
|
||||
return self.parent().suspendMachine(machineId)
|
||||
|
||||
def resetMachine(self, machineId):
|
||||
return self.parent().resetMachine(machineId)
|
||||
|
||||
def removeMachine(self, machineId):
|
||||
'''
|
||||
Tries to delete a machine. No check is done, it is simply requested to OpenNebula
|
||||
|
@ -43,17 +43,17 @@ from defusedxml import minidom
|
||||
from .LiveService import LiveService
|
||||
from . import on
|
||||
|
||||
|
||||
import logging
|
||||
import six
|
||||
|
||||
# Python bindings for OpenNebula
|
||||
# import oca
|
||||
|
||||
__updated__ = '2017-03-28'
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Provider(ServiceProvider):
|
||||
'''
|
||||
This class represents the sample services provider
|
||||
@ -125,7 +125,6 @@ class Provider(ServiceProvider):
|
||||
def endpoint(self):
|
||||
return 'http{}://{}:{}/RPC2'.format('s' if self.ssl.isTrue() else '', self.host.value, self.port.value)
|
||||
|
||||
|
||||
@property
|
||||
def api(self):
|
||||
if self._api is None:
|
||||
@ -194,7 +193,6 @@ class Provider(ServiceProvider):
|
||||
'''
|
||||
return on.vm.getMachineSubstate(self.api, machineId)
|
||||
|
||||
|
||||
def startMachine(self, machineId):
|
||||
'''
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula.
|
||||
@ -207,6 +205,7 @@ class Provider(ServiceProvider):
|
||||
Returns:
|
||||
'''
|
||||
on.vm.startMachine(self.api, machineId)
|
||||
return True
|
||||
|
||||
def stopMachine(self, machineId):
|
||||
'''
|
||||
@ -218,6 +217,7 @@ class Provider(ServiceProvider):
|
||||
Returns:
|
||||
'''
|
||||
on.vm.stopMachine(self.api, machineId)
|
||||
return True
|
||||
|
||||
def suspendMachine(self, machineId):
|
||||
'''
|
||||
@ -229,6 +229,13 @@ class Provider(ServiceProvider):
|
||||
Returns:
|
||||
'''
|
||||
on.vm.suspendMachine(self.api, machineId)
|
||||
return True
|
||||
|
||||
def resetMachine(self, machineId):
|
||||
'''
|
||||
Resets a machine (hard-reboot)
|
||||
'''
|
||||
on.vm.resetMachine(self.api, machineId)
|
||||
|
||||
def removeMachine(self, machineId):
|
||||
'''
|
||||
@ -240,6 +247,7 @@ class Provider(ServiceProvider):
|
||||
Returns:
|
||||
'''
|
||||
on.vm.removeMachine(self.api, machineId)
|
||||
return True
|
||||
|
||||
def getNetInfo(self, machineId, networkId=None):
|
||||
'''
|
||||
@ -263,7 +271,6 @@ class Provider(ServiceProvider):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@staticmethod
|
||||
def test(env, data):
|
||||
'''
|
||||
|
@ -39,7 +39,7 @@ from defusedxml import minidom
|
||||
# Python bindings for OpenNebula
|
||||
from .common import VmState
|
||||
|
||||
__updated__ = '2017-03-28'
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -61,7 +61,7 @@ def getMachineState(api, machineId):
|
||||
# return vm.state
|
||||
return api.getVMState(machineId)
|
||||
except Exception as e:
|
||||
logger.error('Error obtaining machine state for {} on opennebula: {}'.format(machineId, e))
|
||||
logger.error('Error obtaining machine state for {} on OpenNebula: {}'.format(machineId, e))
|
||||
|
||||
return VmState.UNKNOWN
|
||||
|
||||
@ -73,7 +73,7 @@ def getMachineSubstate(api, machineId):
|
||||
try:
|
||||
return api.getVMSubState(machineId)
|
||||
except Exception as e:
|
||||
logger.error('Error obtaining machine state for {} on opennebula: {}'.format(machineId, e))
|
||||
logger.error('Error obtaining machine state for {} on OpenNebula: {}'.format(machineId, e))
|
||||
|
||||
return VmState.UNKNOWN
|
||||
|
||||
@ -90,13 +90,12 @@ def startMachine(api, machineId):
|
||||
Returns:
|
||||
'''
|
||||
try:
|
||||
# vm = oca.VirtualMachine.new_with_id(api, int(machineId))
|
||||
# vm.resume()
|
||||
api.VMAction(machineId, 'resume')
|
||||
except Exception as e:
|
||||
# logger.error('Error obtaining machine state for {} on opennebula: {}'.format(machineId, e))
|
||||
# MAybe the machine is already running. If we get error here, simply ignore it for now...
|
||||
pass
|
||||
|
||||
|
||||
def stopMachine(api, machineId):
|
||||
'''
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula
|
||||
@ -107,23 +106,40 @@ def stopMachine(api, machineId):
|
||||
Returns:
|
||||
'''
|
||||
try:
|
||||
# vm = oca.VirtualMachine.new_with_id(api, int(machineId))
|
||||
# vm.poweroff_hard()
|
||||
api.VMAction(machineId, 'poweroff-hard')
|
||||
except Exception as e:
|
||||
logger.error('Error obtaining machine state for {} on opennebula: {}'.format(machineId, e))
|
||||
logger.error('Error powering off {} on OpenNebula: {}'.format(machineId, e))
|
||||
|
||||
|
||||
def suspendMachine(api, machineId):
|
||||
'''
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula
|
||||
Tries to suspend a machine. No check is done, it is simply requested to OpenNebula
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
startMachine(api, machineId)
|
||||
try:
|
||||
api.VMAction(machineId, 'suspend')
|
||||
except Exception as e:
|
||||
logger.error('Error suspending {} on OpenNebula: {}'.format(machineId, e))
|
||||
|
||||
|
||||
def resetMachine(api, machineId):
|
||||
'''
|
||||
Tries to suspend a machine. No check is done, it is simply requested to OpenNebula
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
try:
|
||||
api.VMAction(machineId, 'reboot-hard')
|
||||
except Exception as e:
|
||||
logger.error('Error reseting {} on OpenNebula: {}'.format(machineId, e))
|
||||
|
||||
|
||||
def removeMachine(api, machineId):
|
||||
'''
|
||||
@ -139,8 +155,8 @@ def removeMachine(api, machineId):
|
||||
# vm.delete()
|
||||
api.deleteVM(machineId)
|
||||
except Exception as e:
|
||||
logger.exception('Error removing machine {} on opennebula: {}'.format(machineId, e))
|
||||
raise 'Error removing machine {} on opennebula: {}'.format(machineId, e)
|
||||
logger.exception('Error removing machine {} on OpenNebula: {}'.format(machineId, e))
|
||||
raise 'Error removing machine {} on OpenNebula: {}'.format(machineId, e)
|
||||
|
||||
|
||||
def enumerateMachines(api):
|
||||
@ -191,6 +207,7 @@ def getNetInfo(api, machineId, networkId=None):
|
||||
except Exception:
|
||||
raise Exception('No network interface found on template. Please, add a network and republish.')
|
||||
|
||||
|
||||
def getDisplayConnection(api, machineId):
|
||||
'''
|
||||
If machine is not running or there is not a display, will return NONE
|
||||
@ -218,8 +235,6 @@ def getDisplayConnection(api, machineId):
|
||||
except Exception:
|
||||
return None # No SPICE connection
|
||||
|
||||
|
||||
|
||||
# Sample NIC Content (there will be as much as nics)
|
||||
# <NIC>
|
||||
# <BRIDGE><![CDATA[br0]]></BRIDGE>
|
||||
@ -234,5 +249,3 @@ def getDisplayConnection(api, machineId):
|
||||
# <VLAN><![CDATA[NO]]></VLAN>
|
||||
# </NIC>
|
||||
|
||||
|
||||
|
||||
|
@ -39,7 +39,7 @@ from . import openStack
|
||||
import pickle
|
||||
import logging
|
||||
|
||||
__updated__ = '2017-11-21'
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -190,6 +190,10 @@ class LiveDeployment(UserDeployment):
|
||||
self.cache.put('ready', '1')
|
||||
return State.FINISHED
|
||||
|
||||
def reset(self):
|
||||
if self._vmid != '':
|
||||
self.service().resetMachine(self._vmid)
|
||||
|
||||
def getConsoleConnection(self):
|
||||
return self.service().getConsoleConnection(self._vmid)
|
||||
|
||||
|
@ -42,7 +42,7 @@ from uds.core.ui import gui
|
||||
import six
|
||||
import logging
|
||||
|
||||
__updated__ = '2017-05-16'
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -85,6 +85,7 @@ class LiveService(Service):
|
||||
# : If true, the system can't do an automatic assignation of a deployed user
|
||||
# : service from this service
|
||||
mustAssignManually = False
|
||||
canReset = True
|
||||
|
||||
# : Types of publications (preparated data for deploys)
|
||||
# : In our case, we do no need a publication, so this is None
|
||||
@ -161,7 +162,6 @@ class LiveService(Service):
|
||||
|
||||
self._api = None
|
||||
|
||||
|
||||
def initGui(self):
|
||||
'''
|
||||
Loads required values inside
|
||||
@ -270,7 +270,7 @@ class LiveService(Service):
|
||||
|
||||
Returns:
|
||||
'''
|
||||
return self.api.startServer(machineId)
|
||||
self.api.startServer(machineId)
|
||||
|
||||
def stopMachine(self, machineId):
|
||||
'''
|
||||
@ -281,7 +281,18 @@ class LiveService(Service):
|
||||
|
||||
Returns:
|
||||
'''
|
||||
return self.api.stopServer(machineId)
|
||||
self.api.stopServer(machineId)
|
||||
|
||||
def resetMachine(self, machineId):
|
||||
'''
|
||||
Tries to stop a machine. No check is done, it is simply requested to OpenStack
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
self.api.resetServer(machineId)
|
||||
|
||||
def suspendMachine(self, machineId):
|
||||
'''
|
||||
@ -292,7 +303,7 @@ class LiveService(Service):
|
||||
|
||||
Returns:
|
||||
'''
|
||||
return self.api.suspendServer(machineId)
|
||||
self.api.suspendServer(machineId)
|
||||
|
||||
def resumeMachine(self, machineId):
|
||||
'''
|
||||
@ -303,8 +314,7 @@ class LiveService(Service):
|
||||
|
||||
Returns:
|
||||
'''
|
||||
return self.api.suspendServer(machineId)
|
||||
|
||||
self.api.resumeServer(machineId)
|
||||
|
||||
def removeMachine(self, machineId):
|
||||
'''
|
||||
@ -315,7 +325,7 @@ class LiveService(Service):
|
||||
|
||||
Returns:
|
||||
'''
|
||||
return self.api.deleteServer(machineId)
|
||||
self.api.deleteServer(machineId)
|
||||
|
||||
def getNetInfo(self, machineId):
|
||||
'''
|
||||
|
@ -39,7 +39,7 @@ import json
|
||||
import dateutil.parser
|
||||
import six
|
||||
|
||||
__updated__ = '2018-03-02'
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -519,6 +519,17 @@ class Client(object):
|
||||
|
||||
ensureResponseIsValid(r, 'Resuming server')
|
||||
|
||||
@authProjectRequired
|
||||
def resetServer(self, serverId):
|
||||
r = requests.post(self._getEndpointFor('compute') + '/servers/{server_id}/action'.format(server_id=serverId),
|
||||
data='{"reboot":{"type":"HARD"}}',
|
||||
headers=self._requestHeaders(),
|
||||
verify=VERIFY_SSL,
|
||||
timeout=self._timeout)
|
||||
|
||||
# Ignore response for this...
|
||||
# ensureResponseIsValid(r, 'Reseting server')
|
||||
|
||||
def testConnection(self):
|
||||
# First, ensure requested api is supported
|
||||
# We need api version 3.2 or greater
|
||||
|
@ -180,6 +180,9 @@ class XenLinkedDeployment(UserDeployment):
|
||||
|
||||
return State.FINISHED
|
||||
|
||||
def reset(self):
|
||||
if self._vmid != '':
|
||||
self.service().resetVM(self._vmid) # Reset in sync
|
||||
|
||||
def notifyReadyFromOsManager(self, data):
|
||||
# Here we will check for suspending the VM (when full ready)
|
||||
@ -323,7 +326,6 @@ class XenLinkedDeployment(UserDeployment):
|
||||
if self._task is None:
|
||||
raise Exception('Can\'t create machine')
|
||||
|
||||
|
||||
def __remove(self):
|
||||
'''
|
||||
Removes a machine from system
|
||||
|
@ -88,6 +88,7 @@ class XenLinkedService(Service):
|
||||
# : If true, the system can't do an automatic assignation of a deployed user
|
||||
# : service from this service
|
||||
mustAssignManually = False
|
||||
canReset = True
|
||||
|
||||
# : Types of publications (preparated data for deploys)
|
||||
# : In our case, we do no need a publication, so this is None
|
||||
@ -97,7 +98,6 @@ class XenLinkedService(Service):
|
||||
|
||||
servicesTypeProvided = (serviceTypes.VDI,)
|
||||
|
||||
|
||||
# Now the form part
|
||||
datastore = gui.ChoiceField(
|
||||
label=_("Storage SR"),
|
||||
@ -216,12 +216,9 @@ class XenLinkedService(Service):
|
||||
self.datastore.setValues(storages_list)
|
||||
self.network.setValues(network_list)
|
||||
|
||||
|
||||
|
||||
def checkTaskFinished(self, task):
|
||||
return self.parent().checkTaskFinished(task)
|
||||
|
||||
|
||||
def datastoreHasSpace(self):
|
||||
# Get storages for that datacenter
|
||||
logger.debug('Checking datastore space for {0}'.format(self.datastore.value))
|
||||
@ -237,7 +234,6 @@ class XenLinkedService(Service):
|
||||
'''
|
||||
return name
|
||||
|
||||
|
||||
def startDeployTemplate(self, name, comments):
|
||||
'''
|
||||
Invokes makeTemplate from parent provider, completing params
|
||||
@ -325,6 +321,17 @@ class XenLinkedService(Service):
|
||||
'''
|
||||
return self.parent().stopVM(machineId, async)
|
||||
|
||||
def resetVM(self, machineId, async=True):
|
||||
'''
|
||||
Tries to stop a machine. No check is done, it is simply requested to Xen
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
return self.parent().resetVM(machineId, async)
|
||||
|
||||
def canSuspendVM(self, machineId):
|
||||
'''
|
||||
The machine can be suspended only when "suspend" is in their operations list (mush have xentools installed)
|
||||
@ -359,7 +366,6 @@ class XenLinkedService(Service):
|
||||
'''
|
||||
return self.parent().suspendVM(machineId, async)
|
||||
|
||||
|
||||
def removeVM(self, machineId):
|
||||
'''
|
||||
Tries to delete a machine. No check is done, it is simply requested to Xen
|
||||
|
@ -49,8 +49,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__updated__ = '2017-03-06'
|
||||
|
||||
__updated__ = '2018-03-16'
|
||||
|
||||
CACHE_TIME_FOR_SERVER = 1800
|
||||
|
||||
@ -320,6 +319,17 @@ class Provider(ServiceProvider):
|
||||
'''
|
||||
return self.__getApi().stopVM(machineId, async)
|
||||
|
||||
def resetVM(self, machineId, async=True):
|
||||
'''
|
||||
Tries to start a machine. No check is done, it is simply requested to XenServer
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
return self.__getApi().resetVM(machineId, async)
|
||||
|
||||
def canSuspendVM(self, machineId):
|
||||
'''
|
||||
The machine can be suspended only when "suspend" is in their operations list (mush have xentools installed)
|
||||
|
@ -90,6 +90,7 @@ class XenFailure(XenAPI.Failure, XenFault):
|
||||
|
||||
|
||||
class XenException(XenFault):
|
||||
|
||||
def __init__(self, message):
|
||||
XenFault.__init__(self, message)
|
||||
logger.debug('Exception create: {0}'.format(message))
|
||||
@ -103,6 +104,7 @@ class XenPowerState(object):
|
||||
|
||||
|
||||
class XenServer(object):
|
||||
|
||||
def __init__(self, host, port, username, password, useSSL=False, verifySSL=False):
|
||||
self._originalHost = self._host = host
|
||||
self._port = unicode(port)
|
||||
@ -333,6 +335,14 @@ class XenServer(object):
|
||||
return self.Async.VM.hard_shutdown(vmId)
|
||||
return self.VM.hard_shutdown(vmId)
|
||||
|
||||
def resetVM(self, vmId, async=True):
|
||||
vmState = self.getVMPowerState(vmId)
|
||||
if vmState in (XenPowerState.suspended, XenPowerState.halted):
|
||||
return None # Already powered off
|
||||
if async:
|
||||
return self.Async.VM.hard_reboot(vmId)
|
||||
return self.VM.hard_reboot(vmId)
|
||||
|
||||
def canSuspendVM(self, vmId):
|
||||
operations = self.VM.get_allowed_operations(vmId)
|
||||
logger.debug('Operations: {}'.format(operations))
|
||||
|
Loading…
Reference in New Issue
Block a user