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

Filter edge ports on selected partner

parent 89f65bf6
No related branches found
Tags 2.27
1 merge request!286Add Edge Port, GÉANT IP and IAS products
......@@ -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}
......
......@@ -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:
......
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