mirror of
https://github.com/dkmstr/openuds.git
synced 2025-03-22 14:50:29 +03:00
Added L2 cache support for proxmox
This commit is contained in:
parent
4094818ccc
commit
3e8a3efb75
@ -404,6 +404,12 @@ class ProxmoxClient:
|
||||
node = node or self.getVmInfo(vmId).node
|
||||
return types.UPID.fromDict(self._post('nodes/{}/qemu/{}/status/suspend'.format(node, vmId)))
|
||||
|
||||
@ensureConected
|
||||
def shutdownVm(self, vmId: int, node: typing.Optional[str] = None) -> types.UPID:
|
||||
# if exitstatus is "OK" or contains "already running", all is fine
|
||||
node = node or self.getVmInfo(vmId).node
|
||||
return types.UPID.fromDict(self._post('nodes/{}/qemu/{}/status/shutdown'.format(node, vmId)))
|
||||
|
||||
@ensureConected
|
||||
def convertToTemplate(self, vmId: int, node: typing.Optional[str] = None) -> None:
|
||||
node = node or self.getVmInfo(vmId).node
|
||||
|
@ -50,7 +50,7 @@ if typing.TYPE_CHECKING:
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
opCreate, opStart, opStop, opSuspend, opRemove, opWait, opError, opFinish, opRetry, opGetMac = range(10)
|
||||
opCreate, opStart, opStop, opShutdown, opRemove, opWait, opError, opFinish, opRetry, opGetMac = range(10)
|
||||
|
||||
NO_MORE_NAMES = 'NO-NAME-ERROR'
|
||||
UP_STATES = ('up', 'reboot_in_progress', 'powering_up', 'restoring_state')
|
||||
@ -214,7 +214,7 @@ if sys.platform == 'win32':
|
||||
if forLevel2 is False:
|
||||
self._queue = [opCreate, opGetMac, opStart, opFinish]
|
||||
else:
|
||||
self._queue = [opCreate, opGetMac, opStart, opWait, opSuspend, opFinish]
|
||||
self._queue = [opCreate, opGetMac, opStart, opWait, opShutdown, opFinish]
|
||||
|
||||
def __setTask(self, upid: 'client.types.UPID'):
|
||||
self._task = ','.join([upid.node, upid.upid])
|
||||
@ -275,7 +275,7 @@ if sys.platform == 'win32':
|
||||
opRetry: self.__retry,
|
||||
opStart: self.__startMachine,
|
||||
opStop: self.__stopMachine,
|
||||
opSuspend: self.__suspendMachine,
|
||||
opShutdown: self.__shutdownMachine,
|
||||
opWait: self.__wait,
|
||||
opRemove: self.__remove,
|
||||
opGetMac: self.__getMac
|
||||
@ -370,14 +370,14 @@ if sys.platform == 'win32':
|
||||
|
||||
return State.RUNNING
|
||||
|
||||
def __suspendMachine(self) -> str:
|
||||
def __shutdownMachine(self) -> str:
|
||||
try:
|
||||
vmInfo = self.service().getMachineInfo(int(self._vmid))
|
||||
except Exception:
|
||||
raise Exception('Machine not found on suspend machine')
|
||||
|
||||
if vmInfo.status != 'stopped':
|
||||
self.__setTask(self.service().suspendMachine(int(self._vmid)))
|
||||
self.__setTask(self.service().shutdownMachine(int(self._vmid)))
|
||||
|
||||
return State.RUNNING
|
||||
|
||||
@ -425,7 +425,7 @@ if sys.platform == 'win32':
|
||||
"""
|
||||
return self.__checkTaskFinished()
|
||||
|
||||
def __checkSuspend(self) -> str:
|
||||
def __checkShutdown(self) -> str:
|
||||
"""
|
||||
Check if the machine has suspended
|
||||
"""
|
||||
@ -464,7 +464,7 @@ if sys.platform == 'win32':
|
||||
opWait: self.__wait,
|
||||
opStart: self.__checkStart,
|
||||
opStop: self.__checkStop,
|
||||
opSuspend: self.__checkSuspend,
|
||||
opShutdown: self.__checkShutdown,
|
||||
opRemove: self.__checkRemoved,
|
||||
opGetMac: self.__checkMac
|
||||
}
|
||||
@ -494,7 +494,7 @@ if sys.platform == 'win32':
|
||||
if newLevel == self.L1_CACHE:
|
||||
self._queue = [opStart, opFinish]
|
||||
else:
|
||||
self._queue = [opStart, opSuspend, opFinish]
|
||||
self._queue = [opStart, opShutdown, opFinish]
|
||||
|
||||
return self.__executeQueue()
|
||||
|
||||
@ -551,7 +551,7 @@ if sys.platform == 'win32':
|
||||
opCreate: 'create',
|
||||
opStart: 'start',
|
||||
opStop: 'stop',
|
||||
opSuspend: 'suspend',
|
||||
opShutdown: 'suspend',
|
||||
opRemove: 'remove',
|
||||
opWait: 'wait',
|
||||
opError: 'error',
|
||||
|
@ -146,6 +146,9 @@ class ProxmoxProvider(services.ServiceProvider): # pylint: disable=too-many-pub
|
||||
def suspendMachine(self, vmId: int) -> client.types.UPID:
|
||||
return self.__getApi().suspendVm(vmId)
|
||||
|
||||
def shutdownMachine(self, vmId: int) -> client.types.UPID:
|
||||
return self.__getApi().shutdownVm(vmId)
|
||||
|
||||
def removeMachine(self, vmId: int) -> client.types.UPID:
|
||||
return self.__getApi().deleteVm(vmId)
|
||||
|
||||
|
@ -84,10 +84,10 @@ class ProxmoxLinkedService(Service): # pylint: disable=too-many-public-methods
|
||||
cacheTooltip = _('Number of desired machines to keep running waiting for a user')
|
||||
# : If we need to generate a "Level 2" cache for this service (i.e., L1
|
||||
# : could be running machines and L2 suspended machines)
|
||||
usesCache_L2 = False
|
||||
usesCache_L2 = True
|
||||
# : Tooltip shown to user when this item is pointed at admin interface, None
|
||||
# : also because we don't use it
|
||||
cacheTooltip_L2 = _('Number of desired machines to keep suspended waiting for use')
|
||||
cacheTooltip_L2 = _('Number of desired VMs to keep stopped waiting for use')
|
||||
|
||||
# : If the service needs a s.o. manager (managers are related to agents
|
||||
# : provided by services itselfs, i.e. virtual machines with actors)
|
||||
@ -245,6 +245,9 @@ class ProxmoxLinkedService(Service): # pylint: disable=too-many-public-methods
|
||||
def suspendMachine(self, vmId: int) -> 'client.types.UPID':
|
||||
return self.parent().suspendMachine(vmId)
|
||||
|
||||
def shutdownMachine(self, vmId: int) -> 'client.types.UPID':
|
||||
return self.parent().shutdownMachine(vmId)
|
||||
|
||||
def removeMachine(self, vmId: int) -> 'client.types.UPID':
|
||||
# First, remove from HA if needed
|
||||
self.disableHA(vmId)
|
||||
|
Loading…
x
Reference in New Issue
Block a user