go-nautobot
nautobot
package provides the Go Bindings to interact with Nautobot Source of Truth API, starting from Nautobot version 1.5.8. It comes with its own versioning schema, derived from Nautobot (see #release-versioning).
This package bindings are auto-generated. Every release it's triggered automatically from the Nautobot release pipeline, for every new version released. It uses oapi-codegen
package, using the swagger.yaml
generated by Nautobot service implementing OpenAPI 3.0.
Nautobot allows query parameter api_version
to specify the major-minor version to generate the schema from.
Release Versioning
go-nautobot
uses semantic versioning with a dependency on the Nautobot major-minor version used to generate the bindings.
The minor version in go-nautobot
will always match the minor version from Nautobot, but the patch version will evolve independently.
For example, a fictitious release process would be:
Nautobot |
go-nautobot |
5.1.0 |
5.1.0 |
5.1.1 |
5.1.1 |
5.1.1* |
5.1.2 (some local fix) |
5.1.2 |
5.1.3 |
the "*" case shows that when regenerating the bindings for the same Nautobot version, a increment on the patch release of go-nautobot
occurs.
This way the project versioning will keep relationship with the original minor Nautobot version while it also enables its own release lifecycle.
How to use nautobot
package
Go Get Nautobot package
Simply point your get of the nautobot
package to the version you require, in the example version 1.5.0
:
$ go get github.com/nautobot/go-nautobot/pkg/nautobot@v1.5.0
Go main example
This is example is also available in example/main.go
:
package main
import (
"context"
"fmt"
nb "github.com/nautobot/go-nautobot/pkg/nautobot"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
token, err := nb.NewSecurityProviderNautobotToken("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
check(err)
c, err := nb.NewClientWithResponses(
"https://demo.nautobot.com/api/",
nb.WithRequestEditorFn(token.Intercept),
)
check(err)
ctx := context.Background()
resp, err := c.DcimManufacturersListWithResponse(ctx, &nb.DcimManufacturersListParams{})
check(err)
fmt.Printf("%v", string(resp.Body))
}
Other examples
How to use while being a private repository
export GOPRIVATE=github.com/nautobot/go-nautobot
vi ~/.gitconfig
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
Local Development
Run it locally
docker-compose --project-name go_nautobot -f development/docker-compose.yml --env-file development/local_dev.env up --build --abort-on-container-exit
Hint: If you get a build fail during testing, check that you are not limiting container memory to 2GB. Upgrade to 4GB.
Trigger the build manually
The release process can be triggered manually from GitHub Actions CLI:
gh workflow run release.yml -f tag=1.3.2
TODO
- [] Notify in slack for every release or failure
- [] Add a step in Nautobot, at the end of OSRB