From 8b7046d1344377596f766c416f493c05cdef07b5 Mon Sep 17 00:00:00 2001
From: Neda Moeini <neda.moeini@geant.org>
Date: Tue, 12 Nov 2024 10:18:59 +0100
Subject: [PATCH] Add policer_burst_rate field to the creation and modification
 WF.

---
 gso/workflows/l2_circuit/create_layer_2_circuit.py | 11 ++++++++---
 gso/workflows/l2_circuit/modify_layer_2_circuit.py |  4 ++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gso/workflows/l2_circuit/create_layer_2_circuit.py b/gso/workflows/l2_circuit/create_layer_2_circuit.py
index a3199bc1..a7485897 100644
--- a/gso/workflows/l2_circuit/create_layer_2_circuit.py
+++ b/gso/workflows/l2_circuit/create_layer_2_circuit.py
@@ -52,6 +52,10 @@ def initial_input_generator(product_name: str) -> FormGenerator:
         """Return the appropriate field type based on whether the circuit is tagged."""
         return VLAN_ID if is_tagged else ReadOnlyField(None, default_type=int)
 
+    def _policer_field(*, policer_enabled: bool) -> BandwidthString:
+        """Return the appropriate field type based on whether the policer is enabled."""
+        return BandwidthString if policer_enabled else ReadOnlyField(None, default_type=str)
+
     class Layer2CircuitServiceSidesPage(FormPage):
         model_config = ConfigDict(title=f"{product_name} - Configure Edge Ports")
 
@@ -63,9 +67,8 @@ def initial_input_generator(product_name: str) -> FormGenerator:
             is_tagged=initial_user_input.layer_2_circuit_type == Layer2CircuitType.TAGGED
         )
         vlan_divider: Divider = Field(None, exclude=True)
-        policer_bandwidth: (  # type: ignore[valid-type]
-            BandwidthString if initial_user_input.policer_enabled else ReadOnlyField(None, default_type=str)
-        )
+        policer_bandwidth: _policer_field(policer_enabled=initial_user_input.policer_enabled)  # type: ignore[valid-type]
+        policer_burst_rate: _policer_field(policer_enabled=initial_user_input.policer_enabled)  # type: ignore[valid-type]
         geant_sid: str
 
         layer_2_circuit_side_a: Layer2CircuitSideSelection
@@ -102,6 +105,7 @@ def initialize_subscription(
     vlan_range_upper_bound: VLAN_ID | None,
     policer_enabled: bool,  # noqa: FBT001
     policer_bandwidth: BandwidthString | None,
+    policed_burst_rate: BandwidthString | None,
     geant_sid: str,
 ) -> State:
     """Build a subscription object from all user input."""
@@ -125,6 +129,7 @@ def initialize_subscription(
     subscription.layer_2_circuit.vlan_range_upper_bound = vlan_range_upper_bound
     subscription.layer_2_circuit.policer_enabled = policer_enabled
     subscription.layer_2_circuit.bandwidth = policer_bandwidth
+    subscription.layer_2_circuit.policer_burst_rate = policed_burst_rate
     subscription.description = f"{subscription.product.name} - {subscription.layer_2_circuit.virtual_circuit_id}"
 
     subscription = Layer2Circuit.from_other_lifecycle(subscription, SubscriptionLifecycle.PROVISIONING)
diff --git a/gso/workflows/l2_circuit/modify_layer_2_circuit.py b/gso/workflows/l2_circuit/modify_layer_2_circuit.py
index 7a3366b5..0ac2d391 100644
--- a/gso/workflows/l2_circuit/modify_layer_2_circuit.py
+++ b/gso/workflows/l2_circuit/modify_layer_2_circuit.py
@@ -49,8 +49,10 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
         vlan_divider: Divider = Field(None, exclude=True)
         if layer_2_circuit_input.policer_enabled:
             policer_bandwidth: BandwidthString = subscription.layer_2_circuit.bandwidth  # type: ignore[assignment]
+            policer_burst_rate: BandwidthString = subscription.layer_2_circuit.policer_burst_rate  # type: ignore[assignment]
         else:
             policer_bandwidth: ReadOnlyField(None, default_type=str)  # type: ignore[no-redef, valid-type]
+            policer_burst_rate: ReadOnlyField(None, default_type=str)  # type: ignore[no-redef, valid-type]
         policer_divider: Divider = Field(None, exclude=True)
 
         layer_2_circuit_side_a: ReadOnlyField(  # type: ignore[valid-type]
@@ -80,6 +82,7 @@ def modify_layer_2_circuit_subscription(
     vlan_range_upper_bound: VLAN_ID | None,
     policer_enabled: bool,  # noqa: FBT001
     policer_bandwidth: BandwidthString | None,
+    policer_burst_rate: BandwidthString | None,
 ) -> dict:
     """Update the Layer 2 Circuit subscription with the new values."""
     subscription.layer_2_circuit.layer_2_circuit_type = layer_2_circuit_type
@@ -87,6 +90,7 @@ def modify_layer_2_circuit_subscription(
     subscription.layer_2_circuit.vlan_range_upper_bound = vlan_range_upper_bound
     subscription.layer_2_circuit.policer_enabled = policer_enabled
     subscription.layer_2_circuit.bandwidth = policer_bandwidth
+    subscription.layer_2_circuit.policer_burst_rate = policer_burst_rate
     for layer_2_circuit_side in subscription.layer_2_circuit.layer_2_circuit_sides:
         layer_2_circuit_side.sbp.is_tagged = layer_2_circuit_type == Layer2CircuitType.TAGGED
 
-- 
GitLab