diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py index fdf851e8495c697e95ad45747d07269f29e7a2db..cca681a4be8d56c0772aaae40f5929f516c3dbc5 100644 --- a/gso/utils/helpers.py +++ b/gso/utils/helpers.py @@ -12,7 +12,7 @@ from pydantic_core.core_schema import ValidationInfo from pydantic_forms.validators import Choice from gso import settings -from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock +from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock, PhysicalPortCapacity from gso.products.product_blocks.router import RouterRole from gso.products.product_blocks.site import LatitudeCoordinate, LongitudeCoordinate, SiteTier from gso.products.product_types.router import Router @@ -332,3 +332,18 @@ def generate_inventory_for_active_routers( } } } + + +def calculate_recommended_minimum_links(iptrunk_number_of_members: int, iptrunk_speed: PhysicalPortCapacity) -> int: + """Calculate the recommended minimum number of links for an IP trunk based on the number of members and speed. + + If the IP trunk speed is 400G, the recommended minimum number of links is the number of members minus 1. + Otherwise, the recommended minimum number of links is the number of members. + + :param int iptrunk_number_of_members: The number of members in the IP trunk. + :param PhysicalPortCapacity iptrunk_speed: The speed of the IP trunk. + :return: The recommended minimum number of links for the IP trunk. + """ + if iptrunk_speed == PhysicalPortCapacity.FOUR_HUNDRED_GIGABIT_PER_SECOND: + return iptrunk_number_of_members - 1 + return iptrunk_number_of_members diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py index 95703094cf67299b6b235e914de4959ff5426832..373dfc03b63e378b2889c62aca3496011121f909 100644 --- a/gso/workflows/iptrunk/create_iptrunk.py +++ b/gso/workflows/iptrunk/create_iptrunk.py @@ -35,6 +35,7 @@ from gso.utils.helpers import ( LAGMember, available_interfaces_choices, available_lags_choices, + calculate_recommended_minimum_links, get_router_vendor, validate_interface_name_list, validate_iptrunk_unique_interface, @@ -70,12 +71,13 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: return validate_tt_number(tt_number) initial_user_input = yield CreateIptrunkForm + recommended_minimum_links = calculate_recommended_minimum_links( + initial_user_input.iptrunk_number_of_members, initial_user_input.iptrunk_speed + ) class VerifyMinimumLinksForm(FormPage): - info_label: Label = ( - f"This is the calculated minimum-links for this LAG: " f"{initial_user_input.iptrunk_number_of_members - 1}" - ) - iptrunk_minimum_links: int = initial_user_input.iptrunk_number_of_members - 1 + info_label: Label = f"This is the calculated minimum-links for this LAG: {recommended_minimum_links}" + iptrunk_minimum_links: int = recommended_minimum_links info_label2: Label = "Please confirm or modify." verify_minimum_links = yield VerifyMinimumLinksForm diff --git a/gso/workflows/iptrunk/modify_trunk_interface.py b/gso/workflows/iptrunk/modify_trunk_interface.py index c938884cfe9b1c682a0eeeaa7e3fe1199e12ef33..f5d17d7752503d8fdb8979d0eefadd7818af4936 100644 --- a/gso/workflows/iptrunk/modify_trunk_interface.py +++ b/gso/workflows/iptrunk/modify_trunk_interface.py @@ -28,6 +28,7 @@ from gso.utils.helpers import ( LAGMember, available_interfaces_choices, available_interfaces_choices_including_current_members, + calculate_recommended_minimum_links, get_router_vendor, validate_interface_name_list, validate_iptrunk_unique_interface, @@ -108,12 +109,15 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: initial_user_input = yield ModifyIptrunkForm + recommended_minimum_links = calculate_recommended_minimum_links( + initial_user_input.iptrunk_number_of_members, initial_user_input.iptrunk_speed + ) + class VerifyMinimumLinksForm(FormPage): - info_label: Label = ( - f"This is the calculated minimum-links for this LAG: " f"{initial_user_input.iptrunk_number_of_members - 1}" - ) - iptrunk_minimum_links: int = initial_user_input.iptrunk_number_of_members - 1 - info_label2: Label = "Please confirm or modify." + info_label: Label = f"Current value of minimum-links : {subscription.iptrunk.iptrunk_minimum_links}" + info_label1: Label = f"Recommended minimum-links for this LAG: {recommended_minimum_links}" + iptrunk_minimum_links: int = recommended_minimum_links + info_label2: Label = "Please review the recommended value and adjust if necessary." verify_minimum_links = yield VerifyMinimumLinksForm ae_members_side_a = initialize_ae_members(subscription, initial_user_input.model_dump(), 0)