Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
1287ea49
Commit
1287ea49
authored
1 year ago
by
JORGE SASIAIN
Browse files
Options
Downloads
Patches
Plain Diff
NAT-356: create BaseSiteModel and extend it in CreateSiteForm
parent
91e16db4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!112
Address SonarQube code smells
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gso/workflows/site/base_site_model.py
+42
-0
42 additions, 0 deletions
gso/workflows/site/base_site_model.py
gso/workflows/site/create_site.py
+2
-35
2 additions, 35 deletions
gso/workflows/site/create_site.py
with
44 additions
and
35 deletions
gso/workflows/site/base_site_model.py
0 → 100644
+
42
−
0
View file @
1287ea49
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
This diff is collapsed.
Click to expand it.
gso/workflows/site/create_site.py
+
2
−
35
View file @
1287ea49
...
@@ -6,25 +6,18 @@ from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUID
...
@@ -6,25 +6,18 @@ from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUID
from
orchestrator.workflow
import
StepList
,
done
,
init
,
step
,
workflow
from
orchestrator.workflow
import
StepList
,
done
,
init
,
step
,
workflow
from
orchestrator.workflows.steps
import
resync
,
set_status
,
store_process_subscription
from
orchestrator.workflows.steps
import
resync
,
set_status
,
store_process_subscription
from
orchestrator.workflows.utils
import
wrap_create_initial_input_form
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
import
site
as
site_pb
from
gso.products.product_blocks.site
import
LatitudeCoordinate
,
LongitudeCoordinate
from
gso.products.product_blocks.site
import
LatitudeCoordinate
,
LongitudeCoordinate
from
gso.products.product_types
import
site
from
gso.products.product_types
import
site
from
gso.services.crm
import
customer_selector
from
gso.services.crm
import
customer_selector
from
gso.utils.helpers
import
(
from
gso.workflows.site.base_site_model
import
BaseSiteModel
validate_country_code
,
validate_ipv4_or_ipv6
,
validate_site_fields_is_unique
,
validate_site_name
,
)
def
initial_input_form_generator
(
product_name
:
str
)
->
FormGenerator
:
def
initial_input_form_generator
(
product_name
:
str
)
->
FormGenerator
:
"""
Get input from the operator about the new site subscription.
"""
"""
Get input from the operator about the new site subscription.
"""
class
CreateSiteForm
(
FormPage
):
class
CreateSiteForm
(
FormPage
,
BaseSiteModel
):
class
Config
:
class
Config
:
title
=
product_name
title
=
product_name
...
@@ -40,32 +33,6 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
...
@@ -40,32 +33,6 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
site_tier
:
site_pb
.
SiteTier
site_tier
:
site_pb
.
SiteTier
site_ts_address
:
str
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
user_input
=
yield
CreateSiteForm
return
user_input
.
dict
()
return
user_input
.
dict
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment