Fix GoMetaLint errors.
This commit is contained in:
parent
b1ad0dab6f
commit
620a6cf71f
3 changed files with 58 additions and 36 deletions
|
@ -1,13 +1,15 @@
|
||||||
package netboxgo
|
package netboxgo
|
||||||
|
|
||||||
|
// NetBox settings struct
|
||||||
type NetBox struct {
|
type NetBox struct {
|
||||||
RootURL string
|
RootURL string
|
||||||
Token string
|
Token string
|
||||||
InsecureSkipVerify bool
|
InsecureSkipVerify bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NetBox) New(root, token string, TlsSkipVerify bool) {
|
// New populates the NetBox settings struct
|
||||||
|
func (n *NetBox) New(root, token string, TLSSkipVerify bool) {
|
||||||
n.RootURL = root
|
n.RootURL = root
|
||||||
n.Token = token
|
n.Token = token
|
||||||
n.InsecureSkipVerify = TlsSkipVerify
|
n.InsecureSkipVerify = TLSSkipVerify
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,17 @@ package netboxgo
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/gorilla/schema"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/schema"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dcim_Devices_List struct {
|
// DcimDevicesList is used for Netbox dcim_device_list return struct
|
||||||
|
type DcimDevicesList struct {
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
Next string `json:"next"`
|
Next string `json:"next"`
|
||||||
Previous string `json:"previous"`
|
Previous string `json:"previous"`
|
||||||
|
@ -138,43 +140,44 @@ type Dcim_Devices_List struct {
|
||||||
} `json:"results"`
|
} `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeviceFilter is used to filter dcim_device_list query to the Netbox API
|
||||||
type DeviceFilter struct {
|
type DeviceFilter struct {
|
||||||
Offset int64 `schema:"offset,omitempty"`
|
Offset int64 `schema:"offset,omitempty"`
|
||||||
Limit int64 `schema:"limit,omitempty"`
|
Limit int64 `schema:"limit,omitempty"`
|
||||||
|
|
||||||
//User specific filters
|
//User specific filters
|
||||||
Id string `schema:"id,omitempty"`
|
ID string `schema:"id,omitempty"`
|
||||||
Name string `schema:"name,omitempty"`
|
Name string `schema:"name,omitempty"`
|
||||||
AssetTag string `schema:"asset_tag,omitempty"`
|
AssetTag string `schema:"asset_tag,omitempty"`
|
||||||
Face string `schema:"face,omitempty"`
|
Face string `schema:"face,omitempty"`
|
||||||
Position string `schema:"position,omitempty"`
|
Position string `schema:"position,omitempty"`
|
||||||
VcPosition string `schema:"vc_position,omitempty"`
|
VcPosition string `schema:"vc_position,omitempty"`
|
||||||
VcPriority string `schema:"vc_priority,omitempty"`
|
VcPriority string `schema:"vc_priority,omitempty"`
|
||||||
TenantGroupId string `schema:"tenant_group_id,omitempty"`
|
TenantGroupID string `schema:"tenant_group_id,omitempty"`
|
||||||
TenantGroup string `schema:"tenant_group,omitempty"`
|
TenantGroup string `schema:"tenant_group,omitempty"`
|
||||||
TenantId string `schema:"tenant_id,omitempty"`
|
TenantID string `schema:"tenant_id,omitempty"`
|
||||||
Tenant string `schema:"tenant,omitempty"`
|
Tenant string `schema:"tenant,omitempty"`
|
||||||
IdIn string `schema:"id__in,omitempty"`
|
IDIn string `schema:"id__in,omitempty"`
|
||||||
Q string `schema:"q,omitempty"`
|
Q string `schema:"q,omitempty"`
|
||||||
ManufacturerId string `schema:"manufacturer_id,omitempty"`
|
ManufacturerID string `schema:"manufacturer_id,omitempty"`
|
||||||
Manufacturer string `schema:"manufacturer,omitempty"`
|
Manufacturer string `schema:"manufacturer,omitempty"`
|
||||||
DeviceTypeId string `schema:"device_type_id,omitempty"`
|
DeviceTypeID string `schema:"device_type_id,omitempty"`
|
||||||
RoleId string `schema:"role_id,omitempty"`
|
RoleID string `schema:"role_id,omitempty"`
|
||||||
Role string `schema:"role,omitempty"`
|
Role string `schema:"role,omitempty"`
|
||||||
RegionId string `schema:"region_id,omitempty"`
|
RegionID string `schema:"region_id,omitempty"`
|
||||||
Region string `schema:"region,omitempty"`
|
Region string `schema:"region,omitempty"`
|
||||||
SiteId string `schema:"site_id,omitempty"`
|
SiteID string `schema:"site_id,omitempty"`
|
||||||
Site string `schema:"site,omitempty"`
|
Site string `schema:"site,omitempty"`
|
||||||
RackGroupId string `schema:"rack_group_id,omitempty"`
|
RackGroupID string `schema:"rack_group_id,omitempty"`
|
||||||
RackId string `schema:"rack_id,omitempty"`
|
RackID string `schema:"rack_id,omitempty"`
|
||||||
ClusterId string `schema:"cluster_id,omitempty"`
|
ClusterID string `schema:"cluster_id,omitempty"`
|
||||||
Model string `schema:"model,omitempty"`
|
Model string `schema:"model,omitempty"`
|
||||||
Status string `schema:"status,omitempty"`
|
Status string `schema:"status,omitempty"`
|
||||||
IsfullDepth string `schema:"is_full_depth,omitempty"`
|
IsfullDepth string `schema:"is_full_depth,omitempty"`
|
||||||
MacAddress string `schema:"mac_address,omitempty"`
|
MacAddress string `schema:"mac_address,omitempty"`
|
||||||
Serial string `schema:"serial,omitempty"`
|
Serial string `schema:"serial,omitempty"`
|
||||||
HasPrimaryIp string `schema:"has_primary_ip,omitempty"`
|
HasPrimaryIP string `schema:"has_primary_ip,omitempty"`
|
||||||
VirtualChassiId string `schema:"virtual_chassis_id,omitempty"`
|
VirtualChassiID string `schema:"virtual_chassis_id,omitempty"`
|
||||||
VirtualChassiMember string `schema:"virtual_chassis_member,omitempty"`
|
VirtualChassiMember string `schema:"virtual_chassis_member,omitempty"`
|
||||||
ConsolePorts string `schema:"console_ports,omitempty"`
|
ConsolePorts string `schema:"console_ports,omitempty"`
|
||||||
ConsoleServerPorts string `schema:"console_server_ports,omitempty"`
|
ConsoleServerPorts string `schema:"console_server_ports,omitempty"`
|
||||||
|
@ -185,7 +188,8 @@ type DeviceFilter struct {
|
||||||
Tag string `schema:"tag,omitempty"`
|
Tag string `schema:"tag,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NetBox) ListDevices(d *Dcim_Devices_List, f *DeviceFilter) error {
|
// ListDevices method returns dcim_device_list from Netbox API
|
||||||
|
func (n *NetBox) ListDevices(d *DcimDevicesList, f *DeviceFilter) error {
|
||||||
var encoder = schema.NewEncoder()
|
var encoder = schema.NewEncoder()
|
||||||
|
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{
|
||||||
|
@ -218,7 +222,6 @@ func (n *NetBox) ListDevices(d *Dcim_Devices_List, f *DeviceFilter) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
|
||||||
|
|
||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
return errors.Errorf("Error: response was: %d should be %d (%s)\n", response.StatusCode, http.StatusOK, deviceurl)
|
return errors.Errorf("Error: response was: %d should be %d (%s)\n", response.StatusCode, http.StatusOK, deviceurl)
|
||||||
|
@ -229,6 +232,11 @@ func (n *NetBox) ListDevices(d *Dcim_Devices_List, f *DeviceFilter) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = response.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(data, &d)
|
err = json.Unmarshal(data, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -4,16 +4,19 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
// "fmt"
|
// "fmt"
|
||||||
"github.com/gorilla/schema"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/schema"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dcim_Interfaces_Create struct {
|
// DcimInterfacesCreate is used for the return values from Netbox API dcim_interfaces_create
|
||||||
|
type DcimInterfacesCreate struct {
|
||||||
Device int `json:"device"`
|
Device int `json:"device"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type int `json:"type,omitempty"`
|
Type int `json:"type,omitempty"`
|
||||||
|
@ -33,7 +36,8 @@ type Dcim_Interfaces_Create struct {
|
||||||
Tags []string `json:"tags,omitempty"`
|
Tags []string `json:"tags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Dcim_Interfaces_List struct {
|
// DcimInterfacesList is used for the return value from NetBox API dcim_interfaces_list
|
||||||
|
type DcimInterfacesList struct {
|
||||||
Count int `json:"count,omitempty"`
|
Count int `json:"count,omitempty"`
|
||||||
Next interface{} `json:"next,omitempty"`
|
Next interface{} `json:"next,omitempty"`
|
||||||
Previous interface{} `json:"previous,omitempty"`
|
Previous interface{} `json:"previous,omitempty"`
|
||||||
|
@ -84,12 +88,13 @@ type Dcim_Interfaces_List struct {
|
||||||
} `json:"results,omitempty"`
|
} `json:"results,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InterfaceFilter is used to filter out returned object from Netbox API dcim_interfaces_list
|
||||||
type InterfaceFilter struct {
|
type InterfaceFilter struct {
|
||||||
Offset int64 `schema:"offset,omitempty"`
|
Offset int64 `schema:"offset,omitempty"`
|
||||||
Limit int64 `schema:"limit,omitempty"`
|
Limit int64 `schema:"limit,omitempty"`
|
||||||
|
|
||||||
//User specific filters
|
//User specific filters
|
||||||
Id string `schema:"id,omitempty"`
|
ID string `schema:"id,omitempty"`
|
||||||
Name string `schema:"name,omitempty"`
|
Name string `schema:"name,omitempty"`
|
||||||
ConnectionStatus string `schema:"connection_status,omitempty"`
|
ConnectionStatus string `schema:"connection_status,omitempty"`
|
||||||
Type string `schema:"type,omitempty"`
|
Type string `schema:"type,omitempty"`
|
||||||
|
@ -99,17 +104,18 @@ type InterfaceFilter struct {
|
||||||
Description string `schema:"description,omitempty"`
|
Description string `schema:"description,omitempty"`
|
||||||
Q string `schema:"q,omitempty"`
|
Q string `schema:"q,omitempty"`
|
||||||
Device string `schema:"device,omitempty"`
|
Device string `schema:"device,omitempty"`
|
||||||
DeviceId string `schema:"device_id,omitempty"`
|
DeviceID string `schema:"device_id,omitempty"`
|
||||||
Cabled string `schema:"cabled,omitempty"`
|
Cabled string `schema:"cabled,omitempty"`
|
||||||
Kind string `schema:"kind,omitempty"`
|
Kind string `schema:"kind,omitempty"`
|
||||||
LagId string `schema:"lag_id,omitempty"`
|
LagID string `schema:"lag_id,omitempty"`
|
||||||
MacAddress string `schema:"mac_address,omitempty"`
|
MacAddress string `schema:"mac_address,omitempty"`
|
||||||
Tag string `schema:"tag,omitempty"`
|
Tag string `schema:"tag,omitempty"`
|
||||||
VlanId string `schema:"vlan_id,omitempty"`
|
VlanID string `schema:"vlan_id,omitempty"`
|
||||||
Vlan string `schema:"vlan,omitempty"`
|
Vlan string `schema:"vlan,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NetBox) ListInterfaces(i *Dcim_Interfaces_List, f *InterfaceFilter) error {
|
// ListInterfaces returns Netbox dcim_interfaces_list
|
||||||
|
func (n *NetBox) ListInterfaces(i *DcimInterfacesList, f *InterfaceFilter) error {
|
||||||
var encoder = schema.NewEncoder()
|
var encoder = schema.NewEncoder()
|
||||||
|
|
||||||
form := url.Values{}
|
form := url.Values{}
|
||||||
|
@ -137,7 +143,6 @@ func (n *NetBox) ListInterfaces(i *Dcim_Interfaces_List, f *InterfaceFilter) err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
|
||||||
|
|
||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
return errors.Errorf("Error: response was: %d should be %d\n", response.StatusCode, http.StatusOK)
|
return errors.Errorf("Error: response was: %d should be %d\n", response.StatusCode, http.StatusOK)
|
||||||
|
@ -148,6 +153,11 @@ func (n *NetBox) ListInterfaces(i *Dcim_Interfaces_List, f *InterfaceFilter) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = response.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(data, &i)
|
err = json.Unmarshal(data, &i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -155,7 +165,8 @@ func (n *NetBox) ListInterfaces(i *Dcim_Interfaces_List, f *InterfaceFilter) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NetBox) CreateInterfaces(i *Dcim_Interfaces_Create) error {
|
// CreateInterfaces creates interfaces via Netbox API dcim_interfaces_create
|
||||||
|
func (n *NetBox) CreateInterfaces(i *DcimInterfacesCreate) error {
|
||||||
interfaceData, err := json.Marshal(i)
|
interfaceData, err := json.Marshal(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -179,12 +190,13 @@ func (n *NetBox) CreateInterfaces(i *Dcim_Interfaces_Create) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
err = response.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if response.StatusCode == http.StatusCreated {
|
if response.StatusCode == http.StatusCreated {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return errors.Errorf("Error: response was: %d should be %d\n", response.StatusCode, http.StatusCreated)
|
|
||||||
}
|
}
|
||||||
return nil
|
return errors.Errorf("Error: response was: %d should be %d\n", response.StatusCode, http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue