forked from shaba/openuds
Fixing up things for 3.7. providers part
This commit is contained in:
parent
7b4563b359
commit
5abd8184dc
@ -98,7 +98,7 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
module.
|
||||
"""
|
||||
# Types
|
||||
ValuesType = typing.Optional[typing.Dict[str, str]]
|
||||
ValuesType = typing.Optional[typing.Dict[str, typing.Any]] # values type value will be str or list[str] int most cases
|
||||
|
||||
# : Which coded to use to encode module by default.
|
||||
# : Basic name used to provide the administrator an "huma readable" form for the module
|
||||
|
@ -111,12 +111,12 @@ class ServiceProvider(Module):
|
||||
|
||||
# : This defines the maximum number of concurrent services that should be in state "in preparation" for this provider
|
||||
# : Default is return the GlobalConfig value of GlobalConfig.MAX_PREPARING_SERVICES
|
||||
# : Note: this variable can be either a fixed value (integer, string) or a Gui text field (with a .value)
|
||||
# : Note: this variable can be either a fixed value (integer, string) or a Gui text field (with a .value property)
|
||||
maxPreparingServices: typing.Any = None
|
||||
|
||||
# : This defines the maximum number of concurrent services that should be in state "removing" for this provider
|
||||
# : Default is return the GlobalConfig value of GlobalConfig.MAX_REMOVING_SERVICES
|
||||
# : Note: this variable can be either a fixed value (integer, string) or a Gui text field (with a .value)
|
||||
# : Note: this variable can be either a fixed value (integer, string) or a Gui text field (with a .value property)
|
||||
maxRemovingServices: typing.Any = None
|
||||
|
||||
# : This defines if the limits (max.. vars) should be taken into accout or simply ignored
|
||||
|
@ -81,7 +81,7 @@ class gui:
|
||||
"""
|
||||
# Values dict type
|
||||
ValuesType = typing.Optional[typing.Dict[str, str]]
|
||||
ValuesDictType = typing.Dict[str, typing.Union[str, typing.List[str], typing.List[typing.Dict[str, str]]]]
|
||||
ValuesDictType = typing.Dict[str, typing.Union[str, bool, typing.List[str], typing.List[typing.Dict[str, str]]]]
|
||||
ChoiceType = typing.Dict[str, str]
|
||||
|
||||
# : True string value
|
||||
@ -403,6 +403,10 @@ class gui:
|
||||
|
||||
self._type(gui.InputField.NUMERIC_TYPE)
|
||||
|
||||
def _setValue(self, value: typing.Any):
|
||||
# Internally stores an string
|
||||
super()._setValue(str(value))
|
||||
|
||||
def num(self) -> int:
|
||||
"""
|
||||
Return value as integer
|
||||
|
@ -34,13 +34,11 @@ import re
|
||||
import logging
|
||||
import typing
|
||||
|
||||
from uds.core.module import Module
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from uds.core.module import Module
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def validateNumeric(
|
||||
numericStr: str,
|
||||
minValue: typing.Optional[int] = None,
|
||||
@ -79,24 +77,24 @@ def validateNumeric(
|
||||
return numericStr
|
||||
|
||||
|
||||
def validatePort(portStr: str, returnAsInteger: bool = True) -> typing.Union[str, int]:
|
||||
def validatePort(portStr: str) -> int:
|
||||
"""
|
||||
Validates that a port number is valid
|
||||
:param portStr: port to validate, as string
|
||||
:param returnAsInteger: if True, returns value as integer, if not, as string
|
||||
:return: Raises Module.Validation exception if is invalid, else return the value "fixed"
|
||||
"""
|
||||
return validateNumeric(portStr, minValue=0, maxValue=65535, returnAsInteger=returnAsInteger, fieldName='Port')
|
||||
return typing.cast(int, validateNumeric(portStr, minValue=0, maxValue=65535, returnAsInteger=True, fieldName='Port'))
|
||||
|
||||
|
||||
def validateTimeout(timeOutStr, returnAsInteger: bool = True) -> typing.Union[str, int]:
|
||||
def validateTimeout(timeOutStr) -> int:
|
||||
"""
|
||||
Validates that a timeout value is valid
|
||||
:param timeOutStr: timeout to validate
|
||||
:param returnAsInteger: if True, returns value as integer, if not, as string
|
||||
:return: Raises Module.Validation exception if is invalid, else return the value "fixed"
|
||||
"""
|
||||
return validateNumeric(timeOutStr, minValue=0, returnAsInteger=returnAsInteger, fieldName='Timeout')
|
||||
return typing.cast(int, validateNumeric(timeOutStr, minValue=0, returnAsInteger=True, fieldName='Timeout'))
|
||||
|
||||
|
||||
def validateMacRange(macRange: str) -> str:
|
||||
|
@ -144,7 +144,7 @@ class Provider(ServiceProvider):
|
||||
|
||||
if values is not None:
|
||||
self.macsRange.value = validators.validateMacRange(self.macsRange.value)
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value, returnAsInteger=False)
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
||||
logger.debug(self.host.value)
|
||||
|
||||
def testConnection(self):
|
||||
|
@ -117,8 +117,8 @@ class OGProvider(ServiceProvider):
|
||||
self._api = None
|
||||
|
||||
if values is not None:
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value, returnAsInteger=False)
|
||||
logger.debug('Endpoint: {}'.format(self.endpoint))
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
||||
logger.debug('Endpoint: %s', self.endpoint)
|
||||
|
||||
try:
|
||||
request = values['_request']
|
||||
|
@ -107,7 +107,7 @@ class Provider(ServiceProvider):
|
||||
self._api = None
|
||||
|
||||
if values is not None:
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value, returnAsInteger=False)
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
||||
logger.debug('Endpoint: %s', self.endpoint)
|
||||
|
||||
@property
|
||||
|
@ -123,7 +123,7 @@ class Provider(ServiceProvider):
|
||||
self._api = None
|
||||
|
||||
if values is not None:
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value, returnAsInteger=False)
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
||||
|
||||
def api(self, projectId=None, region=None) -> openStack.Client:
|
||||
if self._api is None:
|
||||
|
@ -129,7 +129,7 @@ class ProviderLegacy(ServiceProvider):
|
||||
# Just reset _api connection variable
|
||||
|
||||
if values is not None:
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value, returnAsInteger=False)
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
||||
|
||||
def api(self, projectId=None, region=None) -> openStack.Client:
|
||||
return openStack.Client(
|
||||
|
Loading…
Reference in New Issue
Block a user