diff --git a/gso/services/subscriptions.py b/gso/services/subscriptions.py index d82c66c9b0a42aa83b62fe731e40710a41c85005..85d3972630333ec4295c7bb624b04ac050978e97 100644 --- a/gso/services/subscriptions.py +++ b/gso/services/subscriptions.py @@ -253,3 +253,18 @@ def get_site_by_name(site_name: str) -> Site: raise ValueError(msg) return Site.from_subscription(subscription[0].subscription_id) + + +def get_all_active_sites() -> list[dict[str, Any]]: + """Retrieve all active sites subscription together with instance values. + + :return: A list of active sites with their subscription IDs and site instances. + :rtype: list[dict[str, Any]] + """ + return [ + { + "subscription_id": subscription["subscription_id"], + "site": Site.from_subscription(subscription["subscription_id"]).site, + } + for subscription in get_active_site_subscriptions(includes=["subscription_id"]) + ] diff --git a/gso/workflows/router/promote_p_to_pe.py b/gso/workflows/router/promote_p_to_pe.py index a910a5710dff6d940f7e671770e7e1280c104c02..ff0902c2f9aa3ffba05cffca38e5d874a87d1da1 100644 --- a/gso/workflows/router/promote_p_to_pe.py +++ b/gso/workflows/router/promote_p_to_pe.py @@ -1,5 +1,6 @@ """Promote a P router to a PE router.""" +import json from typing import Any from orchestrator.config.assignee import Assignee @@ -8,6 +9,7 @@ from orchestrator.forms.validators import Label from orchestrator.targets import Target from orchestrator.types import FormGenerator, State, UUIDstr from orchestrator.utils.errors import ProcessFailureError +from orchestrator.utils.json import json_dumps from orchestrator.workflow import StepList, begin, conditional, done, inputstep, step, workflow from orchestrator.workflows.steps import resync, store_process_subscription, unsync from orchestrator.workflows.utils import wrap_modify_initial_input_form @@ -18,6 +20,7 @@ from gso.products.product_types.router import Router from gso.services import lso_client from gso.services.kentik_client import KentikClient, NewKentikDevice from gso.services.lso_client import lso_interaction +from gso.services.subscriptions import get_all_active_sites from gso.utils.helpers import generate_inventory_for_active_routers from gso.utils.shared_enums import Vendor from gso.utils.types import TTNumber @@ -66,6 +69,7 @@ def deploy_pe_base_config_dry( "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - deploy PE base config", "verb": "deploy_pe_base_config", "pe_router_list": generate_inventory_for_active_routers(RouterRole.PE)["all"]["hosts"], + "geant_sites": json.loads(json_dumps(get_all_active_sites())), } lso_client.execute_playbook( @@ -87,6 +91,7 @@ def deploy_pe_base_config_real( "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - deploy PE base config", "verb": "deploy_pe_base_config", "pe_router_list": generate_inventory_for_active_routers(RouterRole.PE)["all"]["hosts"], + "geant_sites": json.loads(json_dumps(get_all_active_sites())), } lso_client.execute_playbook(