Skip to content
Snippets Groups Projects
Select Git revision
  • 2ccc756a64d3000e296420c1769a0e85eda4107b
  • develop default protected
  • master protected
  • authorship-fix-from-develop
  • 1048-service-config-backfilling
  • feature/nat-1211-edgeport-lacp-xmit
  • fix/nat-1120-sdp-validation
  • NAT-1154-import-edge-port-update
  • fix/l3-imports
  • feature/10GGBS-NAT-980
  • fix/NAT-1009/fix-redeploy-base-config-if-there-is-a-vprn
  • 4.24
  • 4.23
  • 4.22
  • 4.21
  • 4.20
  • 4.19
  • 4.18
  • 4.17
  • 4.16
  • 4.15
  • 4.14
  • 4.13
  • 4.12
  • 4.11
  • 4.10
  • 4.8
  • 4.5
  • 4.4
  • 4.3
  • 4.2
31 results

workflow_steps.py

Blame
  • user avatar
    Aleksandr Kurbatov authored
    2ccc756a
    History
    workflow_steps.py 7.88 KiB
    """Workflow steps that are shared across multiple workflows."""
    
    import json
    from typing import Any
    
    from orchestrator import inputstep, step
    from orchestrator.config.assignee import Assignee
    from orchestrator.types import State, UUIDstr
    from orchestrator.utils.json import json_dumps
    from pydantic import ConfigDict
    from pydantic_forms.core import FormPage
    from pydantic_forms.types import FormGenerator
    from pydantic_forms.validators import Label
    
    from gso.products.product_blocks import router
    from gso.products.product_blocks.router import RouterRole
    from gso.products.product_types.iptrunk import Iptrunk
    from gso.services import lso_client
    from gso.settings import load_oss_params
    from gso.utils.helpers import generate_inventory_for_active_routers
    from gso.utils.shared_enums import Vendor
    
    
    def _deploy_base_config(
        subscription: dict[str, Any],
        tt_number: str,
        callback_route: str,
        process_id: UUIDstr,
        *,
        dry_run: bool,
    ) -> None:
        inventory = subscription["router"]["router_fqdn"]
    
        extra_vars = {
            "wfo_router_json": subscription,
            "dry_run": dry_run,
            "verb": "deploy",
            "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Deploy base config",
        }
    
        lso_client.execute_playbook(
            playbook_name="base_config.yaml",
            callback_route=callback_route,
            inventory=inventory,
            extra_vars=extra_vars,
        )
    
    
    def _update_sdp_mesh(
        subscription: dict[str, Any],
        callback_route: str,
        tt_number: str,
        process_id: UUIDstr,
        *,
        dry_run: bool,
    ) -> None:
        inventory = generate_inventory_for_active_routers(
            router_role=RouterRole.PE, router_vendor=Vendor.NOKIA, exclude_routers=[subscription["router"]["router_fqdn"]]
        )
        extra_vars = {
            "dry_run": dry_run,
            "subscription": subscription,
            "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - "
            f"Update the SDP mesh for L2circuits(epipes) config on PE NOKIA routers",
            "verb": "update_sdp_mesh",
            "pe_router_list": {
                subscription["router"]["router_fqdn"]: {
                    "lo4": str(subscription["router"]["router_lo_ipv4_address"]),
                    "lo6": str(subscription["router"]["router_lo_ipv6_address"]),
                }
            },
        }
    
        lso_client.execute_playbook(
            playbook_name="update_pe_sdp_mesh.yaml",
            callback_route=callback_route,
            inventory=inventory,
            extra_vars=extra_vars,
        )
    
    
    def _update_sdp_single_pe(
        subscription: dict[str, Any],
        callback_route: str,
        tt_number: str,
        process_id: UUIDstr,
        *,
        dry_run: bool,
    ) -> None:
        inventory = subscription["router"]["router_fqdn"]
        extra_vars = {
            "dry_run": dry_run,
            "subscription": subscription,
            "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - "
            f"Update the SDP mesh for L2circuits(epipes) config on PE NOKIA routers",
            "verb": "update_sdp_mesh",
            "pe_router_list": generate_inventory_for_active_routers(
                router.RouterRole.PE, exclude_routers=[subscription["router"]["router_fqdn"]]
            ),
        }
    
        lso_client.execute_playbook(
            playbook_name="update_pe_sdp_mesh.yaml",
            callback_route=callback_route,
            inventory=inventory,
            extra_vars=extra_vars,
        )
    
    
    @step("[DRY RUN] Deploy base config")
    def deploy_base_config_dry(
        subscription: dict[str, Any],
        tt_number: str,
        callback_route: str,
        process_id: UUIDstr,
    ) -> State:
        """Perform a dry run of provisioning base config on a router."""
        _deploy_base_config(subscription, tt_number, callback_route, process_id, dry_run=True)
    
        return {"subscription": subscription}
    
    
    @step("[FOR REAL] Deploy base config")
    def deploy_base_config_real(
        subscription: dict[str, Any],
        tt_number: str,
        callback_route: str,
        process_id: UUIDstr,
    ) -> State:
        """Deploy base config on a router using the provisioning proxy."""
        _deploy_base_config(subscription, tt_number, callback_route, process_id, dry_run=False)
    
        return {"subscription": subscription}
    
    
    @step("[DRY RUN] Include new PE into SDP mesh on other Nokia PEs")
    def update_sdp_mesh_dry(
        subscription: dict[str, Any], callback_route: str, tt_number: str, process_id: UUIDstr
    ) -> State:
        """Perform a dry run of including new PE router in SDP mesh on other NOKIA PE routers."""
        _update_sdp_mesh(subscription, tt_number, callback_route, process_id, dry_run=True)
    
        return {"subscription": subscription}
    
    
    @step("[FOR REAL] Include new PE into SDP mesh on other Nokia PEs")
    def update_sdp_mesh_real(
        subscription: dict[str, Any], callback_route: str, tt_number: str, process_id: UUIDstr
    ) -> State:
        """Include new PE router in SDP mesh on other NOKIA PE routers."""
        _update_sdp_mesh(subscription, tt_number, callback_route, process_id, dry_run=False)
    
        return {"subscription": subscription}
    
    
    @step("[DRY RUN] Configure SDP on a new PE to all other Nokia PEs")
    def update_sdp_single_pe_dry(
        subscription: dict[str, Any], callback_route: str, tt_number: str, process_id: UUIDstr
    ) -> State:
        """Perform a dry run of configuring SDP on a new PE router to all other NOKIA PE routers."""
        _update_sdp_single_pe(subscription, tt_number, callback_route, process_id, dry_run=True)
    
        return {"subscription": subscription}
    
    
    @step("[FOR REAL] Configure SDP on a new PE to all other Nokia PEs")
    def update_sdp_single_pe_real(
        subscription: dict[str, Any], callback_route: str, tt_number: str, process_id: UUIDstr
    ) -> State:
        """Configure SDP on a new PE router to all other NOKIA PE routers."""
        _update_sdp_single_pe(subscription, tt_number, callback_route, process_id, dry_run=False)
    
        return {"subscription": subscription}
    
    
    @step("[FOR REAL] Set ISIS metric to very high value")
    def set_isis_to_max(subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str) -> State:
        """Workflow step for setting the :term:`ISIS` metric to an arbitrarily high value to drain a link."""
        old_isis_metric = subscription.iptrunk.iptrunk_isis_metric
        params = load_oss_params()
        subscription.iptrunk.iptrunk_isis_metric = params.GENERAL.isis_high_metric
        extra_vars = {
            "wfo_trunk_json": json.loads(json_dumps(subscription)),
            "dry_run": False,
            "verb": "deploy",
            "config_object": "isis_interface",
            "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Deploy config for "
            f"{subscription.iptrunk.geant_s_sid}",
        }
    
        lso_client.execute_playbook(
            playbook_name="iptrunks.yaml",
            callback_route=callback_route,
            inventory=f"{subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.router_fqdn}\n"
            f"{subscription.iptrunk.iptrunk_sides[1].iptrunk_side_node.router_fqdn}\n",
            extra_vars=extra_vars,
        )
    
        return {
            "subscription": subscription,
            "old_isis_metric": old_isis_metric,
        }
    
    
    @step("Run show commands after base config install")
    def run_checks_after_base_config(subscription: dict[str, Any], callback_route: str) -> None:
        """Workflow step for running show commands after installing base config."""
        lso_client.execute_playbook(
            playbook_name="base_config_checks.yaml",
            callback_route=callback_route,
            inventory=subscription["router"]["router_fqdn"],
            extra_vars={"wfo_router_json": subscription},
        )
    
    
    @inputstep("Prompt for new SharePoint checklist", assignee=Assignee.SYSTEM)
    def prompt_sharepoint_checklist_url(checklist_url: str) -> FormGenerator:
        """Prompt the operator with the checklist in SharePoint for approving a new subscription."""
    
        class SharepointPrompt(FormPage):
            model_config = ConfigDict(title="Complete new checklist")
    
            info_label_1: Label = f"A new checklist has been created at: {checklist_url}"
            info_label_2: Label = "Click proceed to finish the workflow."
    
        yield SharepointPrompt
    
        return {}