diff --git a/gso/workflows/switch/create_switch.py b/gso/workflows/switch/create_switch.py index f4e6fc1615137001c9e879bea443a3ada2f2f221..cd4c066f35f5d1eb4d7dbe1af78418bb3ed7493c 100644 --- a/gso/workflows/switch/create_switch.py +++ b/gso/workflows/switch/create_switch.py @@ -17,13 +17,14 @@ from gso.products.product_blocks.switch import SwitchModel from gso.products.product_types.site import Site from gso.products.product_types.switch import SwitchInactive from gso.services import infoblox -from gso.services.lso_client import execute_playbook, lso_interaction +from gso.services.lso_client import LSOState, lso_interaction from gso.services.partners import get_partner_by_name from gso.services.sharepoint import SharePointClient from gso.settings import load_oss_params from gso.utils.helpers import active_site_selector, generate_fqdn -from gso.utils.shared_enums import PortNumber, Vendor -from gso.utils.types import TTNumber +from gso.utils.shared_enums import Vendor +from gso.utils.types.ip_address import PortNumber +from gso.utils.types.tt_number import TTNumber from gso.utils.workflow_steps import prompt_sharepoint_checklist_url @@ -34,6 +35,7 @@ def _initial_input_form_generator(product_name: str) -> FormGenerator: model_config = ConfigDict(title=product_name) tt_number: TTNumber + partner: ReadOnlyField("GEANT", default_type=str) # type: ignore[valid-type] switch_site: active_site_selector() # type: ignore[valid-type] hostname: str ts_port: PortNumber @@ -63,7 +65,7 @@ def create_subscription(product: UUIDstr, partner: str) -> State: """Create a new subscription object.""" subscription = SwitchInactive.from_product_id(product, get_partner_by_name(partner)["partner_id"]) - return {"subscription": subscription} + return {"subscription": subscription, "subscription_id": subscription.subscription_id} @step("Initialize subscription") @@ -76,11 +78,11 @@ def initialize_subscription( hostname: str, ) -> State: """Initialize the subscription with user input.""" - subscription.switch.switch_site = Site.from_subscription(switch_site).site - subscription.switch.switch_fqdn = generate_fqdn( - hostname, subscription.switch.switch_site.site_name, subscription.switch.switch_site.site_country_code + subscription.switch.site = Site.from_subscription(switch_site).site + subscription.switch.fqdn = generate_fqdn( + hostname, subscription.switch.site.site_name, subscription.switch.site.site_country_code ) - subscription.switch.switch_ts_port = ts_port + subscription.switch.ts_port = ts_port subscription.switch.switch_vendor = vendor subscription.switch.switch_model = model @@ -88,10 +90,8 @@ def initialize_subscription( @step("[DRY RUN] Deploy base config") -def deploy_base_config_dry(subscription: dict, tt_number: str, callback_route: str, process_id: UUIDstr) -> None: +def deploy_base_config_dry(subscription: dict, tt_number: str, process_id: UUIDstr) -> LSOState: """Perform a dry run of provisioning base config on a switch.""" - inventory = subscription["switch"]["switch_fqdn"] - extra_vars = { "subscription_json": subscription, "dry_run": True, @@ -99,19 +99,16 @@ def deploy_base_config_dry(subscription: dict, tt_number: str, callback_route: s "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Deploy base config", } - execute_playbook( - playbook_name="switch_base_config.yaml", - callback_route=callback_route, - inventory=inventory, - extra_vars=extra_vars, - ) + return { + "playbook_name": "switch_base_config.yaml", + "extra_vars": extra_vars, + "inventory": {"all": {"hosts": {subscription["switch"]["fqdn"]: None}}}, + } @step("[FOR REAL] Deploy base config") -def deploy_base_config_real(subscription: dict, tt_number: str, callback_route: str, process_id: UUIDstr) -> None: +def deploy_base_config_real(subscription: dict, tt_number: str, process_id: UUIDstr) -> LSOState: """Provision base config on a switch.""" - inventory = subscription["switch"]["switch_fqdn"] - extra_vars = { "subscription_json": subscription, "dry_run": False, @@ -119,12 +116,11 @@ def deploy_base_config_real(subscription: dict, tt_number: str, callback_route: "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Deploy base config", } - execute_playbook( - playbook_name="switch_base_config.yaml", - callback_route=callback_route, - inventory=inventory, - extra_vars=extra_vars, - ) + return { + "playbook_name": "switch_base_config.yaml", + "extra_vars": extra_vars, + "inventory": {"all": {"hosts": {subscription["switch"]["fqdn"]: None}}}, + } @inputstep("Prompt for console login", assignee=Assignee.SYSTEM) @@ -161,27 +157,26 @@ def create_netbox_device() -> State: @step("Run post-deployment checks") -def run_post_deploy_checks(subscription: dict, callback_route: str) -> None: +def run_post_deploy_checks(subscription: dict) -> LSOState: """Workflow step for running checks after installing base config.""" - execute_playbook( - playbook_name="switch_base_config_checks.yaml", - callback_route=callback_route, - inventory=subscription["switch"]["switch_fqdn"], - extra_vars={"subscription_json": subscription}, - ) + return { + "playbook_name": "switch_base_config_checks.yaml", + "extra_vars": {"subscription_json": subscription}, + "inventory": {"all": {"hosts": {subscription["switch"]["fqdn"]: None}}}, + } @step("Create a new SharePoint checklist") def create_new_sharepoint_checklist(subscription: SwitchInactive, tt_number: str, process_id: UUIDstr) -> State: """Create a new checklist in SharePoint for approving this router.""" - if not subscription.switch.switch_fqdn: + if not subscription.switch.fqdn: msg = "Switch is missing an FQDN." raise ProcessFailureError(msg, details=subscription.subscription_id) new_list_item_url = SharePointClient().add_list_item( list_name="switch", fields={ - "Title": subscription.switch.switch_fqdn, + "Title": subscription.switch.fqdn, "TT_NUMBER": tt_number, "GAP_PROCESS_URL": f"{load_oss_params().GENERAL.public_hostname}/workflows/{process_id}", },