Skip to content
Snippets Groups Projects
Verified Commit d9d770dc authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

First attempt at refactoring device to router

parent 96a041ef
No related branches found
No related tags found
1 merge request!59Feature/refactor device to router
Showing
with 746 additions and 910 deletions
"""add Device workflows.
Revision ID: 857225661207
Revises: f4959f32c866
Create Date: 2023-04-05 09:16:03.725750
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '857225661207'
down_revision = 'd52256e7d715'
branch_labels = None
depends_on = None
from orchestrator.migrations.helpers import create_workflow, delete_workflow
new_workflows = [
{
"name": "create_device",
"target": "CREATE",
"description": "Create Device",
"product_type": "Device"
}
]
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"])
"""add Iptrunk create workflow.
Revision ID: 60d340427471
Revises: 80b0a70d4faf
Create Date: 2023-04-29 06:25:49.525661
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '60d340427471'
down_revision = '80b0a70d4faf'
branch_labels = None
depends_on = None
from orchestrator.migrations.helpers import create_workflow, delete_workflow
new_workflows = [
{
"name": "create_iptrunk",
"target": "CREATE",
"description": "Create Iptrunk",
"product_type": "Iptrunk"
}
]
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"])
"""Add site model.
Revision ID: 4d850df522f2
Revises:
Create Date: 2023-05-04 08:27:31.942548
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '4d850df522f2'
down_revision = None
branch_labels = ('data',)
depends_on = 'e05bb1967eff'
def upgrade() -> None:
conn = op.get_bind()
conn.execute("""
INSERT INTO products (name, description, product_type, tag, status) VALUES ('Site', 'A Geant POP', 'Site', 'SITE', 'active') RETURNING products.product_id
""")
conn.execute("""
INSERT INTO product_blocks (name, description, tag, status) VALUES ('SiteBlock', 'A Geant POP', 'SITE', 'active') RETURNING product_blocks.product_block_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_internal_id', 'Site internal ID') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_country', 'Site country') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_longitude', 'Site Longitude') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_country_code', 'Site country code') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_tier', 'Site Tier') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_city', 'Site city') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_latitude', 'Site latitude') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_name', 'Site name') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_bgp_community_id', 'Site BGP community ID') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO product_product_blocks (product_id, product_block_id) VALUES ((SELECT products.product_id FROM products WHERE products.name IN ('Site')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('SiteBlock')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_name')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_city')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country_code')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_latitude')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_longitude')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_internal_id')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_bgp_community_id')))
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_tier')))
""")
def downgrade() -> None:
conn = op.get_bind()
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_name'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_name'))
""")
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_city'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_city'))
""")
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country'))
""")
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country_code'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country_code'))
""")
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_latitude'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_latitude'))
""")
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_longitude'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_longitude'))
""")
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_internal_id'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_internal_id'))
""")
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_bgp_community_id'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_bgp_community_id'))
""")
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_tier'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_tier'))
""")
conn.execute("""
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 ('site_internal_id', 'site_country', 'site_longitude', 'site_country_code', 'site_tier', 'site_city', 'site_latitude', 'site_name', 'site_bgp_community_id'))
""")
conn.execute("""
DELETE FROM resource_types WHERE resource_types.resource_type IN ('site_internal_id', 'site_country', 'site_longitude', 'site_country_code', 'site_tier', 'site_city', 'site_latitude', 'site_name', 'site_bgp_community_id')
""")
conn.execute("""
DELETE FROM product_product_blocks WHERE product_product_blocks.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('Site')) AND product_product_blocks.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('SiteBlock'))
""")
conn.execute("""
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 ('SiteBlock'))
""")
conn.execute("""
DELETE FROM product_blocks WHERE product_blocks.name IN ('SiteBlock')
""")
conn.execute("""
DELETE FROM processes WHERE processes.pid IN (SELECT processes_subscriptions.pid FROM processes_subscriptions WHERE processes_subscriptions.subscription_id IN (SELECT subscriptions.subscription_id FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('Site'))))
""")
conn.execute("""
DELETE FROM processes_subscriptions WHERE processes_subscriptions.subscription_id IN (SELECT subscriptions.subscription_id FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('Site')))
""")
conn.execute("""
DELETE FROM subscription_instances WHERE subscription_instances.subscription_id IN (SELECT subscriptions.subscription_id FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('Site')))
""")
conn.execute("""
DELETE FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('Site'))
""")
conn.execute("""
DELETE FROM products WHERE products.name IN ('Site')
""")
This diff is collapsed.
"""add Terminate device workflow.
Revision ID: 61f8e90581c5
Revises: 21e7bb0e5cad
Create Date: 2023-05-08 10:48:21.655880
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '61f8e90581c5'
down_revision = '21e7bb0e5cad'
branch_labels = None
depends_on = None
from orchestrator.migrations.helpers import create_workflow, delete_workflow
new_workflows = [
{
"name": "terminate_device",
"target": "TERMINATE",
"description": "Terminate device",
"product_type": "Device"
}
]
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"])
"""Add device access_via_ts attr.
Revision ID: 84d0ad6e7294
Revises: c7def54cc165
Create Date: 2023-06-18 12:03:23.365781
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '84d0ad6e7294'
down_revision = 'c7def54cc165'
branch_labels = None
depends_on = None
def upgrade() -> None:
conn = op.get_bind()
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('device_access_via_ts', 'Access to the device via terminal server') RETURNING resource_types.resource_type_id
""")
conn.execute("""
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 ('DeviceBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('device_access_via_ts')))
""")
conn.execute("""
WITH subscription_instance_ids AS (
SELECT subscription_instances.subscription_instance_id
FROM subscription_instances
WHERE subscription_instances.product_block_id IN (
SELECT product_blocks.product_block_id
FROM product_blocks
WHERE product_blocks.name = 'DeviceBlock'
)
)
INSERT INTO
subscription_instance_values (subscription_instance_id, resource_type_id, value)
SELECT
subscription_instance_ids.subscription_instance_id,
resource_types.resource_type_id,
'false'
FROM resource_types
CROSS JOIN subscription_instance_ids
WHERE resource_types.resource_type = 'device_access_via_ts'
""")
def downgrade() -> None:
conn = op.get_bind()
conn.execute("""
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 ('DeviceBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('device_access_via_ts'))
""")
conn.execute("""
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 ('DeviceBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('device_access_via_ts'))
""")
conn.execute("""
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 ('device_access_via_ts'))
""")
conn.execute("""
DELETE FROM resource_types WHERE resource_types.resource_type IN ('device_access_via_ts')
""")
"""Add Iptrunk ISIS attr.
Revision ID: c7def54cc165
Revises: 647e066bc99e
Create Date: 2023-06-18 06:56:21.189733
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = 'c7def54cc165'
down_revision = '647e066bc99e'
branch_labels = None
depends_on = None
def upgrade() -> None:
conn = op.get_bind()
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_isis_metric', 'ISIS metric for a Trunk') RETURNING resource_types.resource_type_id
""")
conn.execute("""
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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_isis_metric')))
""")
def downgrade() -> None:
conn = op.get_bind()
conn.execute("""
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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_isis_metric'))
""")
conn.execute("""
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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_isis_metric'))
""")
conn.execute("""
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 ('iptrunk_isis_metric'))
""")
conn.execute("""
DELETE FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_isis_metric')
""")
"""add Iptrunk modify workflow.
Revision ID: e57ebfade80b
Revises: 7694b98571f8
Create Date: 2023-06-26 12:20:16.828055
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = 'e57ebfade80b'
down_revision = '7694b98571f8'
branch_labels = None
depends_on = None
from orchestrator.migrations.helpers import create_workflow, delete_workflow
new_workflows = [
{
"name": "modify_generic",
"target": "MODIFY",
"description": "Modify IP trunk",
"product_type": "Iptrunk"
}
]
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"])
"""Modify sites and device PB.
Revision ID: 7728b3ef410c
Revises: e57ebfade80b
Create Date: 2023-08-07 12:53:31.090424
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '7728b3ef410c'
down_revision = 'e57ebfade80b'
branch_labels = None
depends_on = None
def upgrade() -> None:
conn = op.get_bind()
conn.execute("""
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 ('DeviceBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('device_ts_address'))
""")
conn.execute("""
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 ('DeviceBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('device_ts_address'))
""")
conn.execute("""
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 ('device_ts_address'))
""")
conn.execute("""
DELETE FROM resource_types WHERE resource_types.resource_type IN ('device_ts_address')
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('device_is_ias_connected', 'device has lt to IAS') RETURNING resource_types.resource_type_id
""")
conn.execute("""
INSERT INTO resource_types (resource_type, description) VALUES ('site_ts_address', 'Address of the terminal server') RETURNING resource_types.resource_type_id
""")
conn.execute("""
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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_ts_address')))
""")
conn.execute("""
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 ('DeviceBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('device_is_ias_connected')))
""")
conn.execute("""
WITH subscription_instance_ids AS (
SELECT subscription_instances.subscription_instance_id
FROM subscription_instances
WHERE subscription_instances.product_block_id IN (
SELECT product_blocks.product_block_id
FROM product_blocks
WHERE product_blocks.name = 'SiteBlock'
)
)
INSERT INTO
subscription_instance_values (subscription_instance_id, resource_type_id, value)
SELECT
subscription_instance_ids.subscription_instance_id,
resource_types.resource_type_id,
'Address of the terminal server'
FROM resource_types
CROSS JOIN subscription_instance_ids
WHERE resource_types.resource_type = 'site_ts_address'
""")
conn.execute("""
WITH subscription_instance_ids AS (
SELECT subscription_instances.subscription_instance_id
FROM subscription_instances
WHERE subscription_instances.product_block_id IN (
SELECT product_blocks.product_block_id
FROM product_blocks
WHERE product_blocks.name = 'DeviceBlock'
)
)
INSERT INTO
subscription_instance_values (subscription_instance_id, resource_type_id, value)
SELECT
subscription_instance_ids.subscription_instance_id,
resource_types.resource_type_id,
'true'
FROM resource_types
CROSS JOIN subscription_instance_ids
WHERE resource_types.resource_type = 'device_is_ias_connected'
""")
def downgrade() -> None:
conn = op.get_bind()
conn.execute("""
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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_ts_address'))
""")
conn.execute("""
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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_ts_address'))
""")
conn.execute("""
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 ('DeviceBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('device_is_ias_connected'))
""")
conn.execute("""
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 ('DeviceBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('device_is_ias_connected'))
""")
conn.execute("""
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 ('device_is_ias_connected', 'site_ts_address'))
""")
conn.execute("""
DELETE FROM resource_types WHERE resource_types.resource_type IN ('device_is_ias_connected', 'site_ts_address')
""")
"""add Terminate Iptrunk workflow.
"""Add Router workflows.
Revision ID: 647e066bc99e
Revises: 61f8e90581c5
Create Date: 2023-05-08 18:59:01.309425
Revision ID: 3657611f0dfc
Revises: 91047dd30b40
Create Date: 2023-08-14 15:44:25.616608
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '647e066bc99e'
down_revision = '61f8e90581c5'
revision = '3657611f0dfc'
down_revision = '91047dd30b40'
branch_labels = None
depends_on = None
......@@ -19,10 +19,16 @@ from orchestrator.migrations.helpers import create_workflow, delete_workflow
new_workflows = [
{
"name": "terminate_iptrunk",
"name": "create_router",
"target": "CREATE",
"description": "Create router",
"product_type": "Router"
},
{
"name": "terminate_router",
"target": "TERMINATE",
"description": "Terminate IPtrunk",
"product_type": "Iptrunk"
"description": "Terminate router",
"product_type": "Router"
}
]
......
"""add Site create workflow.
"""Add Site workflows.
Revision ID: 21e7bb0e5cad
Revises: 60d340427471
Create Date: 2023-05-04 09:00:36.433715
Revision ID: 91047dd30b40
Revises: 97436160a422
Create Date: 2023-08-14 15:42:35.450032
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '21e7bb0e5cad'
down_revision = '60d340427471'
revision = '91047dd30b40'
down_revision = '97436160a422'
branch_labels = None
depends_on = None
......
"""add Iptrunk ISIS modify workflow.
"""Add IP Trunk workflows.
Revision ID: 7694b98571f8
Revises: 84d0ad6e7294
Create Date: 2023-06-21 08:36:42.824952
Revision ID: a6eefd32c4f7
Revises: 3657611f0dfc
Create Date: 2023-08-14 15:50:03.376997
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '7694b98571f8'
down_revision = '84d0ad6e7294'
revision = 'a6eefd32c4f7'
down_revision = '3657611f0dfc'
branch_labels = None
depends_on = None
......@@ -18,6 +18,24 @@ depends_on = None
from orchestrator.migrations.helpers import create_workflow, delete_workflow
new_workflows = [
{
"name": "create_iptrunk",
"target": "CREATE",
"description": "Create IP trunk",
"product_type": "Iptrunk"
},
{
"name": "terminate_iptrunk",
"target": "TERMINATE",
"description": "Terminate IPtrunk",
"product_type": "Iptrunk"
},
{
"name": "modify_trunk_interface",
"target": "MODIFY",
"description": "Modify IP Trunk interface",
"product_type": "Iptrunk"
},
{
"name": "modify_isis_metric",
"target": "MODIFY",
......
"""Module that updates the domain model of {term}`GSO`. Should contain all types of subscriptions."""
from orchestrator.domain import SUBSCRIPTION_MODEL_REGISTRY
from gso.products.product_types.device import Device
from gso.products.product_types.router import Router
from gso.products.product_types.iptrunk import Iptrunk
from gso.products.product_types.site import Site
SUBSCRIPTION_MODEL_REGISTRY.update(
{
"Site": Site,
"Router": Device,
"Switch": Device,
"Iptrunk": Iptrunk,
"Router": Router,
"IP trunk": Iptrunk,
}
)
"""Product block for {class}`Device` products."""
import ipaddress
from typing import Optional
from orchestrator.domain.base import ProductBlockModel
from orchestrator.types import SubscriptionLifecycle, strEnum
from gso.products.product_blocks.site import SiteBlock, SiteBlockInactive, SiteBlockProvisioning
class DeviceVendor(strEnum):
"""Enumerator for the different product vendors that are supported."""
JUNIPER = "juniper"
"""Juniper devices."""
NOKIA = "nokia"
"""Nokia devices."""
class DeviceRole(strEnum):
"""Enumerator for the different types of routers."""
P = "p"
"""P router."""
PE = "pe"
"""PE router."""
AMT = "amt"
"""AMT router."""
class DeviceBlockInactive(
ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="DeviceBlock"
):
"""A device that's being currently inactive. See {class}`DeviceBlock`."""
device_fqdn: Optional[str] = None
device_ts_port: Optional[int] = None
device_access_via_ts: Optional[bool] = None
device_lo_ipv4_address: Optional[ipaddress.IPv4Address] = None
device_lo_ipv6_address: Optional[ipaddress.IPv6Address] = None
device_lo_iso_address: Optional[str] = None
device_si_ipv4_network: Optional[ipaddress.IPv4Network] = None
device_ias_lt_ipv4_network: Optional[ipaddress.IPv4Network] = None
device_ias_lt_ipv6_network: Optional[ipaddress.IPv6Network] = None
device_vendor: Optional[DeviceVendor] = None
device_role: Optional[DeviceRole] = None
device_site: Optional[SiteBlockInactive]
device_is_ias_connected: Optional[bool] = None
class DeviceBlockProvisioning(DeviceBlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]):
"""A device that's being provisioned. See {class}`DeviceBlock`."""
device_fqdn: str
device_ts_port: int
device_access_via_ts: Optional[bool] = None
device_lo_ipv4_address: Optional[ipaddress.IPv4Address] = None
device_lo_ipv6_address: Optional[ipaddress.IPv6Address] = None
device_lo_iso_address: Optional[str] = None
device_si_ipv4_network: Optional[ipaddress.IPv4Network] = None
device_ias_lt_ipv4_network: Optional[ipaddress.IPv4Network] = None
device_ias_lt_ipv6_network: Optional[ipaddress.IPv6Network] = None
device_vendor: Optional[DeviceVendor] = None
device_role: Optional[DeviceRole] = None
device_site: Optional[SiteBlockProvisioning]
device_is_ias_connected: Optional[bool] = None
class DeviceBlock(DeviceBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]):
"""A device that's currently deployed in the network."""
device_fqdn: str
"""{term}`FQDN` of a device."""
device_ts_port: int
"""The port of the terminal server that this device is connected to. Used for the same reason as mentioned
previously."""
device_access_via_ts: bool
"""Whether this device should be accessed through the terminal server, or through its loopback address."""
device_lo_ipv4_address: ipaddress.IPv4Address
"""The IPv4 loopback address of the device."""
device_lo_ipv6_address: ipaddress.IPv6Address
"""The IPv6 loopback address of the device."""
device_lo_iso_address: str
"""The {term}`ISO` {term}`NET` of the device, used for {term}`IS-IS` support."""
device_si_ipv4_network: Optional[ipaddress.IPv4Network]
"""The SI IPv4 network of the device."""
device_ias_lt_ipv4_network: Optional[ipaddress.IPv4Network]
"""The IAS LT IPv4 network of the device."""
device_ias_lt_ipv6_network: Optional[ipaddress.IPv6Network]
"""The IAS LT IPv6 network of the device."""
device_vendor: DeviceVendor
"""The vendor of the device, can be any of the values defined in {class}`DeviceVendor`."""
device_role: DeviceRole
"""The role of the device, which can be any of the values defined in {class}`DeviceRole`."""
device_site: SiteBlock
"""The {class}`Site` that this device resides in. Both physically and computationally."""
device_is_ias_connected: bool
"""The device is going to have a LT interface between inet0 and IAS"""
......@@ -7,7 +7,7 @@ from orchestrator.domain.base import ProductBlockModel
from orchestrator.types import SubscriptionLifecycle, strEnum
from pydantic import Field
from gso.products.product_blocks.device import DeviceBlock, DeviceBlockInactive, DeviceBlockProvisioning
from gso.products.product_blocks.router import RouterBlock, RouterBlockInactive, RouterBlockProvisioning
class IptrunkType(strEnum):
......@@ -29,13 +29,13 @@ class IptrunkBlockInactive(
iptrunk_ipv4_network: Optional[ipaddress.IPv4Network] = None
iptrunk_ipv6_network: Optional[ipaddress.IPv6Network] = None
#
iptrunk_sideA_node: DeviceBlockInactive
iptrunk_sideA_node: RouterBlockInactive
iptrunk_sideA_ae_iface: Optional[str] = None
iptrunk_sideA_ae_geant_a_sid: Optional[str] = None
iptrunk_sideA_ae_members: list[str] = Field(default_factory=list)
iptrunk_sideA_ae_members_description: list[str] = Field(default_factory=list)
#
iptrunk_sideB_node: DeviceBlockInactive
iptrunk_sideB_node: RouterBlockInactive
iptrunk_sideB_ae_iface: Optional[str] = None
iptrunk_sideB_ae_geant_a_sid: Optional[str] = None
iptrunk_sideB_ae_members: list[str] = Field(default_factory=list)
......@@ -54,13 +54,13 @@ class IptrunkBlockProvisioning(IptrunkBlockInactive, lifecycle=[SubscriptionLife
iptrunk_ipv4_network: Optional[ipaddress.IPv4Network] = None
iptrunk_ipv6_network: Optional[ipaddress.IPv6Network] = None
#
iptrunk_sideA_node: DeviceBlockProvisioning
iptrunk_sideA_node: RouterBlockProvisioning
iptrunk_sideA_ae_iface: Optional[str] = None
iptrunk_sideA_ae_geant_a_sid: Optional[str] = None
iptrunk_sideA_ae_members: list[str] = Field(default_factory=list)
iptrunk_sideA_ae_members_description: list[str] = Field(default_factory=list)
#
iptrunk_sideB_node: DeviceBlockProvisioning
iptrunk_sideB_node: RouterBlockProvisioning
iptrunk_sideB_ae_iface: Optional[str] = None
iptrunk_sideB_ae_geant_a_sid: Optional[str] = None
iptrunk_sideB_ae_members: list[str] = Field(default_factory=list)
......@@ -87,7 +87,7 @@ class IptrunkBlock(IptrunkBlockProvisioning, lifecycle=[SubscriptionLifecycle.AC
iptrunk_ipv6_network: ipaddress.IPv6Network
"""The IPv6 network used for this trunk."""
#
iptrunk_sideA_node: DeviceBlock
iptrunk_sideA_node: RouterBlock
"""The router that hosts the A side of the trunk."""
iptrunk_sideA_ae_iface: str
"""The name of the interface on which the trunk connects."""
......@@ -98,7 +98,7 @@ class IptrunkBlock(IptrunkBlockProvisioning, lifecycle=[SubscriptionLifecycle.AC
iptrunk_sideA_ae_members_description: list[str] = Field(default_factory=list)
"""The list of descriptions that describe the list of interface members."""
#
iptrunk_sideB_node: DeviceBlock
iptrunk_sideB_node: RouterBlock
"""The router that hosts the B side of the trunk. It possesses the same attributes as the A-side, including the
interfaces and its descriptions."""
iptrunk_sideB_ae_iface: str
......
"""Product block for {class}`Router` products."""
import ipaddress
from typing import Optional
from orchestrator.domain.base import ProductBlockModel
from orchestrator.types import SubscriptionLifecycle, strEnum
from gso.products.product_blocks.site import SiteBlock, SiteBlockInactive, SiteBlockProvisioning
class RouterVendor(strEnum):
"""Enumerator for the different product vendors that are supported."""
JUNIPER = "juniper"
"""Juniper routers."""
NOKIA = "nokia"
"""Nokia routers."""
class RouterRole(strEnum):
"""Enumerator for the different types of routers."""
P = "p"
"""P router."""
PE = "pe"
"""PE router."""
AMT = "amt"
"""AMT router."""
class RouterBlockInactive(
ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="RouterBlock"
):
"""A router that's being currently inactive. See {class}`RouterBlock`."""
router_fqdn: Optional[str] = None
router_ts_port: Optional[int] = None
router_access_via_ts: Optional[bool] = None
router_lo_ipv4_address: Optional[ipaddress.IPv4Address] = None
router_lo_ipv6_address: Optional[ipaddress.IPv6Address] = None
router_lo_iso_address: Optional[str] = None
router_si_ipv4_network: Optional[ipaddress.IPv4Network] = None
router_ias_lt_ipv4_network: Optional[ipaddress.IPv4Network] = None
router_ias_lt_ipv6_network: Optional[ipaddress.IPv6Network] = None
router_vendor: Optional[RouterVendor] = None
router_role: Optional[RouterRole] = None
router_site: Optional[SiteBlockInactive]
router_is_ias_connected: Optional[bool] = None
class RouterBlockProvisioning(RouterBlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]):
"""A router that's being provisioned. See {class}`RouterBlock`."""
router_fqdn: str
router_ts_port: int
router_access_via_ts: Optional[bool] = None
router_lo_ipv4_address: Optional[ipaddress.IPv4Address] = None
router_lo_ipv6_address: Optional[ipaddress.IPv6Address] = None
router_lo_iso_address: Optional[str] = None
router_si_ipv4_network: Optional[ipaddress.IPv4Network] = None
router_ias_lt_ipv4_network: Optional[ipaddress.IPv4Network] = None
router_ias_lt_ipv6_network: Optional[ipaddress.IPv6Network] = None
router_vendor: Optional[RouterVendor] = None
router_role: Optional[RouterRole] = None
router_site: Optional[SiteBlockProvisioning]
router_is_ias_connected: Optional[bool] = None
class RouterBlock(RouterBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]):
"""A router that's currently deployed in the network."""
router_fqdn: str
"""{term}`FQDN` of a router."""
router_ts_port: int
"""The port of the terminal server that this router is connected to. Used for the same reason as mentioned
previously."""
router_access_via_ts: bool
"""Whether this router should be accessed through the terminal server, or through its loopback address."""
router_lo_ipv4_address: ipaddress.IPv4Address
"""The IPv4 loopback address of the router."""
router_lo_ipv6_address: ipaddress.IPv6Address
"""The IPv6 loopback address of the router."""
router_lo_iso_address: str
"""The {term}`ISO` {term}`NET` of the router, used for {term}`IS-IS` support."""
router_si_ipv4_network: Optional[ipaddress.IPv4Network]
"""The SI IPv4 network of the router."""
router_ias_lt_ipv4_network: Optional[ipaddress.IPv4Network]
"""The IAS LT IPv4 network of the router."""
router_ias_lt_ipv6_network: Optional[ipaddress.IPv6Network]
"""The IAS LT IPv6 network of the router."""
router_vendor: RouterVendor
"""The vendor of the router, can be any of the values defined in {class}`RouterVendor`."""
router_role: RouterRole
"""The role of the router, which can be any of the values defined in {class}`RouterRole`."""
router_site: SiteBlock
"""The {class}`Site` that this router resides in. Both physically and computationally."""
router_is_ias_connected: bool
"""The router is going to have a LT interface between inet0 and IAS"""
......@@ -50,11 +50,11 @@ class SiteBlockProvisioning(SiteBlockInactive, lifecycle=[SubscriptionLifecycle.
class SiteBlock(SiteBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]):
"""A site that's currently available for devices and services to be hosted at."""
"""A site that's currently available for routers and services to be hosted at."""
site_name: str
"""The name of the site, that will dictate part of the {term}`FQDN` of devices that are hosted at this site. For
example: `device.X.Y.geant.net`, where X denotes the name of the site."""
"""The name of the site, that will dictate part of the {term}`FQDN` of routers that are hosted at this site. For
example: `router.X.Y.geant.net`, where X denotes the name of the site."""
site_city: str
"""The city at which the site is located."""
site_country: str
......@@ -73,6 +73,6 @@ class SiteBlock(SiteBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE])
site_tier: SiteTier
"""The tier of a site, as described in {class}`SiteTier`."""
site_ts_address: Optional[str] = None
"""The address of the terminal server that this device is connected to. The terminal server provides out of band
access. This is required in case a link goes down, or when a device is initially added to the network and it does
"""The address of the terminal server that this router is connected to. The terminal server provides out of band
access. This is required in case a link goes down, or when a router is initially added to the network and it does
not have any IP trunks connected to it yet."""
"""Product types define the different products that are available.
Multiple product blocks may insist on a single product type. In that sense, a product type is a mode general description
of a product. For example, the product type {class}`Device` must either be a router or a switch, both being separate
of a product. For example, the product type {class}`Router` must either be a router or a switch, both being separate
product blocks.
"""
from orchestrator.domain.base import SubscriptionModel
from orchestrator.types import SubscriptionLifecycle, strEnum
from gso.products.product_blocks.device import DeviceBlock, DeviceBlockInactive, DeviceBlockProvisioning
class DeviceType(strEnum):
"""Enumerator for different device types.
A device can either be a router or a switch.
"""
router = "router"
switch = "switch"
class DeviceInactive(SubscriptionModel, is_base=True):
device_type: DeviceType
device: DeviceBlockInactive
class DeviceProvisioning(DeviceInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]):
device_type: DeviceType
device: DeviceBlockProvisioning
class Device(DeviceProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]):
device_type: DeviceType
device: DeviceBlock
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment