From 8bfc7658cb68137fdd72135e78713a852d95379f Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Wed, 25 Sep 2024 14:07:42 +0200 Subject: [PATCH] Update domain model for BGP session --- ...dd_passive_boolean_to_bgp_session_model.py | 41 +++++++++++++++++++ gso/products/product_blocks/bgp_session.py | 4 ++ 2 files changed, 45 insertions(+) create mode 100644 gso/migrations/versions/2024-09-25_c3e98d657b36_add_passive_boolean_to_bgp_session_model.py diff --git a/gso/migrations/versions/2024-09-25_c3e98d657b36_add_passive_boolean_to_bgp_session_model.py b/gso/migrations/versions/2024-09-25_c3e98d657b36_add_passive_boolean_to_bgp_session_model.py new file mode 100644 index 00000000..ef499051 --- /dev/null +++ b/gso/migrations/versions/2024-09-25_c3e98d657b36_add_passive_boolean_to_bgp_session_model.py @@ -0,0 +1,41 @@ +"""Add passive boolean to BGP session model. + +Revision ID: c3e98d657b36 +Revises: f900cbaa47d7 +Create Date: 2024-09-25 14:05:57.072597 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'c3e98d657b36' +down_revision = 'f900cbaa47d7' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + conn = op.get_bind() + conn.execute(sa.text(""" +INSERT INTO resource_types (resource_type, description) VALUES ('is_passive', 'This BGP session is passive') RETURNING resource_types.resource_type_id + """)) + conn.execute(sa.text(""" +INSERT INTO product_block_resource_types (product_block_id, resource_type_id) VALUES ((SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('BGPSession')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('is_passive'))) + """)) + + +def downgrade() -> None: + conn = op.get_bind() + conn.execute(sa.text(""" +DELETE FROM product_block_resource_types WHERE product_block_resource_types.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('BGPSession')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('is_passive')) + """)) + conn.execute(sa.text(""" +DELETE FROM subscription_instance_values USING product_block_resource_types WHERE subscription_instance_values.subscription_instance_id IN (SELECT subscription_instances.subscription_instance_id FROM subscription_instances WHERE subscription_instances.subscription_instance_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('BGPSession'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('is_passive')) + """)) + conn.execute(sa.text(""" +DELETE FROM subscription_instance_values WHERE subscription_instance_values.resource_type_id IN (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('is_passive')) + """)) + conn.execute(sa.text(""" +DELETE FROM resource_types WHERE resource_types.resource_type IN ('is_passive') + """)) diff --git a/gso/products/product_blocks/bgp_session.py b/gso/products/product_blocks/bgp_session.py index 5247c201..8da070c0 100644 --- a/gso/products/product_blocks/bgp_session.py +++ b/gso/products/product_blocks/bgp_session.py @@ -32,6 +32,7 @@ class BGPSessionInactive(ProductBlockModel, lifecycle=[SubscriptionLifecycle.INI multipath_enabled: bool | None = None send_default_route: bool | None = None is_multi_hop: bool = False + is_passive: bool = False class BGPSessionProvisioning(BGPSessionInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): @@ -47,6 +48,7 @@ class BGPSessionProvisioning(BGPSessionInactive, lifecycle=[SubscriptionLifecycl multipath_enabled: bool send_default_route: bool is_multi_hop: bool + is_passive: bool class BGPSession(BGPSessionProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): @@ -72,3 +74,5 @@ class BGPSession(BGPSessionProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE send_default_route: bool #: Whether this session is multi-hop or not. Defaults to no. is_multi_hop: bool + #: Whether this is a passive session. + is_passive: bool -- GitLab