Added isAvailable for all services

This commit is contained in:
Adolfo Gómez García 2022-01-19 14:11:37 +01:00
parent 61a32e13a2
commit f40c2ed618
8 changed files with 53 additions and 13 deletions

View File

@ -52,6 +52,7 @@ if typing.TYPE_CHECKING:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
MIN_VERSION = '1.1.0'
class OGProvider(ServiceProvider): class OGProvider(ServiceProvider):
""" """
@ -227,7 +228,7 @@ class OGProvider(ServiceProvider):
True if all went fine, false if id didn't True if all went fine, false if id didn't
""" """
try: try:
if self.api.version[0:5] < '1.1.0': if self.api.version[0:5] < MIN_VERSION:
return [ return [
False, False,
'OpenGnsys version is not supported (required version 1.1.0 or newer and found {})'.format( 'OpenGnsys version is not supported (required version 1.1.0 or newer and found {})'.format(
@ -291,4 +292,9 @@ class OGProvider(ServiceProvider):
""" """
Check if aws provider is reachable Check if aws provider is reachable
""" """
return self.testConnection()[0] try:
if self.api.version[0:5] < MIN_VERSION:
return False
return True
except Exception:
return False

View File

@ -780,3 +780,13 @@ class Client: # pylint: disable=too-many-public-methods
'Openstack does not support identity API 3.2 or newer. This OpenStack server is not compatible with UDS.' 'Openstack does not support identity API 3.2 or newer. This OpenStack server is not compatible with UDS.'
) )
) )
def isAvailable(self) -> bool:
try:
# If we can connect, it is available
self._session.get(
self._authUrl, verify=VERIFY_SSL, headers=self._requestHeaders()
)
return True
except Exception:
return False

View File

@ -298,5 +298,5 @@ class OpenStackProvider(ServiceProvider):
""" """
Check if aws provider is reachable Check if aws provider is reachable
""" """
return self.testConnection()[0] return self.api().isAvailable()

View File

@ -81,3 +81,8 @@ class IPServiceBase(services.Service):
# logger.debug('Result: %s', result) # logger.debug('Result: %s', result)
except Exception as e: except Exception as e:
logger.error('Error on WOL: %s', e) logger.error('Error on WOL: %s', e)
# Phisical machines does not have "real" providers, so
# always is available
def isAvailable(self) -> bool:
return True

View File

@ -287,6 +287,10 @@ class ProxmoxProvider(
return vmId return vmId
# All assigned VMId will be left as unusable on UDS until released by time (3 months) # All assigned VMId will be left as unusable on UDS until released by time (3 months)
@allowCache('reachable', Cache.SHORT_VALIDITY)
def isAvailable(self) -> bool:
return self.__getApi().test()
@staticmethod @staticmethod
def test(env: 'Environment', data: 'Module.ValuesType') -> typing.List[typing.Any]: def test(env: 'Environment', data: 'Module.ValuesType') -> typing.List[typing.Any]:
""" """

View File

@ -28,28 +28,30 @@
""" """
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com .. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
""" """
import re
import logging import logging
import re
import typing import typing
from django.utils.translation import gettext_noop as _ from django.utils.translation import gettext_noop as _
from uds.core.services import Service
from uds.core.services import types as serviceTypes
from uds.core.transports import protocols from uds.core.transports import protocols
from uds.core.services import Service, types as serviceTypes
from uds.core.util import validators
from uds.core.util import tools
from uds.core.ui import gui from uds.core.ui import gui
from uds.core.util import validators
from uds.core.util.cache import Cache
from uds.core.util.decorators import allowCache
from .publication import ProxmoxPublication
from .deployment import ProxmoxDeployment
from . import helpers from . import helpers
from .deployment import ProxmoxDeployment
from .publication import ProxmoxPublication
# 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 .provider import ProxmoxProvider
from . import client
from uds.core import Module from uds.core import Module
from . import client
from .provider import ProxmoxProvider
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -311,3 +313,7 @@ class ProxmoxLinkedService(Service): # pylint: disable=too-many-public-methods
self, machineId: str self, machineId: str
) -> typing.Optional[typing.MutableMapping[str, typing.Any]]: ) -> typing.Optional[typing.MutableMapping[str, typing.Any]]:
return self.parent().getConsoleConnection(machineId) return self.parent().getConsoleConnection(machineId)
@allowCache('reachable', Cache.SHORT_VALIDITY)
def isAvailable(self) -> bool:
return self.parent().isAvailable()

View File

@ -34,6 +34,8 @@ import typing
from django.utils.translation import gettext_noop as _ from django.utils.translation import gettext_noop as _
from uds.core.services import ServiceProvider from uds.core.services import ServiceProvider
from uds.core.ui import gui from uds.core.ui import gui
from uds.core.util.cache import Cache
from uds.core.util.decorators import allowCache
# from uds.core.util import validators # from uds.core.util import validators
@ -450,6 +452,14 @@ class XenProvider(ServiceProvider): # pylint: disable=too-many-public-methods
def getMacRange(self) -> str: def getMacRange(self) -> str:
return self.macsRange.value return self.macsRange.value
@allowCache('reachable', Cache.SHORT_VALIDITY)
def isAvailable(self) -> bool:
try:
self.testConnection()
return True
except Exception:
return False
@staticmethod @staticmethod
def test(env: 'Environment', data: 'Module.ValuesType') -> typing.List[typing.Any]: def test(env: 'Environment', data: 'Module.ValuesType') -> typing.List[typing.Any]:
""" """

View File

@ -26,7 +26,6 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import ssl import ssl
import enum
import xmlrpc.client import xmlrpc.client
import logging import logging
import typing import typing