diff --git a/gso/workflows/router/create_router.py b/gso/workflows/router/create_router.py index 8b37cd07c4065ab4e72a66782828bd36e32164a4..e1f5efb7ca2780ae5ff88d21719f00949201da01 100644 --- a/gso/workflows/router/create_router.py +++ b/gso/workflows/router/create_router.py @@ -2,12 +2,11 @@ from typing import Any -# noinspection PyProtectedMember from orchestrator.forms import FormPage from orchestrator.forms.validators import Choice from orchestrator.targets import Target from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr -from orchestrator.workflow import StepList, done, init, step, workflow, conditional +from orchestrator.workflow import StepList, conditional, done, init, step, workflow from orchestrator.workflows.steps import resync, set_status, store_process_subscription from orchestrator.workflows.utils import wrap_create_initial_input_form from pydantic import validator diff --git a/gso/workflows/router/terminate_router.py b/gso/workflows/router/terminate_router.py index b258cf7644c239bea092aeb77de316ab9b6cfb10..b7d70d1ed378a357be2b7b1c7832e859ab001897 100644 --- a/gso/workflows/router/terminate_router.py +++ b/gso/workflows/router/terminate_router.py @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: """Let the operator decide whether to delete configuration on the router, and clear up :term:`IPAM` resources.""" - Router.from_subscription(subscription_id) + router = Router.from_subscription(subscription_id) class TerminateForm(FormPage): termination_label: Label = ( @@ -38,7 +38,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: clean_up_ipam: bool = True user_input = yield TerminateForm - return user_input.dict() + return user_input.dict() | {"router_is_nokia": router.router.vendor == RouterVendor.NOKIA} @step("Deprovision loopback IPs from IPAM") @@ -58,12 +58,10 @@ def remove_config_from_router() -> None: """ -@step("Remove Device from NetBox") +@step("Remove Device from Netbox") def remove_device_from_netbox(subscription: Router) -> dict[str, Router]: """Remove the device from Netbox.""" - if subscription.router.vendor == RouterVendor.NOKIA: - # TODO: This should be solved with a conditional - NetboxClient().delete_device(subscription.router.router_fqdn) + NetboxClient().delete_device(subscription.router.router_fqdn) return {"subscription": subscription} @@ -82,6 +80,7 @@ def terminate_router() -> StepList: """ run_ipam_steps = conditional(lambda state: state["clean_up_ipam"]) run_config_steps = conditional(lambda state: state["remove_configuration"]) + router_is_nokia = conditional(lambda state: state["router_is_nokia"]) return ( init @@ -89,7 +88,7 @@ def terminate_router() -> StepList: >> unsync >> run_ipam_steps(deprovision_loopback_ips) >> run_config_steps(remove_config_from_router) - >> remove_device_from_netbox + >> router_is_nokia(remove_device_from_netbox) >> set_status(SubscriptionLifecycle.TERMINATED) >> resync >> done