Skip to content
Snippets Groups Projects
Select Git revision
  • 1266d3fdc0b632d5b5db5213ef00cd992cc8f68c
  • develop default protected
  • validate_l2_circuit
  • master protected
  • feature/NAT-1797-netbox-migration
  • authorship-fix-from-develop
  • 1048-service-config-backfilling
  • feature/nat-1211-edgeport-lacp-xmit
  • fix/nat-1120-sdp-validation
  • NAT-1154-import-edge-port-update
  • fix/l3-imports
  • feature/10GGBS-NAT-980
  • fix/NAT-1009/fix-redeploy-base-config-if-there-is-a-vprn
  • 4.27
  • 4.26
  • 4.25
  • 4.24
  • 4.23
  • 4.22
  • 4.21
  • 4.20
  • 4.19
  • 4.18
  • 4.17
  • 4.16
  • 4.15
  • 4.14
  • 4.13
  • 4.12
  • 4.11
  • 4.10
  • 4.8
  • 4.5
33 results

netbox.py

Blame
  • Karel van Klink's avatar
    Karel van Klink authored
    These are not needed anymore, as MkDocs will pick up on them automatically
    1266d3fd
    History
    netbox.py 1.13 KiB
    """A CLI for interacting with Netbox."""
    
    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()
    
    
    @app.command()
    def netbox_initial_setup() -> None:
        """Set up NetBox for the first time.
    
        It includes:
        - Creating a default site (GEANT)
        - Creating device roles (Router)
        """
        typer.echo("Initial setup of NetBox ...")
        typer.echo("Connecting to NetBox ...")
    
        nbclient = NetboxClient()
    
        typer.echo("Creating GEANT site ...")
        try:
            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_ROLE["name"], ROUTER_ROLE["slug"])
            typer.echo("Device role created successfully.")
        except RequestError as e:
            typer.echo(f"Error creating device role: {e}")
    
        typer.echo("NetBox initial setup completed successfully.")