netbox

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UIDCustomFieldName is the name of the custom field in NetBox,
	// containing the UID of the resource that an IP is assigned to.
	UIDCustomFieldName = "netbox_ip_controller_uid"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	GetTag(ctx context.Context, tag string) (*Tag, error)
	CreateTag(ctx context.Context, tag string) (*Tag, error)
	GetIP(ctx context.Context, uid UID) (*IPAddress, error)
	UpsertIP(ctx context.Context, ip *IPAddress) (*IPAddress, error)
	DeleteIP(ctx context.Context, uid UID) error
	UpsertUIDField(ctx context.Context) error
}

Client is a netbox client.

func NewClient

func NewClient(apiURL, apiToken string, opts ...ClientOption) (Client, error)

NewClient sets up a new NetBox client with default authorization and retries.

func NewFakeClient

func NewFakeClient(tags map[string]Tag, ips map[UID]IPAddress) Client

NewFakeClient returns a fake NetBox client.

type ClientOption

type ClientOption func(*client) error

ClientOption is a function type to pass options to NewClient

func WithCARootCert

func WithCARootCert(path string) ClientOption

WithCARootCert is a functional option that adds the PEM-encoded root certificate found at the given path to the TLSClientConfig of the client's underlying HTTPClient.

func WithLogger

func WithLogger(logger *log.Logger) ClientOption

WithLogger sets the logger to be used by the client.

func WithRateLimiter

func WithRateLimiter(refillRate rate.Limit, bucketSize int) ClientOption

WithRateLimiter is a functional option that attaches a token bucket style rate limiter to the given client.

type CustomField

type CustomField struct {
	ID              int64  `json:"id,omitempty"`
	Name            string `json:"name,omitempty"`
	Label           string `json:"label,omitempty"`
	Description     string `json:"description,omitempty"`
	Required        bool   `json:"required,omitempty"`
	ValidationRegex string `json:"validation_regex,omitempty"`
	// Type is the type of the field.
	// Possible values: text, longtext, integer, boolean, date, url, json, select, multiselect
	Type LabeledString `json:"type"`
	// ContentTypes is the list of modelt to which the custom field is added.
	// Should be in format "domain.object", e.g. "ipam.ipaddress".
	ContentTypes []string `json:"content_types"`
	// FilterLogic can be one of: disabled, loose, exact. Specified how the field
	// will be matched when persorming a query.
	FilterLogic LabeledString `json:"filter_logic,omitempty"`
	// Weight is for display purposes: fields with higher weights appear lower in a form.
	Weight int64 `json:"weight,omitempty"`
}

CustomField is a NetBox custom field attached to some model(s).

type CustomFieldList

type CustomFieldList struct {
	Count   uint          `json:"count"`
	Results []CustomField `json:"results"`
}

CustomFieldList represents the response from the NetBox endpoints that return multiple custom fields.

type IP

type IP netip.Addr

IP is the type for representing address from NetBox. Its purpose is to provide custom marshaling and unmarshaling.

func (IP) MarshalText

func (ip IP) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for IP.

func (*IP) UnmarshalJSON

func (ip *IP) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for IP.

type IPAddress

type IPAddress struct {
	ID int64 `json:"id,omitempty"`
	// UID is the UID of the object that this IP is assigned to.
	// It is stored in NetBox as a custom field.
	UID         UID    `json:"custom_fields,omitempty"`
	DNSName     string `json:"dns_name,omitempty"`
	Address     IP     `json:"address,omitempty"`
	Tags        []Tag  `json:"tags,omitempty"`
	Description string `json:"description,omitempty"`
}

IPAddress represents a NetBox IP address.

type IPAddressList

type IPAddressList struct {
	Count   uint        `json:"count"`
	Results []IPAddress `json:"results"`
}

IPAddressList represents the response from the NetBox endpoints that return multiple IP addresses.

type LabeledString

type LabeledString string

LabeledString represents the kind of field in NetBox which is a string upon writing to NetBox, but is an object {"value": "string", "label": "string"}, upon retrieving from NetBox.

func (*LabeledString) UnmarshalJSON

func (v *LabeledString) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for LabeledString.

type Tag

type Tag struct {
	ID   int64  `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
	Slug string `json:"slug,omitempty"`
}

Tag represents a NetBox tag.

type TagList

type TagList struct {
	Count   uint  `json:"count"`
	Results []Tag `json:"results"`
}

TagList represents the response from the NetBox endpoints that return multiple tags.

type UID

type UID string

UID is the type for representing UID of an IPAddress. Its purpose is to provide custom marshaling and unmarshaling.

func (UID) MarshalJSON

func (uid UID) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for UID.

func (*UID) UnmarshalJSON

func (uid *UID) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for UID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL