Helpers
Helper methods that are used across GSO.
available_interfaces_choices(router_id, speed)
Return a list of available interfaces for a given router and speed.
For Nokia routers, return a list of available interfaces. For Juniper routers, return a string.
Source code in gso/utils/helpers.py
available_interfaces_choices_including_current_members(router_id, speed, interfaces)
Return a list of available interfaces for a given router and speed including the current members.
For Nokia routers, return a list of available interfaces. For Juniper routers, return a string.
Source code in gso/utils/helpers.py
available_lags_choices(router_id)
Return a list of available lags for a given router.
For Nokia routers, return a list of available lags.
For Juniper routers, return None
.
Source code in gso/utils/helpers.py
available_service_lags_choices(router_id)
Return a list of available lags for a given router for services.
For Nokia routers, return a list of available lags.
For Juniper routers, return None
.
Source code in gso/utils/helpers.py
get_router_vendor(router_id)
Retrieve the vendor of a router.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
router_id
|
UUID
|
The UUID of the router. |
required |
Returns:
Type | Description |
---|---|
Vendor
|
The vendor of the router. |
iso_from_ipv4(ipv4_address)
Calculate an ISO address, based on an IPv4 address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ipv4_address
|
IPv4AddressType
|
The address that's to be converted |
required |
Returns:
Type | Description |
---|---|
str
|
An ISO-formatted address. |
Source code in gso/utils/helpers.py
generate_fqdn(hostname, site_name, country_code)
Generate an FQDN from a hostname, site name, and a country code.
Source code in gso/utils/helpers.py
generate_lan_switch_interconnect_subnet_v4(site_internal_id)
Generate an IPv4 network in which a LAN Switch Interconnect resides, given a Site internal ID.
Source code in gso/utils/helpers.py
generate_lan_switch_interconnect_subnet_v6(site_internal_id)
Generate an IPv6 network in which a LAN Switch Interconnect resides, given a Site internal ID.
Source code in gso/utils/helpers.py
generate_inventory_for_routers(router_role, exclude_routers=None, router_vendor=None, *, include_provisioning_routers=True)
Generate an Ansible-compatible inventory for executing playbooks.
Contains all active routers of a specific role. Optionally, routers can be excluded from the inventory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
router_role
|
RouterRole
|
The role of the routers to include in the inventory. |
required |
exclude_routers
|
list[str] | None
|
List of routers to exclude from the inventory. |
None
|
router_vendor
|
Vendor | None
|
The vendor of the routers to include in the inventory. |
None
|
include_provisioning_routers
|
bool
|
Include routers that are in a |
True
|
Returns:
Type | Description |
---|---|
dict
|
A dictionary representing the inventory of active routers. |
Source code in gso/utils/helpers.py
calculate_recommended_minimum_links(iptrunk_number_of_members, iptrunk_speed)
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iptrunk_number_of_members
|
int
|
The number of members in the IP trunk. |
required |
iptrunk_speed
|
PhysicalPortCapacity
|
The speed of the IP trunk. |
required |
Returns:
Type | Description |
---|---|
int
|
The recommended minimum number of links for the IP trunk. |
Source code in gso/utils/helpers.py
active_site_selector()
Generate a dropdown selector for choosing an active site in an input form.
Source code in gso/utils/helpers.py
active_router_selector()
Generate a dropdown selector for choosing an active Router in an input form.
Source code in gso/utils/helpers.py
active_pe_router_selector(excludes=None)
Generate a dropdown selector for choosing an active PE Router in an input form.
Source code in gso/utils/helpers.py
active_switch_selector()
Generate a dropdown selector for choosing an active Switch in an input form.
Source code in gso/utils/helpers.py
active_edge_port_selector(*, partner_id=None)
Generate a dropdown selector for choosing an active Edge Port in an input form.
Source code in gso/utils/helpers.py
partner_choice()
Return a Choice object containing a list of available partners.
Source code in gso/utils/helpers.py
validate_edge_port_number_of_members_based_on_lacp(*, number_of_members, enable_lacp)
Validate the number of edge port members based on the LACP setting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
number_of_members
|
int
|
The number of members to validate. |
required |
enable_lacp
|
bool
|
Whether LACP is enabled or not. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the number of members is greater than 1 and LACP is disabled. |
Source code in gso/utils/helpers.py
generate_unique_vc_id(max_attempts=100)
Generate a unique 8-digit VC_ID starting with '11'.
This function attempts to generate an 8-digit VC_ID beginning with '11', checking its uniqueness before returning it. A maximum attempt limit is set to prevent infinite loops in case the ID space is saturated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_attempts
|
int
|
The maximum number of attempts to generate a unique ID. |
100
|
Returns:
Type | Description |
---|---|
VC_ID | None
|
A unique VC_ID instance if successful, None if no unique ID is found. |