From 9f707fdb992833a01aee26dd9f063d90a654f21e Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Wed, 4 Dec 2024 10:03:51 +0100 Subject: [PATCH] Add Switch models and make them selectable in the creation workflow --- ...e0c35e20_update_lan_switch_interconnect.py | 4 +-- ...-12-03_79a76b22ca53_clean_up_deprecated.py | 33 +++++++++++++++++++ gso/products/product_blocks/switch.py | 4 ++- gso/translations/en-GB.json | 4 +-- gso/workflows/switch/create_switch.py | 4 +-- 5 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 gso/migrations/versions/2024-12-03_79a76b22ca53_clean_up_deprecated.py diff --git a/gso/migrations/versions/2024-11-04_e854e0c35e20_update_lan_switch_interconnect.py b/gso/migrations/versions/2024-11-04_e854e0c35e20_update_lan_switch_interconnect.py index dd4c10d9..60a4438f 100644 --- a/gso/migrations/versions/2024-11-04_e854e0c35e20_update_lan_switch_interconnect.py +++ b/gso/migrations/versions/2024-11-04_e854e0c35e20_update_lan_switch_interconnect.py @@ -1,7 +1,7 @@ """Update LAN Switch Interconnect. Revision ID: e854e0c35e20 -Revises: 543afff041f9 +Revises: 28c1723c6a00 Create Date: 2024-11-04 17:21:14.612740 """ @@ -10,7 +10,7 @@ from alembic import op # revision identifiers, used by Alembic. revision = 'e854e0c35e20' -down_revision = '543afff041f9' +down_revision = '28c1723c6a00' branch_labels = None depends_on = None diff --git a/gso/migrations/versions/2024-12-03_79a76b22ca53_clean_up_deprecated.py b/gso/migrations/versions/2024-12-03_79a76b22ca53_clean_up_deprecated.py new file mode 100644 index 00000000..348f0467 --- /dev/null +++ b/gso/migrations/versions/2024-12-03_79a76b22ca53_clean_up_deprecated.py @@ -0,0 +1,33 @@ +"""Clean up deprecated references to NREN-names products + +Revision ID: 79a76b22ca53 +Revises: e854e0c35e20 +Create Date: 2024-12-03 17:01:33.752966 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = '79a76b22ca53' +down_revision = 'e854e0c35e20' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + conn = op.get_bind() + conn.execute(sa.text(""" +DELETE FROM product_product_blocks WHERE product_product_blocks.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('GÉANT IP', 'IAS', 'Imported GÉANT IP', 'Imported IAS')) AND product_product_blocks.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('NRENL3CoreServiceBlock')) + """)) + conn.execute(sa.text(""" +DELETE FROM subscription_instances WHERE subscription_instances.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('NRENL3CoreServiceBlock', 'NRENAccessPort')) + """)) + conn.execute(sa.text(""" +DELETE FROM product_blocks WHERE product_blocks.name IN ('NRENL3CoreServiceBlock', 'NRENAccessPort') + """)) + + +def downgrade() -> None: + conn = op.get_bind() + diff --git a/gso/products/product_blocks/switch.py b/gso/products/product_blocks/switch.py index f6bdb877..abf4a797 100644 --- a/gso/products/product_blocks/switch.py +++ b/gso/products/product_blocks/switch.py @@ -16,7 +16,9 @@ from gso.utils.types.ip_address import PortNumber class SwitchModel(strEnum): """Enumerator for the different types of switches.""" - EX3400 = "EX3400" + EX3400_24T = "EX3400 - 24T" + EX3400_48T = "EX3400 - 48T" + EX4300_32F = "EX4300 - 32F" class SwitchBlockInactive( diff --git a/gso/translations/en-GB.json b/gso/translations/en-GB.json index 2328bba2..c62d1c4d 100644 --- a/gso/translations/en-GB.json +++ b/gso/translations/en-GB.json @@ -12,10 +12,10 @@ "site_tier": "Site Tier", "site_ts_address": "Site Terminal Server Address", - "hostname": "Hostname of the new router, only the part that comes before the first period", + "hostname": "Hostname of the new device, only the part that comes before the first period", "ts_address": "IP address of the terminal server", "ts_port": "Port number of the terminal server", - "vendor": "Router vendor", + "vendor": "Device vendor", "router_role": "Router role", "geant_s_sid": "GÉANT S-SID", diff --git a/gso/workflows/switch/create_switch.py b/gso/workflows/switch/create_switch.py index 0074c8e4..7bbcfbda 100644 --- a/gso/workflows/switch/create_switch.py +++ b/gso/workflows/switch/create_switch.py @@ -10,7 +10,7 @@ from orchestrator.workflow import StepList, begin, done, inputstep, step, workfl from orchestrator.workflows.steps import resync, set_status, store_process_subscription from orchestrator.workflows.utils import wrap_create_initial_input_form from pydantic import ConfigDict, model_validator -from pydantic_forms.validators import Label, ReadOnlyField +from pydantic_forms.validators import Choice, Label, ReadOnlyField from gso.products.product_blocks.switch import SwitchModel from gso.products.product_types.site import Site @@ -40,7 +40,7 @@ def _initial_input_form_generator(product_name: str) -> FormGenerator: hostname: str ts_port: PortNumber vendor: ReadOnlyField(Vendor.JUNIPER, default_type=Vendor) # type: ignore[valid-type] - model: ReadOnlyField(SwitchModel.EX3400, default_type=SwitchModel) # type: ignore[valid-type] + model: SwitchModel = Choice("Switch model", SwitchModel.values()) @model_validator(mode="after") def hostname_must_be_available(self) -> Self: -- GitLab