• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    Shell
  • License
    Other
  • Created over 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The official Go API client for Netbox IPAM and DCIM service.

go-netbox

GoDoc Build Status Report Card

go-netbox is —to nobody's surprise— the official Go API client for Netbox IPAM and DCIM service.

This project follows Semantic Versioning. The version of the library built for a Netbox version has the same tag, followed by a hyphen and the build number (an incremental integer), as several versions of the library may exist for the same version of Netbox.

Installation

Use go get to add the library as a project's dependency. Do not forget to run go mod init first if necessary.

go get github.com/netbox-community/go-netbox/v3

# Or install a specific version
go get github.com/netbox-community/go-netbox/[email protected]

Note: dependencies should be managed with Go modules.

Usage

Instantiate the client

The package has some convenience functions for creating clients with the most common configurations.

package main

import (
	"log"

	"github.com/netbox-community/go-netbox/v3/netbox"
)

func main() {
	c := netbox.NewNetboxAt("netbox.example.org:8000")
    
	// or:
	// c := netbox.NewNetboxWithAPIKey("netbox.example.org:8000", "<api-token>")

	log.Printf("%+v", c)
}

In order to consume the Netbox API with HTTP over TLS, a transport must be created.

package main

import (
	"fmt"
	"log"

	transport "github.com/go-openapi/runtime/client"
	"github.com/netbox-community/go-netbox/v3/netbox/client"
)

func main() {
	t := transport.New("netbox.example.org", client.DefaultBasePath, []string{"https"})

	t.DefaultAuthentication = transport.APIKeyAuth(
		"Authorization",
		"header",
		fmt.Sprintf("Token %v", "<api-token>"),
	)

	c := client.New(t, nil)

	log.Printf("%+v", c)
}

For more complex client configurations, see the documentation of github.com/go-openapi/runtime/client, the library which in turn is used by the client.

Note: setting the DEBUG environment variable will dump all requests to standard error output.

Use the client

With the client already instantiated, it is possible to consume any API feature.

For example, to list the first 100 active virtual machines:

package main

import (
	"log"

	"github.com/netbox-community/go-netbox/v3/netbox"
	"github.com/netbox-community/go-netbox/v3/netbox/client/virtualization"
)

var status = "active"
var pageLimit = int64(100)

func main() {
	c := netbox.NewNetboxWithAPIKey("netbox.example.org", "<api-token>")

	req := virtualization.
		NewVirtualizationVirtualMachinesListParams().
		WithStatus(&status).
		WithLimit(&pageLimit)

	// additional `authInfo` is `nil` because the API token has already been specified in the client 
	res, err := w.netbox.Virtualization.VirtualizationVirtualMachinesList(req, nil)

	if err != nil {
		log.Fatal(err)
	}

	log.Printf("%+v", res.Payload.Results)
}

See reference for more information on all possible usages.

Development

The project comes with a containerized development environment that can be used from any platform. It is only required to have Git and Docker Desktop (or, separately, Docker and Docker Compose) installed on the machine.

To start the development environment, run the following command.

make

Then, to attach a shell in the container, run the command below.

make shell

Finally, to stop the development environment, run the following command.

make down

Considerations

The library is almost entirely generated from the Netbox OpenAPI specification using go-swagger. Therefore, files under directories netbox/client and netbox/models should not be directly modified, as they will be overwritten in the next regeneration (see next section).

To fix issues in generated code, there are two options:

Regenerate the library

To update the OpenAPI specification to the latest Netbox version and regenerate the library, run the following command.

make build

If regeneration of the library is needed for a specific Netbox version other than the latest one, pass the corresponding argument.

make build NETBOX_VERSION=3.0.0

In order to obtain the OpenAPI specification, the version of netbox-docker corresponding to the given Netbox version is used. However, it is also possible to provide a specific version of netbox-docker.

make build NETBOX_VERSION=3.0.0 NETBOX_DOCKER_VERSION=1.3.1

More Repositories

1

netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
Python
15,828
star
2

netbox-docker

🐳 Docker Image of NetBox
Python
1,800
star
3

devicetype-library

A collection of community-sourced DeviceType definitions for import to NetBox
Python
899
star
4

netbox-topology-views

A netbox plugin that draws topology views
Python
753
star
5

pynetbox

Python API client library for Netbox.
Python
563
star
6

ansible_modules

NetBox modules for Ansible using Ansible Collections
Python
327
star
7

Device-Type-Library-Import

This library is intended to assist with importing device and module types into NetBox from the NetBox Community DeviceType-Library
Python
262
star
8

netbox-chart

A Helm chart for NetBox
Mustache
247
star
9

netbox-bgp

NetBox plugin for BGP related objects documentation
Python
242
star
10

customizations

A collection of community submitted and maintained customizations including reports, scripts, validators and export templates
Python
205
star
11

netbox-qrcode

NetBox Plugin for generate QR Codes
Python
201
star
12

awesome-netbox

A curated list of awesome NetBox resources
186
star
13

netbox-zero-to-hero

A short course designed to take new NetBox users from ‘Zero to Hero’.
Python
149
star
14

netbox-plugin-tutorial

A tutorial on building custom plugins for NetBox v3.2+
89
star
15

netbox-acls

A NetBox plugin for Access Lists based off of the NetBox Plugin Demo
Python
86
star
16

netbox-napalm-plugin

NetBox Napalm plugin
JavaScript
49
star
17

netbox-reorder-rack

NetBox plugin to allow users to reorder devices within a rack using a drag and drop UI.
Python
45
star
18

netbox-python

Python NetBox API Client
Python
37
star
19

netbox-operator

[INCUBATING] A Kubernetes operator to manage NetBox resources directly through Kubernetes.
Go
33
star
20

cookiecutter-netbox-plugin

Cookiecutter template for easy building NetBox plugins
Python
22
star
21

netbox-healthcheck-plugin

HTML
20
star
22

netbox-demo-data

Demo data useful for populating demo instances of NetBox
19
star
23

migration-scripts

Python
10
star
24

netbox-plugin-demo

Python
7
star
25

netbox.dev-old

netbox.dev website
HTML
1
star
26

netbox-demo

A plugin for NetBox demo instances
Python
1
star