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

Refactor Edge Port name to avoid conflict

parent d6085245
Branches
Tags 2.11
No related merge requests found
Pipeline #89710 failed
......@@ -72,7 +72,7 @@ INSERT INTO resource_types (resource_type, description) VALUES ('has_custom_poli
INSERT INTO resource_types (resource_type, description) VALUES ('families', 'IP families, can be v4 v6 and UNICAST or MULTICAST') RETURNING resource_types.resource_type_id
"""))
conn.execute(sa.text("""
INSERT INTO resource_types (resource_type, description) VALUES ('name', 'Name') RETURNING resource_types.resource_type_id
INSERT INTO resource_types (resource_type, description) VALUES ('edge_port_name', 'Edge Port interface name') RETURNING resource_types.resource_type_id
"""))
conn.execute(sa.text("""
INSERT INTO resource_types (resource_type, description) VALUES ('edge_port_type', 'Type of Edge Port') RETURNING resource_types.resource_type_id
......@@ -171,7 +171,7 @@ INSERT INTO product_block_relations (in_use_by_id, depends_on_id) VALUES ((SELEC
INSERT INTO product_block_relations (in_use_by_id, depends_on_id) VALUES ((SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('ServiceBindingPort')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('EdgePortBlock')))
"""))
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 ('EdgePortBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('name')))
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 ('EdgePortBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('edge_port_name')))
"""))
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 ('EdgePortBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('edge_port_description')))
......@@ -277,10 +277,10 @@ INSERT INTO product_block_resource_types (product_block_id, resource_type_id) VA
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 ('EdgePortBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('name'))
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 ('EdgePortBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('edge_port_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 ('EdgePortBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('name'))
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 ('EdgePortBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('edge_port_name'))
"""))
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 ('EdgePortBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('edge_port_description'))
......@@ -481,10 +481,10 @@ DELETE FROM product_block_resource_types WHERE product_block_resource_types.prod
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 ('rtbh_enabled'))
"""))
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 ('ignore_if_down', 'multipath_enabled', 'geant_ga_id', 'has_custom_policies', 'families', 'name', 'edge_port_type', 'custom_firewall_filters', 'peer_address', 'ipv6_address', 'edge_port_description', 'authentication_key', 'bfd_multiplier', 'is_tagged', 'rtbh_enabled', 'mac_address', 'bfd_interval', 'is_multi_hop', 'member_speed', 'ipv4_mask', 'geant_sid', 'encapsulation', 'ipv4_address', 'ipv6_mask', 'bfd_enabled', 'ap_type', 'send_default_route', 'is_passive', 'sbp_type', 'enable_lacp'))
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 ('ignore_if_down', 'multipath_enabled', 'geant_ga_id', 'has_custom_policies', 'families', 'edge_port_name', 'edge_port_type', 'custom_firewall_filters', 'peer_address', 'ipv6_address', 'edge_port_description', 'authentication_key', 'bfd_multiplier', 'is_tagged', 'rtbh_enabled', 'mac_address', 'bfd_interval', 'is_multi_hop', 'member_speed', 'ipv4_mask', 'geant_sid', 'encapsulation', 'ipv4_address', 'ipv6_mask', 'bfd_enabled', 'ap_type', 'send_default_route', 'is_passive', 'sbp_type', 'enable_lacp'))
"""))
conn.execute(sa.text("""
DELETE FROM resource_types WHERE resource_types.resource_type IN ('ignore_if_down', 'multipath_enabled', 'geant_ga_id', 'has_custom_policies', 'families', 'name', 'edge_port_type', 'custom_firewall_filters', 'peer_address', 'ipv6_address', 'edge_port_description', 'authentication_key', 'bfd_multiplier', 'is_tagged', 'rtbh_enabled', 'mac_address', 'bfd_interval', 'is_multi_hop', 'member_speed', 'ipv4_mask', 'geant_sid', 'encapsulation', 'ipv4_address', 'ipv6_mask', 'bfd_enabled', 'ap_type', 'send_default_route', 'is_passive', 'sbp_type', 'enable_lacp')
DELETE FROM resource_types WHERE resource_types.resource_type IN ('ignore_if_down', 'multipath_enabled', 'geant_ga_id', 'has_custom_policies', 'families', 'edge_port_name', 'edge_port_type', 'custom_firewall_filters', 'peer_address', 'ipv6_address', 'edge_port_description', 'authentication_key', 'bfd_multiplier', 'is_tagged', 'rtbh_enabled', 'mac_address', 'bfd_interval', 'is_multi_hop', 'member_speed', 'ipv4_mask', 'geant_sid', 'encapsulation', 'ipv4_address', 'ipv6_mask', 'bfd_enabled', 'ap_type', 'send_default_route', 'is_passive', 'sbp_type', 'enable_lacp')
"""))
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 ('Imported Edge Port', 'Edge Port')) AND product_product_blocks.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('EdgePortBlock'))
......
......@@ -63,7 +63,7 @@ class EdgePortBlockInactive(
"""An edge port that's currently inactive. See :class:`EdgePortBlock`."""
node: RouterBlockInactive | None = None
name: str | None = None
edge_port_name: str | None = None
edge_port_description: str | None = None
enable_lacp: bool | None = None
encapsulation: EncapsulationType = EncapsulationType.DOT1Q
......@@ -80,7 +80,7 @@ class EdgePortBlockProvisioning(EdgePortBlockInactive, lifecycle=[SubscriptionLi
"""An edge port that's being provisioned. See :class:`EdgePortBlock`."""
node: RouterBlockProvisioning
name: str
edge_port_name: str
edge_port_description: str | None = None
enable_lacp: bool
encapsulation: EncapsulationType = EncapsulationType.DOT1Q
......@@ -99,7 +99,7 @@ class EdgePortBlock(EdgePortBlockProvisioning, lifecycle=[SubscriptionLifecycle.
#: The router that this edge port is connected to.
node: RouterBlock
#: The name of the edge port, in our case, corresponds to the name of the :term:`LAG` interface.
name: str
edge_port_name: str
#: A description of the edge port.
edge_port_description: str | None = None
#: Indicates whether :term:`LACP` is enabled for this edge port.
......
......@@ -104,7 +104,7 @@ def initialize_subscription(
service_type: EdgePortType,
speed: PhysicalPortCapacity,
encapsulation: EncapsulationType,
name: str,
edge_port_name: str,
minimum_links: int,
geant_ga_id: str | None,
mac_address: str | None,
......@@ -121,13 +121,14 @@ def initialize_subscription(
subscription.edge_port.edge_port_enable_lacp = enable_lacp
subscription.edge_port.edge_port_member_speed = speed
subscription.edge_port.edge_port_encapsulation = encapsulation
subscription.edge_port.edge_port_name = name
subscription.edge_port.edge_port_name = edge_port_name
subscription.edge_port.edge_port_minimum_links = minimum_links
subscription.edge_port.edge_port_ignore_if_down = ignore_if_down
subscription.edge_port.edge_port_geant_ga_id = geant_ga_id
subscription.edge_port.edge_port_mac_address = mac_address
partner_name = get_partner_by_id(partner).name
subscription.description = f"Edge Port {name} on {router.router_fqdn}, {partner_name}, {geant_ga_id or ""}"
subscription.description = (f"Edge Port {edge_port_name} on {router.router_fqdn}, "
f"{partner_name}, {geant_ga_id or ""}")
subscription.edge_port.edge_port_description = description
for member in ae_members:
subscription.edge_port.edge_port_ae_members.append(
......@@ -147,7 +148,7 @@ def reserve_interfaces_in_netbox(subscription: EdgePortProvisioning) -> State:
lag_interface: Interfaces = nbclient.create_interface(
iface_name=edge_port.edge_port_name,
interface_type="lag",
device_name=edge_port.edge_port_node.router_fqdn,
device_name=edge_port.node.router_fqdn,
description=str(subscription.subscription_id),
enabled=True,
)
......@@ -156,13 +157,13 @@ def reserve_interfaces_in_netbox(subscription: EdgePortProvisioning) -> State:
# Reserve interfaces
for interface in edge_port.edge_port_ae_members:
nbclient.attach_interface_to_lag(
device_name=edge_port.edge_port_node.router_fqdn,
device_name=edge_port.node.router_fqdn,
lag_name=lag_interface.name,
iface_name=interface.interface_name,
description=str(subscription.subscription_id),
)
nbclient.reserve_interface(
device_name=edge_port.edge_port_node.router_fqdn,
device_name=edge_port.node.router_fqdn,
iface_name=interface.interface_name,
)
return {
......@@ -174,7 +175,7 @@ def reserve_interfaces_in_netbox(subscription: EdgePortProvisioning) -> State:
def allocate_interfaces_in_netbox(subscription: EdgePortProvisioning) -> None:
"""Allocate the interfaces in NetBox."""
for interface in subscription.edge_port.edge_port_ae_members:
fqdn = subscription.edge_port.edge_port_node.router_fqdn
fqdn = subscription.edge_port.node.router_fqdn
iface_name = interface.interface_name
if not fqdn or not iface_name:
msg = "FQDN and/or interface name missing in subscription"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment