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

use conditionals in IP trunk migration workflow

parent 02d70cb8
No related branches found
No related tags found
1 merge request!128Feature/use conditionals
...@@ -164,7 +164,6 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: ...@@ -164,7 +164,6 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
| new_side_iptrunk_router_input.dict() | new_side_iptrunk_router_input.dict()
| new_side_input.dict() | new_side_input.dict()
| {"replace_index": replace_index} | {"replace_index": replace_index}
| {"new_side_is_nokia": new_side_is_nokia}
) )
...@@ -526,8 +525,8 @@ def update_subscription_model( ...@@ -526,8 +525,8 @@ def update_subscription_model(
return {"subscription": subscription, "old_side_data": old_side_data} return {"subscription": subscription, "old_side_data": old_side_data}
@step("Reserve interfaces in Netbox") @step("Netbox: Reserve new interfaces")
def reserve_interfaces_in_netbox( def netbox_reserve_interfaces(
subscription: Iptrunk, subscription: Iptrunk,
new_node: UUIDstr, new_node: UUIDstr,
new_lag_interface: str, new_lag_interface: str,
...@@ -560,34 +559,37 @@ def reserve_interfaces_in_netbox( ...@@ -560,34 +559,37 @@ def reserve_interfaces_in_netbox(
return {"subscription": subscription} return {"subscription": subscription}
@step("Update Netbox. Allocate new interfaces and deallocate old ones.") @step("Netbox: Remove old LAG interface")
def update_netbox( def netbox_remove_old_interfaces(old_side_data: dict) -> State:
subscription: Iptrunk, """Remove the old :term:`LAG` interface from Netbox, only relevant if the old side is a Nokia router."""
replace_index: int,
old_side_data: dict,
) -> State:
"""Update Netbox, reallocating the old and new interfaces."""
new_side = subscription.iptrunk.iptrunk_sides[replace_index]
nbclient = NetboxClient() nbclient = NetboxClient()
if get_router_vendor(new_side.iptrunk_side_node.owner_subscription_id) == RouterVendor.NOKIA:
for interface in new_side.iptrunk_side_ae_members:
nbclient.allocate_interface(
device_name=new_side.iptrunk_side_node.router_fqdn,
iface_name=interface.interface_name,
)
if get_router_vendor(old_side_data["iptrunk_side_node"]["owner_subscription_id"]) == RouterVendor.NOKIA:
# Set interfaces to free
for iface in old_side_data["iptrunk_side_ae_members"]:
nbclient.free_interface(
old_side_data["iptrunk_side_node"]["router_fqdn"],
iface["interface_name"],
)
# Delete :term:`LAG` interfaces for iface in old_side_data["iptrunk_side_ae_members"]:
nbclient.delete_interface( nbclient.free_interface(
old_side_data["iptrunk_side_node"]["router_fqdn"], old_side_data["iptrunk_side_node"]["router_fqdn"],
old_side_data["iptrunk_side_ae_iface"], iface["interface_name"],
)
nbclient.delete_interface(
old_side_data["iptrunk_side_node"]["router_fqdn"],
old_side_data["iptrunk_side_ae_iface"],
)
return {}
@step("Netbox: Allocate new LAG member interfaces")
def netbox_allocate_new_interfaces(subscription: Iptrunk, replace_index: int) -> State:
"""Allocate the new :term:`LAG` interface in Netbox. Only relevant if the new router is a Nokia."""
nbclient = NetboxClient()
new_side = subscription.iptrunk.iptrunk_sides[replace_index]
for interface in new_side.iptrunk_side_ae_members:
nbclient.allocate_interface(
device_name=new_side.iptrunk_side_node.router_fqdn,
iface_name=interface.interface_name,
) )
return {"subscription": subscription} return {"subscription": subscription}
...@@ -614,14 +616,18 @@ def migrate_iptrunk() -> StepList: ...@@ -614,14 +616,18 @@ def migrate_iptrunk() -> StepList:
TODO: add interface checks TODO: add interface checks
""" """
new_side_is_nokia = conditional(lambda state: state["new_side_is_nokia"]) new_side_is_nokia = conditional(lambda state: get_router_vendor(state["new_node"]) == RouterVendor.NOKIA)
old_side_is_nokia = conditional(
lambda state: get_router_vendor(state["old_side_data"]["iptrunk_side_node"]["owner_subscription_id"])
== RouterVendor.NOKIA
)
should_restore_isis_metric = conditional(lambda state: state["restore_isis_metric"]) should_restore_isis_metric = conditional(lambda state: state["restore_isis_metric"])
return ( return (
init init
>> store_process_subscription(Target.MODIFY) >> store_process_subscription(Target.MODIFY)
>> unsync >> unsync
>> new_side_is_nokia(reserve_interfaces_in_netbox) >> new_side_is_nokia(netbox_reserve_interfaces)
>> pp_interaction(set_isis_to_90000) >> pp_interaction(set_isis_to_90000)
>> pp_interaction(disable_old_config_dry) >> pp_interaction(disable_old_config_dry)
>> pp_interaction(disable_old_config_real) >> pp_interaction(disable_old_config_real)
...@@ -635,7 +641,8 @@ def migrate_iptrunk() -> StepList: ...@@ -635,7 +641,8 @@ def migrate_iptrunk() -> StepList:
>> pp_interaction(delete_old_config_real) >> pp_interaction(delete_old_config_real)
>> update_ipam >> update_ipam
>> update_subscription_model >> update_subscription_model
>> update_netbox >> old_side_is_nokia(netbox_remove_old_interfaces)
>> new_side_is_nokia(netbox_allocate_new_interfaces)
>> resync >> resync
>> done >> done
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment