Fix ListInterfaces

This commit is contained in:
Kalle Carlbark 2019-09-11 11:39:31 +02:00
parent f174476cdc
commit 37458a35ed
No known key found for this signature in database
GPG key ID: 3FC0C93C5A5A0670

View file

@ -4,9 +4,10 @@ import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
// "fmt"
"github.com/gorilla/schema"
"github.com/pkg/errors"
"io/ioutil"
"net/http"
"net/url"
"time"
@ -117,7 +118,39 @@ func (i *Dcim_Interfaces_List) ListInterfaces(n *NetBox, f *InterfaceFilter) err
return err
}
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
}
@ -134,7 +167,6 @@ func (i *Dcim_Interfaces_Create) CreateInterfaces(n *NetBox) error {
Timeout: timeout,
Transport: transport,
}
fmt.Println(bytes.NewBuffer(interfaceData))
request, err := http.NewRequest("POST", n.RootURL+"/api/dcim/interfaces/", bytes.NewBuffer(interfaceData))
if err != nil {
return err