From e578228f6ada897fd8363c5d76f7a53c3eb828bc Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Thu, 29 Aug 2024 14:35:02 +0200 Subject: [PATCH] Add activate_switch workflow --- gso/workflows/switch/activate_switch.py | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 gso/workflows/switch/activate_switch.py diff --git a/gso/workflows/switch/activate_switch.py b/gso/workflows/switch/activate_switch.py new file mode 100644 index 00000000..1d0d7113 --- /dev/null +++ b/gso/workflows/switch/activate_switch.py @@ -0,0 +1,50 @@ +"""Workflow for activating a switch, making it available to other subscriptions.""" + +from orchestrator.config.assignee import Assignee +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, begin, done, inputstep, workflow +from orchestrator.workflows.steps import resync, set_status, store_process_subscription, unsync +from orchestrator.workflows.utils import wrap_modify_initial_input_form + +from gso.products.product_types.switch import Switch + + +def _initial_input_form(subscription_id: UUIDstr) -> FormGenerator: + switch = Switch.from_subscription(subscription_id) + + class ActivateSwitchForm(FormPage): + info_label: Label = "Start approval process for switch activation." + + yield ActivateSwitchForm + return {"subscription": switch} + + +@inputstep("Verify checklist completion", assignee=Assignee.SYSTEM) +def verify_complete_checklist() -> FormGenerator: + """Ask the operator to provide a link to the completed checklist in SharePoint.""" + + class VerifyCompleteForm(FormPage): + info_label: Label = "Please enter URL to the completed checklist in SharePoint. Then continue this workflow." + checklist_url: str = "" + + user_input = yield VerifyCompleteForm + return {"checklist_url": user_input.model_dump()["checklist_url"]} + + +@workflow( + "Activate switch", initial_input_form=(wrap_modify_initial_input_form(_initial_input_form)), target=Target.MODIFY +) +def activate_switch() -> StepList: + """Take a switch and move it from a `PROVISIONING` to an `ACTIVE` state.""" + return ( + begin + >> store_process_subscription(Target.MODIFY) + >> unsync + >> verify_complete_checklist + >> set_status(SubscriptionLifecycle.ACTIVE) + >> resync + >> done + ) -- GitLab