Skip to content
Snippets Groups Projects
Verified Commit 51ffc223 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

use a conditional to skip a step in terminate_router

parent 3d1d07b9
No related branches found
No related tags found
1 merge request!128Feature/use conditionals
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment