Skip to content

Terminate switch

Workflow for terminating a switch.

_input_form_generator(subscription_id)

Input form to confirm that this switch indeed must be terminated.

Source code in gso/workflows/switch/terminate_switch.py
def _input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
    """Input form to confirm that this switch indeed must be terminated."""
    switch = Switch.from_subscription(subscription_id)

    class TerminateForm(SubmitFormPage):
        if switch.status == SubscriptionLifecycle.INITIAL:
            info_label: Label = (
                "This will immediately mark the subscription as terminated, preventing any other workflows from "
                "interacting with this product subscription."
            )
            info_label_2: Label = "ONLY EXECUTE THIS WORKFLOW WHEN YOU ARE ABSOLUTELY SURE WHAT YOU ARE DOING."

        tt_number: TTNumber

    yield TerminateForm
    return {"subscription": switch}

remove_device_from_netbox(subscription)

Remove the switch from Netbox.

Source code in gso/workflows/switch/terminate_switch.py
@step("Remove switch from Netbox")
def remove_device_from_netbox(subscription: Switch) -> None:
    """Remove the switch from Netbox."""
    NetboxClient().delete_device(subscription.switch.fqdn)

remove_device_from_ipam(subscription)

Remove the switch from IPAM.

Source code in gso/workflows/switch/terminate_switch.py
@step("Remove switch from IPAM")
def remove_device_from_ipam(subscription: Switch) -> None:
    """Remove the switch from IPAM."""
    delete_host_by_fqdn(subscription.switch.fqdn)

terminate_switch()

Terminate a switch subscription.

  • Remove the switch from Netbox
  • Mark the service as terminated in the service database
Source code in gso/workflows/switch/terminate_switch.py
@workflow(
    "Terminate switch",
    initial_input_form=wrap_modify_initial_input_form(_input_form_generator),
    target=Target.TERMINATE,
)
def terminate_switch() -> StepList:
    """Terminate a switch subscription.

    * Remove the switch from Netbox
    * Mark the service as terminated in the service database
    """
    return (
        begin
        >> store_process_subscription(Target.TERMINATE)
        >> unsync
        >> remove_device_from_netbox
        >> remove_device_from_ipam
        >> set_status(SubscriptionLifecycle.TERMINATED)
        >> resync
        >> done
    )