Skip to content
Snippets Groups Projects
Commit 9b11b288 authored by JORGE SASIAIN's avatar JORGE SASIAIN
Browse files

NAT-356: create BaseSiteModel and extend it in CreateSiteForm

parent a07e02cc
No related branches found
No related tags found
No related merge requests found
from pydantic import BaseModel, validator
from pydantic.fields import ModelField
from gso.products.product_blocks.site import SiteTier
from gso.utils.helpers import (
validate_site_fields_is_unique,
validate_ipv4_or_ipv6,
validate_country_code,
validate_site_name,
)
class BaseSiteModel(BaseModel):
site_bgp_community_id: int
site_internal_id: int
site_tier: SiteTier
site_ts_address: str
@validator("site_ts_address", check_fields=False, allow_reuse=True)
def validate_ts_address(cls, site_ts_address: str) -> str:
"""Validate that a terminal server address is valid."""
validate_ipv4_or_ipv6(site_ts_address)
return site_ts_address
@validator("site_country_code", check_fields=False, allow_reuse=True)
def country_code_must_exist(cls, country_code: str) -> str:
"""Validate that the country code exists."""
validate_country_code(country_code)
return country_code
@validator("site_ts_address", "site_internal_id", "site_bgp_community_id", "site_name", check_fields=False, allow_reuse=True)
def validate_unique_fields(cls, value: str, field: ModelField) -> str | int:
"""Validate that the internal and :term:`BGP` community IDs are unique."""
return validate_site_fields_is_unique(field.name, value)
@validator("site_name", check_fields=False, allow_reuse=True)
def site_name_must_be_valid(cls, site_name: str) -> str:
"""Validate the site name.
The site name must consist of three uppercase letters, followed by an optional single digit.
"""
validate_site_name(site_name)
return site_name
\ No newline at end of file
......@@ -6,25 +6,18 @@ from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUID
from orchestrator.workflow import StepList, done, init, step, workflow
from orchestrator.workflows.steps import resync, set_status, store_process_subscription
from orchestrator.workflows.utils import wrap_create_initial_input_form
from pydantic import validator
from pydantic.fields import ModelField
from gso.products.product_blocks import site as site_pb
from gso.products.product_blocks.site import LatitudeCoordinate, LongitudeCoordinate
from gso.products.product_types import site
from gso.services.crm import customer_selector
from gso.utils.helpers import (
validate_country_code,
validate_ipv4_or_ipv6,
validate_site_fields_is_unique,
validate_site_name,
)
from gso.workflows.site.base_site_model import BaseSiteModel
def initial_input_form_generator(product_name: str) -> FormGenerator:
"""Get input from the operator about the new site subscription."""
class CreateSiteForm(FormPage):
class CreateSiteForm(FormPage, BaseSiteModel):
class Config:
title = product_name
......@@ -40,32 +33,6 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
site_tier: site_pb.SiteTier
site_ts_address: str
@validator("site_ts_address", allow_reuse=True)
def validate_ts_address(cls, site_ts_address: str) -> str:
"""Validate that a terminal server address is valid."""
validate_ipv4_or_ipv6(site_ts_address)
return site_ts_address
@validator("site_country_code", allow_reuse=True)
def country_code_must_exist(cls, country_code: str) -> str:
"""Validate that the country code exists."""
validate_country_code(country_code)
return country_code
@validator("site_ts_address", "site_internal_id", "site_bgp_community_id", "site_name", allow_reuse=True)
def validate_unique_fields(cls, value: str, field: ModelField) -> str | int:
"""Validate that the internal and :term:`BGP` community IDs are unique."""
return validate_site_fields_is_unique(field.name, value)
@validator("site_name", allow_reuse=True)
def site_name_must_be_valid(cls, site_name: str) -> str:
"""Validate the site name.
The site name must consist of three uppercase letters, followed by an optional single digit.
"""
validate_site_name(site_name)
return site_name
user_input = yield CreateSiteForm
return user_input.dict()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment