Fixing up things for 3.7. providers part

This commit is contained in:
Adolfo Gómez García 2019-09-27 13:23:18 +02:00
parent 7b4563b359
commit 5abd8184dc
9 changed files with 19 additions and 17 deletions

View File

@ -98,7 +98,7 @@ class Module(UserInterface, Environmentable, Serializable):
module. module.
""" """
# Types # 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. # : Which coded to use to encode module by default.
# : Basic name used to provide the administrator an "huma readable" form for the module # : Basic name used to provide the administrator an "huma readable" form for the module

View File

@ -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 # : 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 # : 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 maxPreparingServices: typing.Any = None
# : This defines the maximum number of concurrent services that should be in state "removing" for this provider # : 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 # : 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 maxRemovingServices: typing.Any = None
# : This defines if the limits (max.. vars) should be taken into accout or simply ignored # : This defines if the limits (max.. vars) should be taken into accout or simply ignored

View File

@ -81,7 +81,7 @@ class gui:
""" """
# Values dict type # Values dict type
ValuesType = typing.Optional[typing.Dict[str, str]] 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] ChoiceType = typing.Dict[str, str]
# : True string value # : True string value
@ -403,6 +403,10 @@ class gui:
self._type(gui.InputField.NUMERIC_TYPE) self._type(gui.InputField.NUMERIC_TYPE)
def _setValue(self, value: typing.Any):
# Internally stores an string
super()._setValue(str(value))
def num(self) -> int: def num(self) -> int:
""" """
Return value as integer Return value as integer

View File

@ -34,13 +34,11 @@ import re
import logging import logging
import typing import typing
from uds.core.module import Module
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from uds.core.module import Module
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def validateNumeric( def validateNumeric(
numericStr: str, numericStr: str,
minValue: typing.Optional[int] = None, minValue: typing.Optional[int] = None,
@ -79,24 +77,24 @@ def validateNumeric(
return numericStr 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 Validates that a port number is valid
:param portStr: port to validate, as string :param portStr: port to validate, as string
:param returnAsInteger: if True, returns value as integer, if not, 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: 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 Validates that a timeout value is valid
:param timeOutStr: timeout to validate :param timeOutStr: timeout to validate
:param returnAsInteger: if True, returns value as integer, if not, 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: 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: def validateMacRange(macRange: str) -> str:

View File

@ -144,7 +144,7 @@ class Provider(ServiceProvider):
if values is not None: if values is not None:
self.macsRange.value = validators.validateMacRange(self.macsRange.value) 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) logger.debug(self.host.value)
def testConnection(self): def testConnection(self):

View File

@ -117,8 +117,8 @@ class OGProvider(ServiceProvider):
self._api = None self._api = None
if values is not 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: {}'.format(self.endpoint)) logger.debug('Endpoint: %s', self.endpoint)
try: try:
request = values['_request'] request = values['_request']

View File

@ -107,7 +107,7 @@ class Provider(ServiceProvider):
self._api = None self._api = None
if values is not 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) logger.debug('Endpoint: %s', self.endpoint)
@property @property

View File

@ -123,7 +123,7 @@ class Provider(ServiceProvider):
self._api = None self._api = None
if values is not 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: def api(self, projectId=None, region=None) -> openStack.Client:
if self._api is None: if self._api is None:

View File

@ -129,7 +129,7 @@ class ProviderLegacy(ServiceProvider):
# Just reset _api connection variable # Just reset _api connection variable
if values is not 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: def api(self, projectId=None, region=None) -> openStack.Client:
return openStack.Client( return openStack.Client(