By Samuel Mutel
Hello,
This library was created by digitalocean but does seems to be maintain today …
For the moment I would like an example of Go code to create a new tenant in Netbox with this library: https://github.com/digitalocean/go-netbox.
Thanks.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
To create a new tenant in Netbox using the go-netbox library, you can follow the example below:
package main
import (
"context"
"fmt"
"log"
"github.com/digitalocean/go-netbox/netbox"
"github.com/digitalocean/go-netbox/netbox/client/tenancy"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
func main() {
client := netbox.NewNetboxWithAPIKey("http://netbox.example.com/api/", "YOUR_API_KEY")
createTenant(client)
}
func createTenant(client *netbox.Netbox) {
tenantParams := &tenancy.TenancyTenantsCreateParams{
Data: &tenancy.TenancyTenantsCreateBody{
Name: swag.String("New tenant"),
Description: swag.String("Tenant description"),
Slug: swag.String("new-tenant"),
Created: strfmt.DateTime{},
LastUpdated: strfmt.DateTime{},
},
Context: context.TODO(),
}
result, err := client.Tenancy.TenancyTenantsCreate(tenantParams, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("New tenant created: %s\n", *result.Payload.Name)
}
Have in mind that this is an example and the code might need a better implementation in order to serve the purpose of your application.
Make sure to replace http://netbox.example.com/api/ with your Netbox API URL and YOUR_API_KEY with your actual API key.
You can find more information on using the go-netbox library in the official GitHub repository. For DigitalOcean API, refer to the official documentation.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.