diff --git a/gso/migrations/versions/2024-04-23_8ebfc8a34c2e_add_site_modification_import_workflow.py b/gso/migrations/versions/2024-04-23_8ebfc8a34c2e_add_site_modification_import_workflow.py new file mode 100644 index 0000000000000000000000000000000000000000..f1802a3fc5f908cee9bd04c5543fc57a6f7122a2 --- /dev/null +++ b/gso/migrations/versions/2024-04-23_8ebfc8a34c2e_add_site_modification_import_workflow.py @@ -0,0 +1,39 @@ +"""Add site modification import workflow. + +Revision ID: 8ebfc8a34c2e +Revises: ab8d805d27b3 +Create Date: 2024-04-23 11:32:39.502729 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = '8ebfc8a34c2e' +down_revision = 'ab8d805d27b3' +branch_labels = None +depends_on = None + + +from orchestrator.migrations.helpers import create_workflow, delete_workflow + +new_workflows = [ + { + "name": "import_site", + "target": "MODIFY", + "description": "Import Site", + "product_type": "ImportedSite" + } +] + + +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/translations/en-GB.json b/gso/translations/en-GB.json index 2ef5f1c0dbcc9d0033804b266fb9c468e9dcdd65..e2b50e04428c0b4cd130c2d9b4ee487eac2290b2 100644 --- a/gso/translations/en-GB.json +++ b/gso/translations/en-GB.json @@ -50,6 +50,7 @@ "create_imported_router": "NOT FOR HUMANS -- Import existing router", "create_imported_iptrunk": "NOT FOR HUMANS -- Import existing IP trunk", "create_imported_super_pop_switch": "NOT FOR HUMANS -- Import existing super PoP switch", - "create_imported_office_router": "NOT FOR HUMANS -- Import existing office router" + "create_imported_office_router": "NOT FOR HUMANS -- Import existing office router", + "import_site": "Finalize import into a Site product" } } diff --git a/gso/workflows/__init__.py b/gso/workflows/__init__.py index 5e76a43db23e26f7f2244de5bcedf19343a28296..535f6e1f5715101f431cfef83934033909b31869 100644 --- a/gso/workflows/__init__.py +++ b/gso/workflows/__init__.py @@ -41,6 +41,7 @@ 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.site.create_imported_site", "create_imported_site") +LazyWorkflowInstance("gso.workflows.site.import_site", "import_site") LazyWorkflowInstance("gso.workflows.router.create_imported_router", "create_imported_router") LazyWorkflowInstance("gso.workflows.iptrunk.create_imported_iptrunk", "create_imported_iptrunk") LazyWorkflowInstance( diff --git a/gso/workflows/site/import_site.py b/gso/workflows/site/import_site.py new file mode 100644 index 0000000000000000000000000000000000000000..b49e8a0647fdd5f89e274d558bcf735aa78cee67 --- /dev/null +++ b/gso/workflows/site/import_site.py @@ -0,0 +1,27 @@ +"""A modification workflow for setting a new :term:`ISIS` metric for an IP trunk.""" + +from orchestrator.targets import Target +from orchestrator.types import State, UUIDstr +from orchestrator.workflow import StepList, done, init, step, workflow +from orchestrator.workflows.steps import resync, store_process_subscription, unsync +from orchestrator.workflows.utils import wrap_modify_initial_input_form + +from gso.products import ProductName +from gso.products.product_types.site import ImportedSite, Site +from gso.services.subscriptions import get_product_id_by_name + + +@step("Create new site subscription") +def import_site_subscription(subscription_id: UUIDstr) -> State: + """Take an ImportedSite subscription, and turn it into a Site subscription.""" + old_site = ImportedSite.from_subscription(subscription_id) + new_subscription_id = get_product_id_by_name(ProductName.SITE) + new_subscription = Site.from_other_product(old_site, new_subscription_id) + + return {"subscription": new_subscription} + + +@workflow("Import Site", target=Target.MODIFY, initial_input_form=wrap_modify_initial_input_form(None)) +def import_site() -> StepList: + """Modify an ImportedSite subscription into a Site subscription to complete the import.""" + return init >> store_process_subscription(Target.MODIFY) >> unsync >> import_site_subscription >> resync >> done