diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py index 6a1a49f99e6f463e916b9b9ffbcd3df8203251cd..c05517a23beed1b47a5aaf37786af5fe8b8d1eee 100644 --- a/gso/utils/helpers.py +++ b/gso/utils/helpers.py @@ -4,6 +4,7 @@ import re from typing import TYPE_CHECKING from uuid import UUID +from pydantic_forms.types import UUIDstr from pydantic_forms.validators import Choice from gso import settings @@ -11,7 +12,7 @@ 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.services.partners import get_all_partners, get_partner_by_name +from gso.services.partners import get_all_partners from gso.utils.shared_enums import Vendor from gso.utils.types.interfaces import PhysicalPortCapacity from gso.utils.types.ip_address import IPv4AddressType @@ -210,20 +211,16 @@ def active_switch_selector() -> Choice: return Choice("Select a switch", zip(switch_subscriptions.keys(), switch_subscriptions.items(), strict=True)) # type: ignore[arg-type] -def active_edge_port_selector(*, geant_only: bool | None = None) -> Choice: +def active_edge_port_selector(*, partner_id: UUIDstr | None = None) -> Choice: """Generate a dropdown selector for choosing an active Edge Port in an input form.""" edge_port_subscriptions = subscriptions.get_active_edge_port_subscriptions( includes=["subscription_id", "description", "customer_id"] ) - if geant_only is not None: - # ``geant_only`` is set, so we will filter accordingly. - geant_partner_id = get_partner_by_name("GEANT")["partner_id"] + if partner_id: + # ``partner_id`` is set, so we will filter accordingly. edge_port_subscriptions = list( - filter( - lambda subscription: geant_only ^ bool(subscription["customer_id"] != geant_partner_id), - edge_port_subscriptions, - ) + filter(lambda subscription: bool(subscription["customer_id"] == partner_id), edge_port_subscriptions) ) edge_ports = {str(port["subscription_id"]): port["description"] for port in edge_port_subscriptions} diff --git a/gso/workflows/geant_ip/create_geant_ip.py b/gso/workflows/geant_ip/create_geant_ip.py index f8c280770695b5f971721ab4eafc5369c068d112..57e40799d5475a74da0f4ad494b705b002578cfd 100644 --- a/gso/workflows/geant_ip/create_geant_ip.py +++ b/gso/workflows/geant_ip/create_geant_ip.py @@ -41,7 +41,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: initial_user_input = yield CreateGeantIPForm class EdgePortSelection(BaseModel): - edge_port: active_edge_port_selector() # type: ignore[valid-type] + edge_port: active_edge_port_selector(partner_id=initial_user_input.partner) # type: ignore[valid-type] ap_type: APType def __hash__(self) -> int: