fixed oVirt for 3.7

This commit is contained in:
Adolfo Gómez García 2019-10-03 15:45:32 +02:00
parent fbff259691
commit a393e0b5a3
3 changed files with 25 additions and 26 deletions

View File

@ -181,7 +181,7 @@ class OVirtLinkedDeployment(services.UserDeployment):
""" """
return self._ip return self._ip
def setReady(self): def setReady(self) -> str:
""" """
The method is invoked whenever a machine is provided to an user, right The method is invoked whenever a machine is provided to an user, right
before presenting it (via transport rendering) to the user. before presenting it (via transport rendering) to the user.
@ -201,14 +201,14 @@ class OVirtLinkedDeployment(services.UserDeployment):
self.cache.put('ready', '1') self.cache.put('ready', '1')
return State.FINISHED return State.FINISHED
def reset(self): def reset(self) -> None:
""" """
o oVirt, reset operation just shutdowns it until v3 support is removed o oVirt, reset operation just shutdowns it until v3 support is removed
""" """
if self._vmid != '': if self._vmid != '':
self.service().stopMachine(self._vmid) self.service().stopMachine(self._vmid)
def getConsoleConnection(self): def getConsoleConnection(self) -> typing.Optional[typing.MutableMapping[str, typing.Any]]:
return self.service().getConsoleConnection(self._vmid) return self.service().getConsoleConnection(self._vmid)
def desktopLogin(self, username, password, domain=''): def desktopLogin(self, username, password, domain=''):

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (c) 2012-2017 Virtual Cable S.L. # Copyright (c) 2012-2019 Virtual Cable S.L.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without modification, # Redistribution and use in source and binary forms, with or without modification,
@ -29,17 +29,14 @@
""" """
@author: Adolfo Gómez, dkmaster at dkmon dot com @author: Adolfo Gómez, dkmaster at dkmon dot com
""" """
from __future__ import unicode_literals import logging
import typing
from uds.core import jobs from uds.core import jobs
from uds.core.util import log
from uds.core.util.state import State
from uds.models import Provider, Service, getSqlDatetime # Not imported at runtime, just for type checking
if typing.TYPE_CHECKING:
from .provider import OVirtProvider
import logging
import time
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -58,8 +55,8 @@ class OVirtDeferredRemoval(jobs.Job):
counter = 0 counter = 0
@staticmethod @staticmethod
def remove(providerInstance, vmId): def remove(providerInstance: 'OVirtProvider', vmId: str) -> None:
logger.debug('Adding {} from {} to defeffed removal process'.format(vmId, providerInstance)) logger.debug('Adding %s from %s to defeffed removal process', vmId, providerInstance)
OVirtDeferredRemoval.counter += 1 OVirtDeferredRemoval.counter += 1
try: try:
# Tries to stop machine sync when found, if any error is done, defer removal for a scheduled task # Tries to stop machine sync when found, if any error is done, defer removal for a scheduled task
@ -73,19 +70,20 @@ class OVirtDeferredRemoval(jobs.Job):
except Exception as e: except Exception as e:
providerInstance.storage.saveData('tr' + vmId, vmId, attr1='tRm') providerInstance.storage.saveData('tr' + vmId, vmId, attr1='tRm')
logger.info('Machine {} could not be removed right now, queued for later: {}'.format(vmId, e)) logger.info('Machine %s could not be removed right now, queued for later: %s', vmId, e)
except Exception as e: except Exception as e:
logger.warning('Exception got queuing for Removal: {}'.format(e)) logger.warning('Exception got queuing for Removal: %s', e)
def run(self): def run(self):
from .OVirtProvider import Provider as OVirtProvider from .provider import OVirtProvider
logger.debug('Looking for deferred vm removals') logger.debug('Looking for deferred vm removals')
provider: OVirtProvider
# Look for Providers of type VCServiceProvider # Look for Providers of type VCServiceProvider
for provider in Provider.objects.filter(maintenance_mode=False, data_type=OVirtProvider.typeType): for provider in OVirtProvider.objects.filter(maintenance_mode=False, data_type=OVirtProvider.typeType):
logger.debug('Provider {} if os type ovirt'.format(provider)) logger.debug('Provider %s if os type ovirt', provider)
storage = provider.getEnvironment().storage storage = provider.getEnvironment().storage
instance = provider.getInstance() instance = provider.getInstance()
@ -93,7 +91,7 @@ class OVirtDeferredRemoval(jobs.Job):
for i in storage.filter('tRm'): for i in storage.filter('tRm'):
vmId = i[1] vmId = i[1]
try: try:
logger.debug('Found {} for removal {}'.format(vmId, i)) logger.debug('Found %s for removal %s', vmId, i)
# If machine is powered on, tries to stop it # If machine is powered on, tries to stop it
# tries to remove in sync mode # tries to remove in sync mode
state = instance.getMachineState(vmId) state = instance.getMachineState(vmId)
@ -107,7 +105,7 @@ class OVirtDeferredRemoval(jobs.Job):
# It this is reached, remove check # It this is reached, remove check
storage.remove('tr' + vmId) storage.remove('tr' + vmId)
except Exception as e: # Any other exception wil be threated again except Exception as e: # Any other exception wil be threated again
instance.doLog('Delayed removal of {} has failed: {}. Will retry later'.format(vmId, e)) instance.doLog('Delayed removal of %s has failed: %s. Will retry later', vmId, e)
logger.error('Delayed removal of {} failed: {}'.format(i, e)) logger.error('Delayed removal of %s failed: %s', i, e)
logger.debug('Deferred removal finished') logger.debug('Deferred removal finished')

View File

@ -38,12 +38,13 @@ from django.utils.translation import ugettext as _
from uds.core.services import Publication from uds.core.services import Publication
from uds.core.util.state import State from uds.core.util.state import State
logger = logging.getLogger(__name__)
# Not imported at runtime, just for type checking # Not imported at runtime, just for type checking
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from .service import OVirtLinkedService from .service import OVirtLinkedService
logger = logging.getLogger(__name__)
class OVirtPublication(Publication): class OVirtPublication(Publication):
""" """
This class provides the publication of a oVirtLinkedService This class provides the publication of a oVirtLinkedService
@ -59,7 +60,7 @@ class OVirtPublication(Publication):
def service(self) -> 'OVirtLinkedService': def service(self) -> 'OVirtLinkedService':
return typing.cast('OVirtLinkedService', super().service()) return typing.cast('OVirtLinkedService', super().service())
def initialize(self): def initialize(self) -> None:
""" """
This method will be invoked by default __init__ of base class, so it gives This method will be invoked by default __init__ of base class, so it gives
us the oportunity to initialize whataver we need here. us the oportunity to initialize whataver we need here.
@ -90,7 +91,7 @@ class OVirtPublication(Publication):
if vals[0] == 'v1': if vals[0] == 'v1':
self._name, self._reason, self._destroyAfter, self._templateId, self._state = vals[1:] self._name, self._reason, self._destroyAfter, self._templateId, self._state = vals[1:]
def publish(self): def publish(self) -> str:
""" """
Realizes the publication of the service Realizes the publication of the service
""" """