Skip to content
Snippets Groups Projects
Commit 9e47b8df authored by Neda Moeini's avatar Neda Moeini
Browse files

parameterized default site and device role data.

parent 1905b3bc
Branches
Tags
1 merge request!82IP-TRUNK-CREATE-WORKFLOW-NETBOX-INTEGRATION
Pipeline #84220 passed
......@@ -2,6 +2,7 @@ import typer
from pynetbox import RequestError
from gso.services.netbox_client import NetboxClient
from gso.utils.device_info import DEFAULT_SITE, ROUTER_ROLE
app: typer.Typer = typer.Typer()
......@@ -21,14 +22,14 @@ def netbox_initial_setup() -> None:
typer.echo("Creating GÉANT site ...")
try:
nbclient.create_device_site("GEANT", "geant")
nbclient.create_device_site(DEFAULT_SITE["name"], DEFAULT_SITE["slug"])
typer.echo("Site created successfully.")
except RequestError as e:
typer.echo(f"Error creating site: {e}")
typer.echo("Creating Router device role ...")
try:
nbclient.create_device_role("router", "router")
nbclient.create_device_role(ROUTER_ROLE["name"], ROUTER_ROLE["slug"])
typer.echo("Device role created successfully.")
except RequestError as e:
typer.echo(f"Error creating device role: {e}")
......
......@@ -7,7 +7,7 @@ from pynetbox.models.dcim import Devices, DeviceTypes, Interfaces
from gso.products import Router
from gso.settings import load_oss_params
from gso.utils.device_info import FEASIBLE_IP_TRUNK_LAG_RANGE, TierInfo
from gso.utils.device_info import DEFAULT_SITE, FEASIBLE_IP_TRUNK_LAG_RANGE, ROUTER_ROLE, TierInfo
from gso.utils.exceptions import NotFoundError, WorkflowStateError
......@@ -123,10 +123,10 @@ class NetboxClient:
device_type = self.netbox.dcim.device_types.get(model=tier_info.device_type)
# Get device role id
device_role = self.netbox.dcim.device_roles.get(name="router")
device_role = self.netbox.dcim.device_roles.get(name=ROUTER_ROLE["name"])
# Get site id
device_site = self.netbox.dcim.sites.get(name="GEANT")
device_site = self.netbox.dcim.sites.get(name=DEFAULT_SITE["name"])
# Create new device
device = self.netbox.dcim.devices.create(
......
......@@ -32,3 +32,7 @@ class TierInfo:
# The range includes values from 1 to 10 (11 is not included)
FEASIBLE_IP_TRUNK_LAG_RANGE = range(1, 11)
# Define default values
ROUTER_ROLE = {"name": "router", "slug": "router"}
DEFAULT_SITE = {"name": "GEANT", "slug": "geant"}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment