From 9e47b8df482524ea9fc1d8e0c788a3138023920c Mon Sep 17 00:00:00 2001
From: Neda Moeini <neda.moeini@GA0479-NMOEINI.local>
Date: Wed, 11 Oct 2023 10:17:07 +0200
Subject: [PATCH] parameterized default site and device role data.

---
 gso/cli/netbox.py             | 5 +++--
 gso/services/netbox_client.py | 6 +++---
 gso/utils/device_info.py      | 4 ++++
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/gso/cli/netbox.py b/gso/cli/netbox.py
index bfd2318c..97ee7bc1 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 5de76f90..45b0906b 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 219e4950..5a139889 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"}
-- 
GitLab