diff --git a/gso/cli/netbox.py b/gso/cli/netbox.py index bfd2318c42a82ddf61b7c02ebe0c7c7f82627a38..97ee7bc16fedd17f976853faeb88dbd9bb3406f8 100644 --- a/gso/cli/netbox.py +++ b/gso/cli/netbox.py @@ -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}") diff --git a/gso/services/netbox_client.py b/gso/services/netbox_client.py index 5de76f908e6f74c76ff84705916085c350d41934..45b0906b2ad28c212b995de483810c51052b02b5 100644 --- a/gso/services/netbox_client.py +++ b/gso/services/netbox_client.py @@ -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( diff --git a/gso/utils/device_info.py b/gso/utils/device_info.py index 219e4950a204062b012499e98400c31239e0c296..5a139889229efd80918e45079c805f18461e9dbb 100644 --- a/gso/utils/device_info.py +++ b/gso/utils/device_info.py @@ -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"}