diff --git a/gso/settings.py b/gso/settings.py index 3596eb1cfcd6855d38c077f10f2babb1bd10ade5..eaeeada908de6f8525311da1db7031e394f747da 100644 --- a/gso/settings.py +++ b/gso/settings.py @@ -209,6 +209,7 @@ class MoodiParams(BaseSettings): """Settings for Moodi.""" host: str + moodi_enabled: bool = False class OSSParams(BaseSettings): diff --git a/gso/utils/workflow_steps.py b/gso/utils/workflow_steps.py index 6c53f2fcead3f1f3743828f55975197bdb7ac626..3ce208a8de33ca92c255351099999e7af9bf625b 100644 --- a/gso/utils/workflow_steps.py +++ b/gso/utils/workflow_steps.py @@ -7,6 +7,7 @@ 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 orchestrator.workflow import StepList, begin, conditional from pydantic import ConfigDict from pydantic_forms.core import FormPage from pydantic_forms.types import FormGenerator @@ -14,7 +15,7 @@ from pydantic_forms.validators import Label from gso.products.product_blocks.router import RouterRole from gso.products.product_types.iptrunk import Iptrunk -from gso.services.lso_client import LSOState +from gso.services.lso_client import LSOState, lso_interaction from gso.settings import load_oss_params from gso.utils.helpers import generate_inventory_for_active_routers from gso.utils.shared_enums import Vendor @@ -391,25 +392,34 @@ def prompt_sharepoint_checklist_url(checklist_url: str) -> FormGenerator: return {} -@step("Start Moodi") -def start_moodi(subscription: dict[str, Any]) -> LSOState: +_is_moodi_enabled = conditional(lambda _: load_oss_params().MOODI.moodi_enabled) + + +def start_moodi() -> StepList: """Start monitoring on demand using Moodi Telemetry stack.""" - params = load_oss_params() + host = load_oss_params().MOODI.host - return { - "playbook_name": "moodi_telemetry/playbooks/start_moodi.yaml", - "inventory": {"all": {"hosts": {params.MOODI.host: None}}}, - "extra_vars": {"subscription": subscription}, - } + @step("Start Moodi") + def _start_moodi(subscription: dict[str, Any]) -> LSOState: + return { + "playbook_name": "moodi_telemetry/playbooks/start_moodi.yaml", + "inventory": {"all": {"hosts": {host: None}}}, + "extra_vars": {"subscription": subscription}, + } + return begin >> _is_moodi_enabled(begin >> lso_interaction(_start_moodi)) -@step("Stop Moodi") -def stop_moodi() -> LSOState: - """Stop monitoring on demand.""" - params = load_oss_params() - return { - "playbook_name": "moodi_telemetry/playbooks/stop_moodi.yaml", - "inventory": {"all": {"hosts": {params.MOODI.host: None}}}, - "extra_vars": None, - } +def stop_moodi() -> StepList: + """Stop Moodi Telemetry monitoring on demand.""" + host = load_oss_params().MOODI.host + + @step("Stop Moodi") + def _stop_moodi() -> LSOState: + return { + "playbook_name": "moodi_telemetry/playbooks/stop_moodi.yaml", + "inventory": {"all": {"hosts": {host: None}}}, + "extra_vars": None, + } + + return begin >> _is_moodi_enabled(begin >> lso_interaction(_stop_moodi)) diff --git a/gso/workflows/edge_port/create_edge_port.py b/gso/workflows/edge_port/create_edge_port.py index 5977206dfaa57ce4bf271c69464e440aa0fdc722..3782800b426fc0b4f08fd70a6dfa2a72947c11fb 100644 --- a/gso/workflows/edge_port/create_edge_port.py +++ b/gso/workflows/edge_port/create_edge_port.py @@ -31,6 +31,7 @@ from gso.utils.helpers import ( ) from gso.utils.types.interfaces import LAGMember, PhysicalPortCapacity from gso.utils.types.tt_number import TTNumber +from gso.utils.workflow_steps import start_moodi, stop_moodi from gso.workflows.shared import create_summary_form @@ -267,11 +268,13 @@ def create_edge_port() -> StepList: >> create_subscription >> store_process_subscription(Target.CREATE) >> initialize_subscription + >> start_moodi() >> reserve_interfaces_in_netbox >> lso_interaction(create_edge_port_dry) >> lso_interaction(create_edge_port_real) >> allocate_interfaces_in_netbox >> set_status(SubscriptionLifecycle.ACTIVE) >> resync + >> stop_moodi() >> done )