Skip to content
Snippets Groups Projects
Verified Commit 1f5e2a0a authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Move types module into utils to avoid collision with existing external module

parent 4de070dd
No related branches found
No related tags found
1 merge request!265Feature/refactor validators
Pipeline #88982 passed
Showing
with 68 additions and 52 deletions
......@@ -13,9 +13,9 @@ from starlette import status
from gso.products.product_blocks.iptrunk import IptrunkType
from gso.products.product_blocks.router import RouterRole
from gso.services.subscriptions import get_active_iptrunk_subscriptions
from gso.types.coordinates import LatitudeCoordinate, LongitudeCoordinate
from gso.types.interfaces import PhysicalPortCapacity
from gso.utils.shared_enums import Vendor
from gso.utils.types.coordinates import LatitudeCoordinate, LongitudeCoordinate
from gso.utils.types.interfaces import PhysicalPortCapacity
router = APIRouter(prefix="/networks", tags=["Network"], dependencies=[Depends(authorize)])
......
......@@ -31,9 +31,10 @@ from gso.services.subscriptions import (
get_active_subscriptions_by_field_and_value,
get_subscriptions,
)
from gso.types.base_site import BaseSiteValidatorModel
from gso.types.interfaces import LAGMember, LAGMemberList, PhysicalPortCapacity
from gso.utils.shared_enums import IPv4AddressType, IPv6AddressType, PortNumber, Vendor
from gso.utils.shared_enums import Vendor
from gso.utils.types.base_site import BaseSiteValidatorModel
from gso.utils.types.interfaces import LAGMember, LAGMemberList, PhysicalPortCapacity
from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType, PortNumber
app: typer.Typer = typer.Typer()
......
......@@ -15,7 +15,7 @@ from gso.products.product_blocks.router import (
RouterBlockInactive,
RouterBlockProvisioning,
)
from gso.types.interfaces import LAGMemberList, PhysicalPortCapacity
from gso.utils.types.interfaces import LAGMemberList, PhysicalPortCapacity
class IptrunkType(strEnum):
......
......@@ -5,7 +5,7 @@ from orchestrator.types import SubscriptionLifecycle, strEnum
from gso.products.product_blocks.router import RouterBlock, RouterBlockInactive, RouterBlockProvisioning
from gso.products.product_blocks.switch import SwitchBlock, SwitchBlockInactive, SwitchBlockProvisioning
from gso.types.interfaces import LAGMemberList
from gso.utils.types.interfaces import LAGMemberList
class LanSwitchInterconnectAddressSpace(strEnum):
......
......@@ -8,7 +8,8 @@ from gso.products.product_blocks.site import (
SiteBlockInactive,
SiteBlockProvisioning,
)
from gso.utils.shared_enums import IPv4AddressType, IPv6AddressType, PortNumber, Vendor
from gso.utils.shared_enums import Vendor
from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType, PortNumber
class OfficeRouterBlockInactive(
......
......@@ -8,7 +8,8 @@ from gso.products.product_blocks.site import (
SiteBlockInactive,
SiteBlockProvisioning,
)
from gso.utils.shared_enums import IPv4AddressType, IPv6AddressType, PortNumber, Vendor
from gso.utils.shared_enums import Vendor
from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType, PortNumber
class RouterRole(strEnum):
......
......@@ -3,9 +3,9 @@
from orchestrator.domain.base import ProductBlockModel
from orchestrator.types import SubscriptionLifecycle, strEnum
from gso.types.coordinates import LatitudeCoordinate, LongitudeCoordinate
from gso.types.ip_address import IPAddress
from gso.types.site_name import SiteName
from gso.utils.types.coordinates import LatitudeCoordinate, LongitudeCoordinate
from gso.utils.types.ip_address import IPAddress
from gso.utils.types.site_name import SiteName
class SiteTier(strEnum):
......
......@@ -8,7 +8,8 @@ from gso.products.product_blocks.site import (
SiteBlockInactive,
SiteBlockProvisioning,
)
from gso.utils.shared_enums import IPv4AddressType, PortNumber, Vendor
from gso.utils.shared_enums import Vendor
from gso.utils.types.ip_address import IPv4AddressType, PortNumber
class SuperPopSwitchBlockInactive(
......
......@@ -9,7 +9,8 @@ from gso.products.product_blocks.site import (
SiteBlockInactive,
SiteBlockProvisioning,
)
from gso.utils.shared_enums import PortNumber, Vendor
from gso.utils.shared_enums import Vendor
from gso.utils.types.ip_address import PortNumber
class SwitchModel(strEnum):
......
......@@ -10,7 +10,7 @@ from infoblox_client.exceptions import (
)
from gso.settings import IPAMParams, load_oss_params
from gso.utils.shared_enums import IPv4AddressType, IPv6AddressType
from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType
logger = getLogger(__name__)
NULL_MAC = "00:00:00:00:00:00"
......
......@@ -10,7 +10,7 @@ from requests import HTTPError, Response
from requests.adapters import HTTPAdapter
from gso.settings import load_oss_params
from gso.types.snmp import SNMPVersion
from gso.utils.types.snmp import SNMPVersion
logger = logging.getLogger(__name__)
......
......@@ -16,7 +16,7 @@ from pydantic_forms.types import UUIDstr, strEnum
from pydantic_settings import BaseSettings
from typing_extensions import Doc
from gso.utils.shared_enums import PortNumber
from gso.utils.types.ip_address import PortNumber
logger = logging.getLogger(__name__)
......
......@@ -11,8 +11,9 @@ from gso.products.product_blocks.router import RouterRole
from gso.products.product_types.router import Router
from gso.services import subscriptions
from gso.services.netbox_client import NetboxClient
from gso.types.interfaces import PhysicalPortCapacity
from gso.utils.shared_enums import IPv4AddressType, Vendor
from gso.utils.shared_enums import Vendor
from gso.utils.types.interfaces import PhysicalPortCapacity
from gso.utils.types.ip_address import IPv4AddressType
if TYPE_CHECKING:
from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock
......
"""Shared choices for the different models."""
import ipaddress
from typing import Annotated, Any
from pydantic import Field, PlainSerializer
from pydantic_forms.types import strEnum
from typing_extensions import Doc
def convert_to_str(value: Any) -> str:
"""Convert the value to a string."""
return str(value)
class Vendor(strEnum):
......@@ -20,24 +10,6 @@ class Vendor(strEnum):
NOKIA = "nokia"
PortNumber = Annotated[
int,
Field(
gt=0,
le=49151,
),
Doc(
"Constrained integer for valid port numbers. The range from 49152 to 65535 is marked as ephemeral, "
"and can therefore not be selected for permanent allocation."
),
]
IPv4AddressType = Annotated[ipaddress.IPv4Address, PlainSerializer(convert_to_str, return_type=str, when_used="always")]
IPv6AddressType = Annotated[ipaddress.IPv6Address, PlainSerializer(convert_to_str, return_type=str, when_used="always")]
class ConnectionStrategy(strEnum):
"""An enumerator for the connection Strategies."""
......
File moved
......@@ -3,11 +3,11 @@
from pydantic import BaseModel
from gso.products.product_blocks.site import SiteTier
from gso.types.coordinates import LatitudeCoordinate, LongitudeCoordinate
from gso.types.country_code import CountryCode
from gso.types.ip_address import IPAddress
from gso.types.site_name import SiteName
from gso.types.unique_field import UniqueField
from gso.utils.types.coordinates import LatitudeCoordinate, LongitudeCoordinate
from gso.utils.types.country_code import CountryCode
from gso.utils.types.ip_address import IPAddress
from gso.utils.types.site_name import SiteName
from gso.utils.types.unique_field import UniqueField
class BaseSiteValidatorModel(BaseModel):
......
File moved
File moved
File moved
"""IP addresses."""
import ipaddress
from typing import Annotated
from typing import Annotated, Any
from pydantic import AfterValidator
from pydantic import AfterValidator, Field, PlainSerializer
from typing_extensions import Doc
def validate_ipv4_or_ipv6(value: str) -> str:
......@@ -17,4 +18,21 @@ def validate_ipv4_or_ipv6(value: str) -> str:
return value
def _str(value: Any) -> str:
return str(value)
IPv4AddressType = Annotated[ipaddress.IPv4Address, PlainSerializer(_str, return_type=str, when_used="always")]
IPv6AddressType = Annotated[ipaddress.IPv6Address, PlainSerializer(_str, return_type=str, when_used="always")]
IPAddress = Annotated[str, AfterValidator(validate_ipv4_or_ipv6)]
PortNumber = Annotated[
int,
Field(
gt=0,
le=49151,
),
Doc(
"Constrained integer for valid port numbers. The range from 49152 to 65535 is marked as ephemeral, "
"and can therefore not be selected for permanent allocation."
),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment