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

add conditionals to the IP trunk creation workflow

parent 51ffc223
Branches
Tags
1 merge request!128Feature/use conditionals
...@@ -8,7 +8,7 @@ from orchestrator.forms.validators import Choice, UniqueConstrainedList ...@@ -8,7 +8,7 @@ from orchestrator.forms.validators import Choice, UniqueConstrainedList
from orchestrator.targets import Target from orchestrator.targets import Target
from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr
from orchestrator.utils.json import json_dumps from orchestrator.utils.json import json_dumps
from orchestrator.workflow import StepList, done, init, step, workflow from orchestrator.workflow import StepList, conditional, done, init, step, workflow
from orchestrator.workflows.steps import resync, set_status, store_process_subscription from orchestrator.workflows.steps import resync, set_status, store_process_subscription
from orchestrator.workflows.utils import wrap_create_initial_input_form from orchestrator.workflows.utils import wrap_create_initial_input_form
from pydantic import validator from pydantic import validator
...@@ -16,6 +16,7 @@ from pynetbox.models.dcim import Interfaces ...@@ -16,6 +16,7 @@ from pynetbox.models.dcim import Interfaces
from gso.products.product_blocks.iptrunk import ( from gso.products.product_blocks.iptrunk import (
IptrunkInterfaceBlockInactive, IptrunkInterfaceBlockInactive,
IptrunkSideBlockProvisioning,
IptrunkType, IptrunkType,
PhyPortCapacity, PhyPortCapacity,
) )
...@@ -39,11 +40,7 @@ from gso.utils.helpers import ( ...@@ -39,11 +40,7 @@ from gso.utils.helpers import (
def initial_input_form_generator(product_name: str) -> FormGenerator: def initial_input_form_generator(product_name: str) -> FormGenerator:
"""Gather input from the user in three steps. General information, and information on both sides of the trunk.""" """Gather input from the user in three steps. General information, and information on both sides of the trunk."""
# TODO: implement more strict validation:
# * interface names must be validated
routers = {} routers = {}
for router in subscriptions.get_active_router_subscriptions(includes=["subscription_id", "description"]): for router in subscriptions.get_active_router_subscriptions(includes=["subscription_id", "description"]):
routers[str(router["subscription_id"])] = router["description"] routers[str(router["subscription_id"])] = router["description"]
...@@ -428,19 +425,24 @@ def reserve_interfaces_in_netbox(subscription: IptrunkProvisioning) -> State: ...@@ -428,19 +425,24 @@ def reserve_interfaces_in_netbox(subscription: IptrunkProvisioning) -> State:
} }
@step("Allocate interfaces in Netbox") def _allocate_interfaces_in_netbox(iptrunk_side: IptrunkSideBlockProvisioning) -> None:
def allocate_interfaces_in_netbox(subscription: IptrunkProvisioning) -> State: for interface in iptrunk_side.iptrunk_side_ae_members:
"""Allocate the :term:`LAG` interfaces in NetBox and attach the lag interfaces to the physical interfaces.""" NetboxClient().allocate_interface(
for trunk_side in subscription.iptrunk.iptrunk_sides: device_name=iptrunk_side.iptrunk_side_node.router_fqdn,
if get_router_vendor(trunk_side.iptrunk_side_node.owner_subscription_id) == RouterVendor.NOKIA: iface_name=interface.interface_name,
for interface in trunk_side.iptrunk_side_ae_members: )
NetboxClient().allocate_interface(
device_name=trunk_side.iptrunk_side_node.router_fqdn,
iface_name=interface.interface_name, @step("Allocate interfaces in Netbox for side A")
) def netbox_allocate_side_a_interfaces(subscription: IptrunkProvisioning) -> None:
return { """Allocate the :term:`LAG` interfaces for the Nokia router on side A."""
"subscription": subscription, _allocate_interfaces_in_netbox(subscription.iptrunk.iptrunk_sides[0])
}
@step("Allocate interfaces in Netbox for side B")
def netbox_allocate_side_b_interfaces(subscription: IptrunkProvisioning) -> None:
"""Allocate the :term:`LAG` interfaces for the Nokia router on side B."""
_allocate_interfaces_in_netbox(subscription.iptrunk.iptrunk_sides[1])
@workflow( @workflow(
...@@ -461,6 +463,9 @@ def create_iptrunk() -> StepList: ...@@ -461,6 +463,9 @@ def create_iptrunk() -> StepList:
* Allocate the interfaces in Netbox * Allocate the interfaces in Netbox
* Set the subscription to active in the database * Set the subscription to active in the database
""" """
side_a_is_nokia = conditional(lambda state: get_router_vendor(state["side_a_node_id"]) == RouterVendor.NOKIA)
side_b_is_nokia = conditional(lambda state: get_router_vendor(state["side_b_node_id"]) == RouterVendor.NOKIA)
return ( return (
init init
>> create_subscription >> create_subscription
...@@ -474,7 +479,8 @@ def create_iptrunk() -> StepList: ...@@ -474,7 +479,8 @@ def create_iptrunk() -> StepList:
>> pp_interaction(provision_ip_trunk_isis_iface_dry) >> pp_interaction(provision_ip_trunk_isis_iface_dry)
>> pp_interaction(provision_ip_trunk_isis_iface_real) >> pp_interaction(provision_ip_trunk_isis_iface_real)
>> pp_interaction(check_ip_trunk_isis) >> pp_interaction(check_ip_trunk_isis)
>> allocate_interfaces_in_netbox >> side_a_is_nokia(netbox_allocate_side_a_interfaces)
>> side_b_is_nokia(netbox_allocate_side_b_interfaces)
>> set_status(SubscriptionLifecycle.ACTIVE) >> set_status(SubscriptionLifecycle.ACTIVE)
>> resync >> resync
>> done >> done
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment