Netbox librarararary.
This commit is contained in:
parent
066a3e5251
commit
44968a9d6f
3 changed files with 40 additions and 27 deletions
5
netbox.go
Normal file
5
netbox.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package netboxclient
|
||||
|
||||
type NetBox struct {
|
||||
RootURL string
|
||||
}
|
|
@ -1,4 +1,12 @@
|
|||
package main
|
||||
package netboxclient
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/pkg/errors"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type dcim_interfaces_create struct {
|
||||
Device int `json:"device"`
|
||||
|
@ -71,6 +79,31 @@ type dcim_interfaces_list struct {
|
|||
} `json:"results"`
|
||||
}
|
||||
|
||||
func (i *NbInterfaces) CreateInterface() {
|
||||
func (i *dcim_interfaces_create) CreateInterface(n *NetBox) error {
|
||||
interfaceData, err := json.Marshal(i)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
timeout := time.Duration(60 * time.Second)
|
||||
client := &http.Client{
|
||||
Timeout: timeout,
|
||||
}
|
||||
request, err := http.NewRequest("POST", n.RootURL+"/dcim/interfaces/", bytes.NewBuffer(interfaceData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if response.StatusCode == http.StatusCreated {
|
||||
return nil
|
||||
} else {
|
||||
return errors.Errorf("Response was: %d\n", response.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *dcim_interface_list) ListInterface(n *NetBox) error {
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type DeviceInterface struct {
|
||||
Id int `json:"id"`
|
||||
Device int `json:"device"`
|
||||
Name string `json:"name"`
|
||||
Type int `json:"type"`
|
||||
FormFactor string `json:"form_factor"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Lag int `json:"lag"`
|
||||
Mtu int `json:"mtu"`
|
||||
MacAddress string `json:"mac_address"`
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func (i * InterfacesCreate
|
Loading…
Reference in a new issue