Skip to content
Snippets Groups Projects
Commit 05cbe09a authored by Neda Moeini's avatar Neda Moeini
Browse files

Add validation to modify VRF router list to avoid having duplicate routers in the VRF router list.

parent 4e633b51
No related branches found
No related tags found
1 merge request!314Feature/vrf
This commit is part of merge request !314. Comments created here will be created in the context of that merge request.
......@@ -8,7 +8,7 @@ from orchestrator.types import FormGenerator, State, UUIDstr
from orchestrator.workflow import StepList, begin, done, step, workflow
from orchestrator.workflows.steps import resync, store_process_subscription, unsync
from orchestrator.workflows.utils import wrap_modify_initial_input_form
from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, ConfigDict, Field, field_validator
from gso.products.product_types.router import Router
from gso.products.product_types.vrf import VRF
......@@ -35,6 +35,14 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
RouterSelection(router_id=str(router.owner_subscription_id)) for router in subscription.vrf.vrf_router_list
]
@field_validator("router_list")
def router_list_must_not_have_duplicates(cls, router_list: list[RouterSelection]) -> list[RouterSelection]:
router_ids = [router.router_id for router in router_list]
if len(router_ids) != len(set(router_ids)):
msg = "Duplicate router IDs found in the list."
raise ValueError(msg)
return router_list
user_input = yield ModifyVRFRouterListForm
return user_input.model_dump()
......
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