diff --git a/gso/migrations/versions/2025-01-13_db6e86c6d4e1_add_custom_service_name_to_edgeport_.py b/gso/migrations/versions/2025-01-13_db6e86c6d4e1_add_custom_service_name_to_edgeport_.py new file mode 100644 index 0000000000000000000000000000000000000000..e8019940d221ca42d6712f290936a1e3b8a6c4d7 --- /dev/null +++ b/gso/migrations/versions/2025-01-13_db6e86c6d4e1_add_custom_service_name_to_edgeport_.py @@ -0,0 +1,41 @@ +"""Add custom service name to EdgePort, L2Circuit and L3CoreService.. + +Revision ID: db6e86c6d4e1 +Revises: 8a65d0ed588e +Create Date: 2025-01-13 11:13:05.149307 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'db6e86c6d4e1' +down_revision = '8a65d0ed588e' +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 ('custom_service_name', 'Custom Service Name mainly used by IMS') 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 ('AccessPort')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('custom_service_name'))), ((SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('Layer2CircuitBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('custom_service_name'))), ((SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('EdgePortBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('custom_service_name'))) + """)) + + +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 ('AccessPort', 'Layer2CircuitBlock', 'EdgePortBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('custom_service_name')) + """)) + 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 ('AccessPort', 'Layer2CircuitBlock', 'EdgePortBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('custom_service_name')) + """)) + 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 ('custom_service_name')) + """)) + conn.execute(sa.text(""" +DELETE FROM resource_types WHERE resource_types.resource_type IN ('custom_service_name') + """)) diff --git a/gso/products/product_blocks/edge_port.py b/gso/products/product_blocks/edge_port.py index d7249d34bbfa6410834a28b0770ce6b1e3c6a08d..e09372341ba01456b7ce744365e57826bd873ea5 100644 --- a/gso/products/product_blocks/edge_port.py +++ b/gso/products/product_blocks/edge_port.py @@ -72,6 +72,7 @@ class EdgePortBlockInactive( ignore_if_down: bool = False ga_id: str | None = None edge_port_ae_members: LAGMemberList[EdgePortAEMemberBlockInactive] + custom_service_name: str | None = None class EdgePortBlockProvisioning(EdgePortBlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): @@ -89,6 +90,7 @@ class EdgePortBlockProvisioning(EdgePortBlockInactive, lifecycle=[SubscriptionLi ignore_if_down: bool = False ga_id: str | None = None edge_port_ae_members: LAGMemberList[EdgePortAEMemberBlockProvisioning] # type: ignore[assignment] + custom_service_name: str | None = None class EdgePortBlock(EdgePortBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): @@ -107,6 +109,7 @@ class EdgePortBlock(EdgePortBlockProvisioning, lifecycle=[SubscriptionLifecycle. ignore_if_down: If set to True, the edge port will be ignored if it is down. ga_id: The GEANT GA ID associated with this edge port, if any. edge_port_ae_members: A list of LAG members associated with this edge port. + custom_service_name: The name of the custom service, if any. """ node: RouterBlock @@ -121,3 +124,4 @@ class EdgePortBlock(EdgePortBlockProvisioning, lifecycle=[SubscriptionLifecycle. ignore_if_down: bool = False ga_id: str | None = None edge_port_ae_members: LAGMemberList[EdgePortAEMemberBlock] # type: ignore[assignment] + custom_service_name: str | None = None diff --git a/gso/products/product_blocks/l3_core_service.py b/gso/products/product_blocks/l3_core_service.py index ce2db1782410311e8d37f34d4b92cd27abed8d01..2c3149db7b75babb58baa91358d8ddaa84d9ad2d 100644 --- a/gso/products/product_blocks/l3_core_service.py +++ b/gso/products/product_blocks/l3_core_service.py @@ -17,6 +17,7 @@ class AccessPortInactive(ProductBlockModel, lifecycle=[SubscriptionLifecycle.INI ap_type: APType | None = None sbp: ServiceBindingPortInactive + custom_service_name: str | None = None class AccessPortProvisioning(AccessPortInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): @@ -24,6 +25,7 @@ class AccessPortProvisioning(AccessPortInactive, lifecycle=[SubscriptionLifecycl ap_type: APType sbp: ServiceBindingPortProvisioning + custom_service_name: str | None = None class AccessPort(AccessPortProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): @@ -32,10 +34,12 @@ class AccessPort(AccessPortProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE Attributes: ap_type: The type of Access Port sbp: The corresponding SBP of this Access Port. + custom_service_name: The name of the custom service, if any. """ ap_type: APType sbp: ServiceBindingPort + custom_service_name: str | None = None class L3CoreServiceBlockInactive( diff --git a/gso/products/product_blocks/layer_2_circuit.py b/gso/products/product_blocks/layer_2_circuit.py index 2e1a7c53b7a995efedc6c09377ef19f4d2ee158b..50bf89ceb4a2ce1f780efcdc520dbd89ae5ce73f 100644 --- a/gso/products/product_blocks/layer_2_circuit.py +++ b/gso/products/product_blocks/layer_2_circuit.py @@ -79,6 +79,7 @@ class Layer2CircuitBlockInactive( policer_enabled: bool | None = None policer_burst_rate: BandwidthString | None = None bandwidth: BandwidthString | None = None + custom_service_name: str | None = None class Layer2CircuitBlockProvisioning(Layer2CircuitBlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): @@ -92,6 +93,7 @@ class Layer2CircuitBlockProvisioning(Layer2CircuitBlockInactive, lifecycle=[Subs policer_enabled: bool policer_burst_rate: BandwidthString | None bandwidth: BandwidthString | None + custom_service_name: str | None = None class Layer2CircuitBlock(Layer2CircuitBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): @@ -106,6 +108,7 @@ class Layer2CircuitBlock(Layer2CircuitBlockProvisioning, lifecycle=[Subscription policer_enabled: Whether this Layer 2 Circuit is policed. policer_burst_rate: If policed, the burst rate of the policer. bandwidth: If policed, the bandwidth of the policer is stored. + custom_service_name: The name of the service which is used in IMS. """ layer_2_circuit_sides: Layer2CircuitSides[Layer2CircuitSideBlock] @@ -116,3 +119,5 @@ class Layer2CircuitBlock(Layer2CircuitBlockProvisioning, lifecycle=[Subscription policer_enabled: bool policer_burst_rate: BandwidthString | None bandwidth: BandwidthString | None + custom_service_name: str | None = None +