Merge remote-tracking branch 'origin/v3.5'

This commit is contained in:
Adolfo Gómez García 2021-11-19 14:14:12 +01:00
commit a0365e1277
6 changed files with 50 additions and 27 deletions

View File

@ -53,9 +53,10 @@ if typing.TYPE_CHECKING:
cache = Cache('StatsDispatcher')
# Enclosed methods under /stats path
POINTS = 300
POINTS = 150
SINCE = 30 # Days, if higer values used, ensure mysql/mariadb has a bigger sort buffer
USE_MAX = True
CACHE_TIME = SINCE * 24 * 3600 // POINTS
def getServicesPoolsCounters(
@ -93,7 +94,7 @@ def getServicesPoolsCounters(
val.append({'stamp': x[0], 'value': int(x[1])})
logger.debug('val: %s', val)
if len(val) >= 2:
cache.put(cacheKey, codecs.encode(pickle.dumps(val), 'zip'), 600)
cache.put(cacheKey, codecs.encode(pickle.dumps(val), 'zip'), CACHE_TIME*2)
else:
val = [{'stamp': since, 'value': 0}, {'stamp': to, 'value': 0}]
else:

View File

@ -204,16 +204,21 @@ class OVirtLinkedDeployment(services.UserDeployment):
if self.cache.get('ready') == '1':
return State.FINISHED
state = self.service().getMachineState(self._vmid)
try:
state = self.service().getMachineState(self._vmid)
if state == 'unknown':
return self.__error('Machine is not available anymore')
if state == 'unknown':
return self.__error('Machine is not available anymore')
if state not in UP_STATES:
self._queue = [opStart, opFinish]
return self.__executeQueue()
if state not in UP_STATES:
self._queue = [opStart, opFinish]
return self.__executeQueue()
self.cache.put('ready', '1')
except Exception as e:
self.doLog(log.ERROR, 'Error on setReady: {}'.format(e))
# Treat as operation done, maybe the machine is ready and we can continue
self.cache.put('ready', '1')
return State.FINISHED
def reset(self) -> None:

View File

@ -131,14 +131,19 @@ class LiveDeployment(UserDeployment): # pylint: disable=too-many-public-methods
if self.cache.get('ready') == '1':
return State.FINISHED
state = self.service().getMachineState(self._vmid)
try:
state = self.service().getMachineState(self._vmid)
if state == on.types.VmState.UNKNOWN: # @UndefinedVariable
return self.__error('Machine is not available anymore')
if state == on.types.VmState.UNKNOWN: # @UndefinedVariable
return self.__error('Machine is not available anymore')
self.service().startMachine(self._vmid)
self.service().startMachine(self._vmid)
self.cache.put('ready', '1')
except Exception as e:
self.doLog(log.ERROR, 'Error on setReady: {}'.format(e))
# Treat as operation done, maybe the machine is ready and we can continue
self.cache.put('ready', '1')
return State.FINISHED
def reset(self) -> None:

View File

@ -142,19 +142,24 @@ class LiveDeployment(UserDeployment): # pylint: disable=too-many-public-methods
if self.cache.get('ready') == '1':
return State.FINISHED
status = self.service().getMachineState(self._vmid)
try:
status = self.service().getMachineState(self._vmid)
if openstack.statusIsLost(status):
return self.__error('Machine is not available anymore')
if openstack.statusIsLost(status):
return self.__error('Machine is not available anymore')
if status == openstack.PAUSED:
self.service().resumeMachine(self._vmid)
elif status in (openstack.STOPPED, openstack.SHUTOFF):
self.service().startMachine(self._vmid)
if status == openstack.PAUSED:
self.service().resumeMachine(self._vmid)
elif status in (openstack.STOPPED, openstack.SHUTOFF):
self.service().startMachine(self._vmid)
# Right now, we suppose the machine is ready
# Right now, we suppose the machine is ready
self.cache.put('ready', '1')
except Exception as e:
self.doLog(log.ERROR, 'Error on setReady: {}'.format(e))
# Treat as operation done, maybe the machine is ready and we can continue
self.cache.put('ready', '1')
return State.FINISHED
def reset(self) -> None:

View File

@ -174,8 +174,8 @@ class ProxmoxDeployment(services.UserDeployment):
vmInfo = self.service().getMachineInfo(int(self._vmid))
except client.ProxmoxConnectionError:
raise # If connection fails, let it fail on parent
except Exception:
return self.__error('Machine not found')
except Exception as e:
return self.__error('Machine not found: {}'.format(e))
if vmInfo.status == 'stopped':
self._queue = [opStart, opFinish]

View File

@ -141,14 +141,21 @@ class XenLinkedDeployment(UserDeployment):
return self._ip
def setReady(self) -> str:
if self.cache.get('ready') == '1':
return State.FINISHED
try:
state = self.service().getVMPowerState(self._vmid)
if state != XenPowerState.running:
self._queue = [opStart, opFinish]
return self.__executeQueue()
except Exception:
return self.__error('Machine is not available anymore')
self.cache.put('ready', '1', 30)
except Exception as e:
# On case of exception, log an an error and return as if the operation was executed
self.doLog(log.ERROR, 'Error setting machine state: {}'.format(e))
# return self.__error('Machine is not available anymore')
return State.FINISHED