From 10b134d22583f9d23c3549f9b2162c842a3ac7a6 Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Mon, 23 Sep 2024 17:14:27 +0200
Subject: [PATCH] =?UTF-8?q?Implement=20feedback=20for=20G=C3=89ANT=20IP=20?=
 =?UTF-8?q?input=20form?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 gso/workflows/geant_ip/create_geant_ip.py | 32 ++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/gso/workflows/geant_ip/create_geant_ip.py b/gso/workflows/geant_ip/create_geant_ip.py
index 57e40799..569fd09a 100644
--- a/gso/workflows/geant_ip/create_geant_ip.py
+++ b/gso/workflows/geant_ip/create_geant_ip.py
@@ -25,7 +25,7 @@ from gso.utils.helpers import (
     partner_choice,
 )
 from gso.utils.shared_enums import APType, SBPType
-from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType
+from gso.utils.types.ip_address import IPAddress, IPv4AddressType, IPv6AddressType
 from gso.utils.types.tt_number import TTNumber
 
 
@@ -44,14 +44,19 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
         edge_port: active_edge_port_selector(partner_id=initial_user_input.partner)  # type: ignore[valid-type]
         ap_type: APType
 
-        def __hash__(self) -> int:
-            return self.edge_port.__hash__()
+    def validate_edge_ports_are_unique(edge_ports: list[EdgePortSelection]) -> list[EdgePortSelection]:
+        """Verify if interfaces are unique."""
+        port_names = [port.edge_port for port in edge_ports]
+        if len(port_names) != len(set(port_names)):
+            msg = "Edge Ports must be unique."
+            raise ValueError(msg)
+        return edge_ports
 
     class EdgePortSelectionForm(FormPage):
         model_config = ConfigDict(title=f"{product_name} - Select Edge Ports")
         info_label: Label = "Please select the Edge Ports where this GÉANT IP service will terminate"
 
-        edge_ports: Annotated[list[EdgePortSelection], AfterValidator(validate_unique_list)]
+        edge_ports: Annotated[list[EdgePortSelection], AfterValidator(validate_edge_ports_are_unique)]
 
     selected_edge_ports = yield EdgePortSelectionForm
     ep_list = selected_edge_ports.edge_ports
@@ -60,21 +65,23 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
 
     binding_port_inputs = []
     while current_ep_index < total_ep_count:
-        current_edge_port_description = EdgePort.from_subscription(ep_list[current_ep_index].edge_port).description
+        current_edge_port = EdgePort.from_subscription(ep_list[current_ep_index].edge_port)
 
         class BindingPortsInputForm(FormPage):
             model_config = ConfigDict(
                 title=f"{product_name} - Configure Service Binding Ports ({current_ep_index + 1}/{total_ep_count})"
             )
             info_label: Label = "Please configure the Service Binding Ports for each Edge Port."
-            current_ep_label: Label = f"Currently configuring on {current_edge_port_description}"
+            current_ep_label: Label = (
+                f"Currently configuring on {current_edge_port.description} "
+                f"(Access Port type: {ep_list[current_ep_index].ap_type})"
+            )
 
             geant_sid: str
             is_tagged: bool = False
-            sbp_type: SBPType
-            vlan_id: VLAN_ID | None
-            ipv4_address: IPv4AddressType | None = None
-            ipv6_address: IPv6AddressType | None = None
+            vlan_id: VLAN_ID
+            ipv4_address: IPv4AddressType
+            ipv6_address: IPv6AddressType
             custom_firewall_filters: bool = False
             divider: Divider
             bgp_peer_count: PositiveInt = 1
@@ -90,11 +97,11 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
             class BGPPeerForm(FormPage):
                 model_config = ConfigDict(
                     title=(
-                        f"Configure BGP peers for {current_edge_port_description} - "
+                        f"Configure BGP peers for {current_edge_port.description} - "
                         f"({bgp_peer_index + 1}/{binding_port_input_form.bgp_peer_count})"
                     )
                 )
-                peer_address: IPv4AddressType | IPv6AddressType
+                peer_address: IPAddress
                 bfd_enabled: bool = False
                 bfd_interval: int | None = None
                 bfd_multiplier: int | None = None
@@ -109,6 +116,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
             bgp_peers.append(bgp_peer_input_form.model_dump())
 
         binding_port_input["bgp_peers"] = bgp_peers
+        binding_port_input["sbp_type"] = SBPType.L3
         binding_port_inputs.append(binding_port_input)
         current_ep_index += 1
 
-- 
GitLab