Skip to content

Modify connection strategy

Modify connection strategy workflow.

Run this workflow to change the way Ansible playbooks connect to a router. Either via OOB access, or directly to the loopback interface.

initial_input_form_generator(subscription_id)

Modify the connection strategy initial form.

Source code in gso/workflows/router/modify_connection_strategy.py
def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
    """Modify the connection strategy initial form."""
    subscription = Router.from_subscription(subscription_id)

    current_connection_strategy = (
        ConnectionStrategy.OUT_OF_BAND if subscription.router.router_access_via_ts else ConnectionStrategy.IN_BAND
    )

    class ModifyConnectionStrategyForm(SubmitFormPage):
        model_config = ConfigDict(title=f"Modify the connection strategy of {subscription.router.router_fqdn}.")

        connection_strategy: ConnectionStrategy = current_connection_strategy

    user_input = yield ModifyConnectionStrategyForm

    return user_input.model_dump()

update_subscription_model(subscription, connection_strategy)

Update the database model to reflect the new connection strategy.

If the connection strategy is set to in-band, then access_via_ts should be set to False. Conversely, if the connection strategy is set to out-of-band, access_via_ts should be set to True.

Source code in gso/workflows/router/modify_connection_strategy.py
@step("Update subscription model")
def update_subscription_model(subscription: Router, connection_strategy: str) -> State:
    """Update the database model to reflect the new connection strategy.

    If the connection strategy is set to in-band, then access_via_ts should be set to False.
    Conversely, if the connection strategy is set to out-of-band, access_via_ts should be set to True.
    """
    subscription.router.router_access_via_ts = connection_strategy == ConnectionStrategy.OUT_OF_BAND

    return {"subscription": subscription}

modify_connection_strategy()

Modify the connection strategy.

Source code in gso/workflows/router/modify_connection_strategy.py
@workflow(
    "Modify connection strategy",
    initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator),
    target=Target.MODIFY,
)
def modify_connection_strategy() -> StepList:
    """Modify the connection strategy."""
    return begin >> store_process_subscription(Target.MODIFY) >> unsync >> update_subscription_model >> resync >> done