Compare commits

..

No commits in common. "836b8e717f6941d06f181194354a8e3719542563" and "f5bf955b0ea58467041e300f81c5f62ea6577949" have entirely different histories.

5 changed files with 264 additions and 633 deletions

View file

@ -1,288 +0,0 @@
package netboxgo
import (
"context"
"fmt"
"net/http"
"net/url"
"time"
// "fmt"
"github.com/gorilla/schema"
)
type DCIMInterfacesService service
// NewDCIMInterface is used for creating a new interface
type NewDCIMInterface struct {
CustomFields interface{} `json:"custom_fields"`
WWN string `json:"wwn"`
Label string `json:"label"`
Type string `json:"type"`
Cable struct {
Label string `json:"label"`
} `json:"cable"`
RFChannel string `json:"rf_channel"`
RFRole string `json:"rf_role"`
Name string `json:"name"`
Description string `json:"description"`
MACAddress string `json:"mac_address"`
Mode string `json:"mode"`
TaggedVLANs []int `json:"tagged_vlans"`
WirelessLANs []int `json:"wireless_lans"`
Tags []struct {
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
} `json:"tags"`
Device int `json:"device"`
Parent int `json:"parent"`
RFChannelFrequency int `json:"rf_channel_frequency"`
RFChannelWidth int `json:"rf_channel_width"`
TXPower int `json:"tx_power"`
UntaggedVLAN int `json:"untagged_vlan"`
Bridge int `json:"bridge"`
LAG int `json:"lag"`
MTU int `json:"mtu"`
WirelessLink int `json:"wireless_link"`
Enabled bool `json:"enabled"`
MarkConnected bool `json:"mark_connected"`
MGMTOnly bool `json:"mgmt_only"`
}
// DCIMInterfaces is a list of interfaces
type DCIMInterfaces struct {
Next interface{} `json:"next,omitempty"`
Previous interface{} `json:"previous,omitempty"`
Results []DCIMInterface `json:"results,omitempty"`
Count int `json:"count,omitempty"`
}
// DCIMInterface is one interface
type DCIMInterface struct {
CustomFields struct{} `json:"custom_fields"`
LastUpdated time.Time `json:"last_updated"`
LinkPeer interface{} `json:"link_peer"`
ConnectedEndpoint interface{} `json:"connected_endpoint"`
Parent struct {
Occupied string `json:"_occupied"`
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Device struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"device"`
Cable int `json:"cable"`
ID int `json:"id"`
} `json:"parent"`
Device struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"device"`
RFChannel struct {
Label string `json:"label"`
Value string `json:"value"`
} `json:"rf_channel"`
RFRole struct {
Label string `json:"label"`
Value string `json:"value"`
} `json:"rf_role"`
Type struct {
Label string `json:"label"`
Value string `json:"value"`
} `json:"type"`
Mode struct {
Label string `json:"label"`
Value string `json:"value"`
} `json:"mode"`
Display string `json:"display"`
LinkPeerType string `json:"link_peer_type"`
MACAddress string `json:"mac_address"`
WWN string `json:"wwn"`
URL string `json:"url"`
Description string `json:"description"`
ConnectedEndpointType string `json:"connected_endpoint_type"`
Label string `json:"label"`
Name string `json:"name"`
Created string `json:"created"`
Cable struct {
URL string `json:"url"`
Display string `json:"display"`
Label string `json:"label"`
ID int `json:"id"`
} `json:"cable"`
WirelessLink struct {
URL string `json:"url"`
Display string `json:"display"`
Ssid string `json:"ssid"`
ID int `json:"id"`
} `json:"wireless_link"`
WirelessLANs []struct {
URL string `json:"url"`
Display string `json:"display"`
Ssid string `json:"ssid"`
ID int `json:"id"`
} `json:"wireless_lans"`
TaggedVLANs []struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
Vid int `json:"vid"`
} `json:"tagged_vlans"`
Tags []struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
ID int `json:"id"`
} `json:"tags"`
UntaggedVLAN struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
Vid int `json:"vid"`
} `json:"untagged_vlan"`
LAG struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Device struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"device"`
ID int `json:"id"`
Cable int `json:"cable"`
Occupied bool `json:"_occupied"`
} `json:"lag"`
Bridge struct {
Occupied string `json:"_occupied"`
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Device struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"device"`
Cable int `json:"cable"`
ID int `json:"id"`
} `json:"bridge"`
CountIPAddresses int `json:"count_ipaddresses"`
MTU int `json:"mtu"`
TXPower int `json:"tx_power"`
CountFHRPGroups int `json:"count_fhrp_groups"`
RFChannelFrequency int `json:"rf_channel_frequency"`
ID int `json:"id"`
RFChannelWidth int `json:"rf_channel_width"`
ConnectedEndpointReachable bool `json:"connected_endpoint_reachable"`
MarkConnected bool `json:"mark_connected"`
MGMTOnly bool `json:"mgmt_only"`
Enabled bool `json:"enabled"`
Occupied bool `json:"_occupied"`
}
// DCIMInterfaceFilter is used to filter out returned object from Netbox API dcim_interfaces_list
type DCIMInterfaceFilter struct {
// User specific filters
ID string `schema:"id,omitempty"`
Name string `schema:"name,omitempty"`
ConnectionStatus string `schema:"connection_status,omitempty"`
Type string `schema:"type,omitempty"`
Mtu string `schema:"mtu,omitempty"`
MgmtOnly string `schema:"mgmt_only,omitempty"`
Mode string `schema:"mode,omitempty"`
Description string `schema:"description,omitempty"`
Q string `schema:"q,omitempty"`
Device string `schema:"device,omitempty"`
DeviceID string `schema:"device_id,omitempty"`
Cabled string `schema:"cabled,omitempty"`
Kind string `schema:"kind,omitempty"`
LagID string `schema:"lag_id,omitempty"`
MacAddress string `schema:"mac_address,omitempty"`
Tag string `schema:"tag,omitempty"`
VLANID string `schema:"vlan_id,omitempty"`
VLAN string `schema:"vlan,omitempty"`
Offset int64 `schema:"offset,omitempty"`
Limit int64 `schema:"limit,omitempty"`
}
const dcimInterfacesPath = dcimPath + "/interfaces"
// List devices. DeviceFilter is used to list based on filter queries.
func (s *DCIMInterfacesService) List(ctx context.Context, f *DCIMInterfaceFilter) (*DCIMInterfaces, error) {
var interfaces DCIMInterfaces
var query string
var req *http.Request
var err error
encoder := schema.NewEncoder()
form := url.Values{}
err = encoder.Encode(f, form)
if err != nil {
return &interfaces, err
}
query = form.Encode()
req, err = s.client.newRequest(ctx, "GET", dcimInterfacesPath, query, nil)
if err != nil {
return &interfaces, err
}
_, err = s.client.do(req, &interfaces)
if err != nil {
return &interfaces, err
}
return &interfaces, nil
}
// Create a interfaces
func (s *DCIMInterfacesService) Create(ctx context.Context, c *NewDCIMInterface) (*DCIMInterface, error) {
var err error
var req *http.Request
var nic DCIMInterface
req, err = s.client.newRequest(ctx, "POST", dcimInterfacesPath, "", c)
if err != nil {
return &nic, fmt.Errorf("unable to create request: %w", err)
}
_, err = s.client.do(req, &nic)
if err != nil {
return &nic, fmt.Errorf("unable to do request: %w", err)
}
return &nic, nil
}
// Delete a interface
func (s *DCIMInterfacesService) Delete(ctx context.Context, i string) error {
var err error
var req *http.Request
req, err = s.client.newRequest(ctx, "DELETE", dcimInterfacesPath+"/"+i+"/", "", nil)
if err != nil {
return fmt.Errorf("unable to create request: %w", err)
}
_, err = s.client.do(req, nil)
if err != nil {
return fmt.Errorf("unable to do request: %w", err)
}
return nil
}

162
interfaces.go Normal file
View file

@ -0,0 +1,162 @@
package netboxgo
import (
"context"
"fmt"
"net/http"
"net/url"
// "fmt"
"github.com/gorilla/schema"
)
type InterfacesService service
// NewInterface is used for the return values from Netbox API dcim_interfaces_create
type NewInterface struct {
Device int `json:"device"`
Name string `json:"name"`
Type int `json:"type,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Lag int `json:"lag,omitempty"`
Mtu int `json:"mtu,omitempty"`
MacAddress string `json:"mac_address,omitempty"`
MgmtOnly bool `json:"mgmt_only,omitempty"`
Description string `json:"description,omitempty"`
ConnectionStatus bool `json:"connection_status,omitempty"`
Cable struct {
Label string `json:"label,omitempty"`
} `json:"cable,omitempty"`
Mode int `json:"mode,omitempty"`
UntaggedVLAN int `json:"untagged_vlan,omitempty"`
TaggedVLANs []int `json:"tagged_vlans,omitempty"`
Tags []string `json:"tags,omitempty"`
}
// Interfaces is used for the return value from NetBox API dcim_interfaces_list
type Interfaces struct {
Count int `json:"count,omitempty"`
Next interface{} `json:"next,omitempty"`
Previous interface{} `json:"previous,omitempty"`
Results []struct {
ID int `json:"id,omitempty"`
Device struct {
ID int `json:"id,omitempty"`
URL string `json:"url,omitempty"`
Name string `json:"name,omitempty"`
DisplayName string `json:"display_name,omitempty"`
} `json:"device,omitempty"`
Name string `json:"name,omitempty"`
Type struct {
Value int `json:"value,omitempty"`
Label string `json:"label,omitempty"`
} `json:"type,omitempty"`
FormFactor struct {
Value int `json:"value,omitempty"`
Label string `json:"label,omitempty"`
} `json:"form_factor,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Lag struct {
ID int `json:"id,omitempty"`
URL string `json:"url,omitempty"`
Device struct {
ID int `json:"id,omitempty"`
URL string `json:"url,omitempty"`
Name string `json:"name,omitempty"`
DisplayName string `json:"display_name,omitempty"`
} `json:"device,omitempty"`
Name string `json:"name,omitempty"`
Cable interface{} `json:"cable,omitempty"`
ConnectionStatus interface{} `json:"connection_status,omitempty"`
} `json:"lag,omitempty"`
Mtu interface{} `json:"mtu,omitempty"`
MacAddress interface{} `json:"mac_address,omitempty"`
MgmtOnly bool `json:"mgmt_only,omitempty"`
Description string `json:"description,omitempty"`
ConnectedEndpointType interface{} `json:"connected_endpoint_type,omitempty"`
ConnectedEndpoint interface{} `json:"connected_endpoint,omitempty"`
ConnectionStatus interface{} `json:"connection_status,omitempty"`
Cable interface{} `json:"cable,omitempty"`
Mode interface{} `json:"mode,omitempty"`
UntaggedVLAN interface{} `json:"untagged_vlan,omitempty"`
TaggedVLANs []interface{} `json:"tagged_vlans,omitempty"`
Tags []interface{} `json:"tags,omitempty"`
CountIpaddresses int `json:"count_ipaddresses,omitempty"`
} `json:"results,omitempty"`
}
// InterfaceFilter is used to filter out returned object from Netbox API dcim_interfaces_list
type InterfaceFilter struct {
Offset int64 `schema:"offset,omitempty"`
Limit int64 `schema:"limit,omitempty"`
// User specific filters
ID string `schema:"id,omitempty"`
Name string `schema:"name,omitempty"`
ConnectionStatus string `schema:"connection_status,omitempty"`
Type string `schema:"type,omitempty"`
Mtu string `schema:"mtu,omitempty"`
MgmtOnly string `schema:"mgmt_only,omitempty"`
Mode string `schema:"mode,omitempty"`
Description string `schema:"description,omitempty"`
Q string `schema:"q,omitempty"`
Device string `schema:"device,omitempty"`
DeviceID string `schema:"device_id,omitempty"`
Cabled string `schema:"cabled,omitempty"`
Kind string `schema:"kind,omitempty"`
LagID string `schema:"lag_id,omitempty"`
MacAddress string `schema:"mac_address,omitempty"`
Tag string `schema:"tag,omitempty"`
VLANID string `schema:"vlan_id,omitempty"`
VLAN string `schema:"vlan,omitempty"`
}
const interfacesPath = dcimPath + "/interfaces"
// List devices. DeviceFilter is used to list based on filter queries.
func (s *InterfacesService) List(ctx context.Context, f *InterfaceFilter) (*Interfaces, error) {
var interfaces Interfaces
var query string
var req *http.Request
var err error
encoder := schema.NewEncoder()
form := url.Values{}
err = encoder.Encode(f, form)
if err != nil {
return &interfaces, err
}
query = form.Encode()
req, err = s.client.newRequest(ctx, "GET", interfacesPath, query, nil)
if err != nil {
return &interfaces, err
}
_, err = s.client.do(req, &interfaces)
if err != nil {
return &interfaces, err
}
return &interfaces, nil
}
// Create a interfaces
func (s *InterfacesService) Create(ctx context.Context, c *NewInterface) error {
var err error
var req *http.Request
req, err = s.client.newRequest(ctx, "POST", interfacesPath, "", c)
if err != nil {
return fmt.Errorf("unable to create request: %w", err)
}
_, err = s.client.do(req, nil)
if err != nil {
return fmt.Errorf("unable to do request: %w", err)
}
return nil
}

View file

@ -15,24 +15,29 @@ import (
// Client struct is used to create a new NetBox endpoint
type Client struct {
Clusters *ClustersService
ClusterTypes *ClusterTypesService
Devices *DevicesService
DeviceRoles *DeviceRolesService
DeviceTypes *DeviceTypesService
DCIMInterfaces *DCIMInterfacesService
InventoryItems *InventoryItemsService
Secrets *SecretsService
Sites *SitesService
SiteGroups *SiteGroupsService
Platforms *PlatformsService
Prefixes *PrefixesService
RearPorts *RearPortsService
Tenants *TenantsService
VirtualMachines *VirtualMachinesService
VirtualizationInterfaces *VirtualizationInterfacesService
VRFs *VRFsService
VLANs *VLANsService
// DCIM *DCIM
// Tenancy *Tenancy
// IPAM *IPAM
// Virtualization *Virtualization
// Secret *Secret
Clusters *ClustersService
ClusterTypes *ClusterTypesService
Devices *DevicesService
DeviceRoles *DeviceRolesService
DeviceTypes *DeviceTypesService
Interfaces *InterfacesService
InventoryItems *InventoryItemsService
Secrets *SecretsService
Sites *SitesService
SiteGroups *SiteGroupsService
Platforms *PlatformsService
Prefixes *PrefixesService
RearPorts *RearPortsService
Tenants *TenantsService
VirtualMachines *VirtualMachinesService
VRFs *VRFsService
VLANs *VLANsService
// baseURL is the URL used for the base URL of the API
baseURL *url.URL
@ -127,8 +132,7 @@ func NewClient(apiurl string, httpClient *http.Client) (*Client, error) {
c.Devices = (*DevicesService)(&c.common)
c.DeviceRoles = (*DeviceRolesService)(&c.common)
c.DeviceTypes = (*DeviceTypesService)(&c.common)
c.DCIMInterfaces = (*DCIMInterfacesService)(&c.common)
c.VirtualizationInterfaces = (*VirtualizationInterfacesService)(&c.common)
c.Interfaces = (*InterfacesService)(&c.common)
c.InventoryItems = (*InventoryItemsService)(&c.common)
c.Prefixes = (*PrefixesService)(&c.common)
c.Platforms = (*PlatformsService)(&c.common)

View file

@ -12,124 +12,90 @@ import (
type VirtualMachinesService service
// VirtualMachines is a list of virtual-machines
type VirtualMachines struct {
Next interface{} `json:"next"`
Previous interface{} `json:"previous"`
Results []VirtualMachine `json:"results"`
Count int `json:"count"`
}
// VirtualMachine is one virtual-machine
type VirtualMachine struct {
CustomFields interface{} `json:"custom_fields"`
LastUpdated time.Time `json:"last_updated"`
Tenant struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
ID int `json:"id"`
} `json:"tenant"`
Site struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
ID int `json:"id"`
} `json:"site"`
PrimaryIP6 struct {
URL string `json:"url"`
Display string `json:"display"`
Address string `json:"address"`
ID int `json:"id"`
Family int `json:"family"`
} `json:"primary_ip6"`
PrimaryIP struct {
URL string `json:"url"`
Display string `json:"display"`
Address string `json:"address"`
ID int `json:"id"`
Family int `json:"family"`
} `json:"primary_ip"`
PrimaryIP4 struct {
URL string `json:"url"`
Display string `json:"display"`
Address string `json:"address"`
ID int `json:"id"`
Family int `json:"family"`
} `json:"primary_ip4"`
ConfigContext interface{} `json:"config_context"`
Status struct {
Label string `json:"label"`
Value string `json:"value"`
} `json:"status"`
URL string `json:"url"`
Name string `json:"name"`
Display string `json:"display"`
Created string `json:"created"`
Comments string `json:"comments"`
LocalContextData interface{} `json:"local_context_data"`
Cluster struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
VirtualmachineCount int `json:"virtualmachine_count"`
} `json:"cluster"`
Tags []struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
ID int `json:"id"`
} `json:"tags"`
Platform struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
ID int `json:"id"`
DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"`
} `json:"platform"`
Role struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
ID int `json:"id"`
DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"`
} `json:"role"`
Disk int `json:"disk"`
Memory int `json:"memory"`
Vcpus int `json:"vcpus"`
ID int `json:"id"`
Next interface{} `json:"next"`
Previous interface{} `json:"previous"`
Results []struct {
LastUpdated time.Time `json:"last_updated"`
Vcpus interface{} `json:"vcpus"`
CustomFields interface{} `json:"custom_fields,omitempty"`
LocalContextData interface{} `json:"local_context_data"`
Disk interface{} `json:"disk"`
Site interface{} `json:"site"`
Memory interface{} `json:"memory"`
ConfigContext interface{} `json:"config_context,omitempty"`
Tenant interface{} `json:"tenant"`
PrimaryIP6 interface{} `json:"primary_ip6"`
Status struct {
Value string `json:"value"`
Label string `json:"label"`
} `json:"status"`
Name string `json:"name"`
URL string `json:"url"`
Display string `json:"display"`
Created string `json:"created"`
Comments string `json:"comments"`
Platform struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
ID int `json:"id"`
} `json:"platform"`
Role struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
ID int `json:"id"`
} `json:"role"`
Cluster struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"cluster"`
Tags []interface{} `json:"tags"`
PrimaryIP4 struct {
URL string `json:"url"`
Display string `json:"display"`
Address string `json:"address"`
ID int `json:"id"`
Family int `json:"family"`
} `json:"primary_ip4"`
PrimaryIP struct {
URL string `json:"url"`
Display string `json:"display"`
Address string `json:"address"`
ID int `json:"id"`
Family int `json:"family"`
} `json:"primary_ip"`
ID int `json:"id"`
} `json:"results"`
Count int `json:"count"`
}
// NewVirtualMachine is used to create new VirtualizationVirtualMachines
type NewVirtualMachine struct {
LocalContextData interface{} `json:"local_context_data,omitempty"`
CustomFields *struct{} `json:"custom_fields,omitempty"`
Status string `json:"status"`
LocalContextData interface{} `json:"local_context_data,omitempty"`
Comments string `json:"comments,omitempty"`
Name string `json:"name"`
Tags *[]struct {
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
Color string `json:"color,omitempty"`
} `json:"tags,omitempty"`
Status string `json:"status"`
Comments string `json:"comments,omitempty"`
Name string `json:"name"`
PrimaryIP4 int `json:"primary_ip4,omitempty"`
Platform int `json:"platform,omitempty"`
VCPUs int `json:"vcpus,omitempty"`
Memory int `json:"memory,omitempty"`
Disk int `json:"disk,omitempty"`
Role int `json:"role,omitempty"`
Cluster int `json:"cluster,omitempty"`
Tenant int `json:"tenant,omitempty"`
PrimaryIP6 int `json:"primary_ip6,omitempty"`
Platform int `json:"platform,omitempty"`
PrimaryIP4 int `json:"primary_ip4,omitempty"`
VCPUs int `json:"vcpus,omitempty"`
Memory int `json:"memory,omitempty"`
Disk int `json:"disk,omitempty"`
Role int `json:"role,omitempty"`
Cluster int `json:"cluster,omitempty"`
Tenant int `json:"tenant,omitempty"`
PrimaryIP6 int `json:"primary_ip6,omitempty"`
}
// VirtualMachineFilter is used to filter dcim_device_list query to the Netbox API
@ -211,22 +177,21 @@ func (s *VirtualMachinesService) List(ctx context.Context, f *VirtualMachineFilt
}
// Create a virtual-machine
func (s *VirtualMachinesService) Create(ctx context.Context, c *NewVirtualMachine) (*VirtualMachine, error) {
func (s *VirtualMachinesService) Create(ctx context.Context, c *NewVirtualMachine) error {
var err error
var req *http.Request
var virtualMachine VirtualMachine
req, err = s.client.newRequest(ctx, "POST", virtualMachinesPath, "", c)
if err != nil {
return &virtualMachine, fmt.Errorf("unable to create request: %w", err)
return fmt.Errorf("unable to create request: %w", err)
}
_, err = s.client.do(req, &virtualMachine)
_, err = s.client.do(req, nil)
if err != nil {
return &virtualMachine, fmt.Errorf("unable to do request: %w", err)
return fmt.Errorf("unable to do request: %w", err)
}
return &virtualMachine, nil
return nil
}
// Delete a virtual-machine

View file

@ -1,212 +0,0 @@
package netboxgo
import (
"context"
"fmt"
"net/http"
"net/url"
"time"
"github.com/gorilla/schema"
)
type VirtualizationInterfacesService service
// NewVirtualizationInterface is used for creating a new virtualization interface
type NewVirtualizationInterface struct {
CustomFields *interface{} `json:"custom_fields,omitempty"`
Name string `json:"name"`
Mode string `json:"mode,omitempty"`
Description string `json:"description,omitempty"`
MACAddress string `json:"mac_address,omitempty"`
Tags *[]struct {
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
Color string `json:"color,omitempty"`
} `json:"tags,omitempty"`
TaggedVLANs *[]int `json:"tagged_vlans,omitempty"`
Bridge int `json:"bridge,omitempty"`
Parent int `json:"parent,omitempty"`
UntaggedVLAN int `json:"untagged_vlan,omitempty"`
MTU int `json:"mtu,omitempty"`
VirtualMachine int `json:"virtual_machine"`
Enabled bool `json:"enabled,omitempty"`
}
// VirtualizationInterfaces is a list of interfaces
type VirtualizationInterfaces struct {
Next string `json:"next,omitempty"`
Previous string `json:"previous,omitempty"`
Results []VirtualizationInterface `json:"results,omitempty"`
Count int `json:"count,omitempty"`
}
// VirtualizationInterface is one virtualization interface
type VirtualizationInterface struct {
LastUpdated time.Time `json:"last_updated"`
CustomFields interface{} `json:"custom_fields"`
Mode struct {
Label string `json:"label"`
Value string `json:"value"`
} `json:"mode"`
Display string `json:"display"`
Description string `json:"description"`
Created string `json:"created"`
URL string `json:"url"`
Name string `json:"name"`
MACAddress string `json:"mac_address"`
VirtualMachine struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"virtual_machine"`
TaggedVLANs []struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
Vid int `json:"vid"`
} `json:"tagged_vlans"`
Tags []struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
ID int `json:"id"`
} `json:"tags"`
Bridge struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
VirtualMachine struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"virtual_machine"`
ID int `json:"id"`
} `json:"bridge"`
Parent struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
VirtualMachine struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
} `json:"virtual_machine"`
ID int `json:"id"`
} `json:"parent"`
UntaggedVLAN struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
ID int `json:"id"`
Vid int `json:"vid"`
} `json:"untagged_vlan"`
ID int `json:"id"`
MTU int `json:"mtu"`
CountIPAddresses int `json:"count_ipaddresses"`
CountFHRPGroups int `json:"count_fhrp_groups"`
Enabled bool `json:"enabled"`
}
// VirtualizationInterfaceFilter is used to filter out virtualization interfaces
type VirtualizationInterfaceFilter struct {
// User specific filters
ID string `schema:"id,omitempty"`
Name string `schema:"name,omitempty"`
ConnectionStatus string `schema:"connection_status,omitempty"`
Type string `schema:"type,omitempty"`
MTU string `schema:"mtu,omitempty"`
MGMTOnly string `schema:"mgmt_only,omitempty"`
Mode string `schema:"mode,omitempty"`
Description string `schema:"description,omitempty"`
Q string `schema:"q,omitempty"`
VirtualMachine string `schema:"device,omitempty"`
ClusterID string `schema:"cluster_id,omitempty"`
VirtualMachineID string `schema:"virtual_machine_id,omitempty"`
Cabled string `schema:"cabled,omitempty"`
Kind string `schema:"kind,omitempty"`
LagID string `schema:"lag_id,omitempty"`
MACAddress string `schema:"mac_address,omitempty"`
Tag string `schema:"tag,omitempty"`
VLANID string `schema:"vlan_id,omitempty"`
VLAN string `schema:"vlan,omitempty"`
ParentID string `schema:"parent_id,omitempty"`
BridgeID string `schema:"bridge_id,omitempty"`
Offset int64 `schema:"offset,omitempty"`
Limit int64 `schema:"limit,omitempty"`
}
const virtualizationInterfacesPath = virtualizationPath + "/interfaces/"
// List devices. DeviceFilter is used to list based on filter queries.
func (s *VirtualizationInterfacesService) List(ctx context.Context, f *VirtualizationInterfaceFilter) (*VirtualizationInterfaces, error) {
var interfaces VirtualizationInterfaces
var query string
var req *http.Request
var err error
encoder := schema.NewEncoder()
form := url.Values{}
err = encoder.Encode(f, form)
if err != nil {
return &interfaces, err
}
query = form.Encode()
req, err = s.client.newRequest(ctx, "GET", virtualizationInterfacesPath, query, nil)
if err != nil {
return &interfaces, err
}
_, err = s.client.do(req, &interfaces)
if err != nil {
return &interfaces, err
}
return &interfaces, nil
}
// Create a interfaces
func (s *VirtualizationInterfacesService) Create(ctx context.Context, c *NewVirtualizationInterface) (*VirtualizationInterface, error) {
var err error
var req *http.Request
var nic VirtualizationInterface
req, err = s.client.newRequest(ctx, "POST", virtualizationInterfacesPath, "", c)
if err != nil {
return &nic, fmt.Errorf("unable to create request: %w", err)
}
_, err = s.client.do(req, &nic)
if err != nil {
return &nic, fmt.Errorf("unable to do request: %w", err)
}
return &nic, nil
}
// Delete a interface
func (s *VirtualizationInterfacesService) Delete(ctx context.Context, i string) error {
var err error
var req *http.Request
req, err = s.client.newRequest(ctx, "DELETE", virtualizationInterfacesPath+"/"+i+"/", "", nil)
if err != nil {
return fmt.Errorf("unable to create request: %w", err)
}
_, err = s.client.do(req, nil)
if err != nil {
return fmt.Errorf("unable to do request: %w", err)
}
return nil
}