From b8b6762c707e2dc80258b5df757d447376f12b1f Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Tue, 18 Jul 2023 14:29:26 +0200
Subject: [PATCH] update intake form of device termination workflow

added two checkboxes that take care of removing config, and cleaning up IPAM
made the corresponding steps in the workflow conditional, so they are skipped if unchecked
---
 gso/translations/en-GB.json              |  4 ++-
 gso/workflows/device/terminate_device.py | 32 ++++++++++++++++--------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/gso/translations/en-GB.json b/gso/translations/en-GB.json
index 845ad732..a4ee0dfc 100644
--- a/gso/translations/en-GB.json
+++ b/gso/translations/en-GB.json
@@ -29,7 +29,9 @@
             "iptrunk_sideB_ae_iface": "Aggregated Ethernet interface name",
             "iptrunk_sideB_ae_geant_a_sid": "GÉANT A-SID",
             "iptrunk_sideB_ae_members": "Aggregated Ethernet member interface names",
-            "iptrunk_sideB_ae_members_descriptions": "Aggregated Ethernet member interface descriptions"
+            "iptrunk_sideB_ae_members_descriptions": "Aggregated Ethernet member interface descriptions",
+            "remove_configuration": "Remove configuration from the device",
+            "clean_up_ipam": "Clean up related entries in IPAM"
         }
     },
     "workflow": {
diff --git a/gso/workflows/device/terminate_device.py b/gso/workflows/device/terminate_device.py
index b7564d2a..1ad4a487 100644
--- a/gso/workflows/device/terminate_device.py
+++ b/gso/workflows/device/terminate_device.py
@@ -5,7 +5,7 @@ from orchestrator.forms import FormPage
 from orchestrator.forms.validators import Label
 from orchestrator.targets import Target
 from orchestrator.types import FormGenerator, SubscriptionLifecycle, UUIDstr
-from orchestrator.workflow import StepList, done, init, step, workflow
+from orchestrator.workflow import StepList, conditional, done, init, step, workflow
 from orchestrator.workflows.steps import resync, set_status, store_process_subscription, unsync
 from orchestrator.workflows.utils import wrap_modify_initial_input_form
 
@@ -21,14 +21,15 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
     subscription = Device.from_subscription(subscription_id)
 
     class TerminateForm(FormPage):
-        are_you_sure: Label = f"Are you sure you want to remove {subscription.description}?"  # type: ignore
+        termination_label: Label = (
+            f"Please confirm whether configuration should get removed from the {subscription.device_type}, and "
+            "whether IPAM resources should be released."  # type: ignore
+        )
+        remove_configuration: bool = True
+        clean_up_ipam: bool = True
 
-    return TerminateForm  # type: ignore
-
-
-def _deprovision_in_user_management_system(fqdn: str) -> None:
-    logger.debug(fqdn)
-    pass
+    user_input = yield TerminateForm
+    return user_input.dict()
 
 
 @step("Deprovision loopback IPs from IPAM/DNS")
@@ -74,19 +75,28 @@ def deprovision_lt_ips(subscription: Device) -> dict[str, V4ServiceNetwork | V6S
     }
 
 
+@step("Remove configuration from device")
+def remove_config_from_device() -> None:
+    pass
+
+
 @workflow(
     "Terminate device",
     initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator),
     target=Target.TERMINATE,
 )
 def terminate_device() -> StepList:
+    run_ipam_steps = conditional(lambda state: state.get("clean_up_ipam", True))
+    run_config_steps = conditional(lambda state: state.get("remove_configuration", True))
+
+    ipam_steps = StepList([deprovision_loopback_ips, deprovision_si_ips, deprovision_lt_ips])
+
     return (
         init
         >> store_process_subscription(Target.TERMINATE)
         >> unsync
-        >> deprovision_loopback_ips
-        >> deprovision_si_ips
-        >> deprovision_lt_ips
+        >> run_ipam_steps(ipam_steps)
+        >> run_config_steps(remove_config_from_device)
         >> set_status(SubscriptionLifecycle.TERMINATED)
         >> resync
         >> done
-- 
GitLab