Fix ListInterfaces
This commit is contained in:
parent
f174476cdc
commit
37458a35ed
1 changed files with 35 additions and 3 deletions
|
@ -4,9 +4,10 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
// "fmt"
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
@ -117,7 +118,39 @@ func (i *Dcim_Interfaces_List) ListInterfaces(n *NetBox, f *InterfaceFilter) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
query := form.Encode()
|
query := form.Encode()
|
||||||
fmt.Println(query)
|
|
||||||
|
transport := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: n.InsecureSkipVerify},
|
||||||
|
}
|
||||||
|
timeout := time.Duration(60 * time.Second)
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: timeout,
|
||||||
|
Transport: transport,
|
||||||
|
}
|
||||||
|
request, err := http.NewRequest("GET", n.RootURL+"/api/dcim/interfaces/?"+query, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
request.Header.Add("Accept", "application/json")
|
||||||
|
request.Header.Add("Authorization", " Token "+n.Token)
|
||||||
|
response, err := client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if response.StatusCode != http.StatusOK {
|
||||||
|
return errors.Errorf("Error: response was: %d should be %d\n", response.StatusCode, http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &i)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +167,6 @@ func (i *Dcim_Interfaces_Create) CreateInterfaces(n *NetBox) error {
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
}
|
}
|
||||||
fmt.Println(bytes.NewBuffer(interfaceData))
|
|
||||||
request, err := http.NewRequest("POST", n.RootURL+"/api/dcim/interfaces/", bytes.NewBuffer(interfaceData))
|
request, err := http.NewRequest("POST", n.RootURL+"/api/dcim/interfaces/", bytes.NewBuffer(interfaceData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue