forked from shaba/openuds
Added isAvailable for all services
This commit is contained in:
parent
61a32e13a2
commit
f40c2ed618
@ -52,6 +52,7 @@ if typing.TYPE_CHECKING:
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MIN_VERSION = '1.1.0'
|
||||
|
||||
class OGProvider(ServiceProvider):
|
||||
"""
|
||||
@ -227,7 +228,7 @@ class OGProvider(ServiceProvider):
|
||||
True if all went fine, false if id didn't
|
||||
"""
|
||||
try:
|
||||
if self.api.version[0:5] < '1.1.0':
|
||||
if self.api.version[0:5] < MIN_VERSION:
|
||||
return [
|
||||
False,
|
||||
'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
|
||||
"""
|
||||
return self.testConnection()[0]
|
||||
try:
|
||||
if self.api.version[0:5] < MIN_VERSION:
|
||||
return False
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
@ -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.'
|
||||
)
|
||||
)
|
||||
|
||||
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
|
||||
|
@ -298,5 +298,5 @@ class OpenStackProvider(ServiceProvider):
|
||||
"""
|
||||
Check if aws provider is reachable
|
||||
"""
|
||||
return self.testConnection()[0]
|
||||
return self.api().isAvailable()
|
||||
|
||||
|
@ -81,3 +81,8 @@ class IPServiceBase(services.Service):
|
||||
# logger.debug('Result: %s', result)
|
||||
except Exception as 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
|
||||
|
@ -287,6 +287,10 @@ class ProxmoxProvider(
|
||||
return vmId
|
||||
# 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
|
||||
def test(env: 'Environment', data: 'Module.ValuesType') -> typing.List[typing.Any]:
|
||||
"""
|
||||
|
@ -28,28 +28,30 @@
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import re
|
||||
import logging
|
||||
import re
|
||||
import typing
|
||||
|
||||
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.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.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 .deployment import ProxmoxDeployment
|
||||
from .publication import ProxmoxPublication
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from .provider import ProxmoxProvider
|
||||
from . import client
|
||||
from uds.core import Module
|
||||
|
||||
from . import client
|
||||
from .provider import ProxmoxProvider
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -311,3 +313,7 @@ class ProxmoxLinkedService(Service): # pylint: disable=too-many-public-methods
|
||||
self, machineId: str
|
||||
) -> typing.Optional[typing.MutableMapping[str, typing.Any]]:
|
||||
return self.parent().getConsoleConnection(machineId)
|
||||
|
||||
@allowCache('reachable', Cache.SHORT_VALIDITY)
|
||||
def isAvailable(self) -> bool:
|
||||
return self.parent().isAvailable()
|
||||
|
@ -34,6 +34,8 @@ import typing
|
||||
from django.utils.translation import gettext_noop as _
|
||||
from uds.core.services import ServiceProvider
|
||||
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
|
||||
|
||||
@ -450,6 +452,14 @@ class XenProvider(ServiceProvider): # pylint: disable=too-many-public-methods
|
||||
def getMacRange(self) -> str:
|
||||
return self.macsRange.value
|
||||
|
||||
@allowCache('reachable', Cache.SHORT_VALIDITY)
|
||||
def isAvailable(self) -> bool:
|
||||
try:
|
||||
self.testConnection()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def test(env: 'Environment', data: 'Module.ValuesType') -> typing.List[typing.Any]:
|
||||
"""
|
||||
|
@ -26,7 +26,6 @@
|
||||
# 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.
|
||||
import ssl
|
||||
import enum
|
||||
import xmlrpc.client
|
||||
import logging
|
||||
import typing
|
||||
|
Loading…
Reference in New Issue
Block a user