diff --git a/gso/migrations/versions/2024-04-19_ab8d805d27b3_add_creation_workflows_for_imported_.py b/gso/migrations/versions/2024-04-19_ab8d805d27b3_add_creation_workflows_for_imported_.py new file mode 100644 index 0000000000000000000000000000000000000000..3a1aa31859c0122c30d846b6baded4e7ba82074c --- /dev/null +++ b/gso/migrations/versions/2024-04-19_ab8d805d27b3_add_creation_workflows_for_imported_.py @@ -0,0 +1,63 @@ +"""Add creation workflows for imported products. + +Revision ID: ab8d805d27b3 +Revises: 3b73ee683cec +Create Date: 2024-04-19 16:21:07.304696 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'ab8d805d27b3' +down_revision = '3b73ee683cec' +branch_labels = None +depends_on = None + + +from orchestrator.migrations.helpers import create_workflow, delete_workflow + +new_workflows = [ + { + "name": "create_imported_site", + "target": "CREATE", + "description": "Import Site", + "product_type": "ImportedSite" + }, + { + "name": "create_imported_router", + "target": "CREATE", + "description": "Import router", + "product_type": "ImportedRouter" + }, + { + "name": "create_imported_iptrunk", + "target": "CREATE", + "description": "Import iptrunk", + "product_type": "ImportedIptrunk" + }, + { + "name": "create_imported_super_pop_switch", + "target": "CREATE", + "description": "Import Super PoP switch", + "product_type": "ImportedSuperPopSwitch" + }, + { + "name": "create_imported_office_router", + "target": "CREATE", + "description": "Import office router", + "product_type": "ImportedOfficeRouter" + } +] + + +def upgrade() -> None: + conn = op.get_bind() + for workflow in new_workflows: + create_workflow(conn, workflow) + + +def downgrade() -> None: + conn = op.get_bind() + for workflow in new_workflows: + delete_workflow(conn, workflow["name"]) diff --git a/gso/workflows/__init__.py b/gso/workflows/__init__.py index 1e89ec894bf9b3029484db458b6ea19e592c6c55..5e76a43db23e26f7f2244de5bcedf19343a28296 100644 --- a/gso/workflows/__init__.py +++ b/gso/workflows/__init__.py @@ -40,8 +40,10 @@ LazyWorkflowInstance("gso.workflows.router.modify_connection_strategy", "modify_ LazyWorkflowInstance("gso.workflows.site.create_site", "create_site") LazyWorkflowInstance("gso.workflows.site.modify_site", "modify_site") LazyWorkflowInstance("gso.workflows.site.terminate_site", "terminate_site") -LazyWorkflowInstance("gso.workflows.tasks.import_site", "import_site") -LazyWorkflowInstance("gso.workflows.tasks.import_router", "import_router") -LazyWorkflowInstance("gso.workflows.tasks.import_iptrunk", "import_iptrunk") -LazyWorkflowInstance("gso.workflows.tasks.import_super_pop_switch", "import_super_pop_switch") -LazyWorkflowInstance("gso.workflows.tasks.import_office_router", "import_office_router") +LazyWorkflowInstance("gso.workflows.site.create_imported_site", "create_imported_site") +LazyWorkflowInstance("gso.workflows.router.create_imported_router", "create_imported_router") +LazyWorkflowInstance("gso.workflows.iptrunk.create_imported_iptrunk", "create_imported_iptrunk") +LazyWorkflowInstance( + "gso.workflows.super_pop_switch.create_imported_super_pop_switch", "create_imported_super_pop_switch" +) +LazyWorkflowInstance("gso.workflows.office_router.create_imported_office_router", "create_imported_office_router") diff --git a/gso/workflows/office_router/create_imported_office_router.py b/gso/workflows/office_router/create_imported_office_router.py index 82c52fc4071272fc8f77c14af665aa42c2e5ed3a..7c1a1f19378d65263c93e23d5755574d26434b98 100644 --- a/gso/workflows/office_router/create_imported_office_router.py +++ b/gso/workflows/office_router/create_imported_office_router.py @@ -76,7 +76,7 @@ def initialize_subscription( initial_input_form=initial_input_form_generator, target=Target.CREATE, ) -def import_office_router() -> StepList: +def create_imported_office_router() -> StepList: """Import an office router without provisioning it.""" return ( init diff --git a/gso/workflows/tasks/import_super_pop_switch.py b/gso/workflows/super_pop_switch/create_imported_super_pop_switch.py similarity index 86% rename from gso/workflows/tasks/import_super_pop_switch.py rename to gso/workflows/super_pop_switch/create_imported_super_pop_switch.py index 5f2796c2c2325ad439a0570db5154f57a0b435f1..14b58256882eae40962ce717921404bcd69d6b2d 100644 --- a/gso/workflows/tasks/import_super_pop_switch.py +++ b/gso/workflows/super_pop_switch/create_imported_super_pop_switch.py @@ -10,8 +10,7 @@ from orchestrator.workflow import StepList, done, init, step from orchestrator.workflows.steps import resync, set_status, store_process_subscription from gso.products import ProductName -from gso.products.product_types import super_pop_switch -from gso.products.product_types.super_pop_switch import SuperPopSwitchInactive +from gso.products.product_types.super_pop_switch import ImportedSuperPopSwitchInactive from gso.services import subscriptions from gso.services.partners import get_partner_by_name from gso.services.subscriptions import get_site_by_name @@ -23,8 +22,8 @@ from gso.utils.shared_enums import PortNumber, Vendor def create_subscription(partner: str) -> State: """Create a new subscription object.""" partner_id = get_partner_by_name(partner)["partner_id"] - product_id = subscriptions.get_product_id_by_name(ProductName.SUPER_POP_SWITCH) - subscription = SuperPopSwitchInactive.from_product_id(product_id, partner_id) + product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_SUPER_POP_SWITCH) + subscription = ImportedSuperPopSwitchInactive.from_product_id(product_id, partner_id) return { "subscription": subscription, @@ -52,7 +51,7 @@ def initial_input_form_generator() -> FormGenerator: @step("Initialize subscription") def initialize_subscription( - subscription: SuperPopSwitchInactive, + subscription: ImportedSuperPopSwitchInactive, hostname: str, super_pop_switch_ts_port: PortNumber, super_pop_switch_site: str, @@ -68,10 +67,6 @@ def initialize_subscription( subscription.super_pop_switch.super_pop_switch_mgmt_ipv4_address = super_pop_switch_mgmt_ipv4_address subscription.super_pop_switch.vendor = Vendor.JUNIPER - subscription = super_pop_switch.SuperPopSwitchProvisioning.from_other_lifecycle( - subscription, SubscriptionLifecycle.PROVISIONING - ) - return {"subscription": subscription} @@ -80,7 +75,7 @@ def initialize_subscription( initial_input_form=initial_input_form_generator, target=Target.CREATE, ) -def import_super_pop_switch() -> StepList: +def create_imported_super_pop_switch() -> StepList: """Import a Super PoP switch without provisioning it.""" return ( init diff --git a/gso/workflows/tasks/__init__.py b/gso/workflows/tasks/__init__.py deleted file mode 100644 index 3f8c21608af4db6181ae4cd184959737898977bf..0000000000000000000000000000000000000000 --- a/gso/workflows/tasks/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Task workflows that are either started by an :term:`API` endpoint, or by one of the set schedules."""