Add network hardware info (#8358)

peerRESTVersion changed to v6
This commit is contained in:
Ashish Kumar Sinha
2019-10-17 16:39:50 +05:30
committed by Harshavardhana
parent 3adc311c1c
commit 18cb15559d
10 changed files with 222 additions and 11 deletions

View File

@@ -20,6 +20,7 @@ package madmin
import (
"encoding/json"
"io/ioutil"
"net"
"net/http"
"net/url"
@@ -34,6 +35,8 @@ const (
HARDWARE = "hwType"
// CPU represents hardware as cpu
CPU HardwareType = "cpu"
// NETWORK hardware Info
NETWORK HardwareType = "network"
)
// ServerCPUHardwareInfo holds informantion about cpu hardware
@@ -76,3 +79,44 @@ func (adm *AdminClient) ServerCPUHardwareInfo() ([]ServerCPUHardwareInfo, error)
}
return cpuInfo, nil
}
// ServerNetworkHardwareInfo holds informantion about cpu hardware
type ServerNetworkHardwareInfo struct {
Addr string `json:"addr"`
Error string `json:"error,omitempty"`
NetworkInfo []net.Interface `json:"network"`
}
// ServerNetworkHardwareInfo - Returns network hardware information
func (adm *AdminClient) ServerNetworkHardwareInfo() ([]ServerNetworkHardwareInfo, error) {
v := url.Values{}
v.Set(HARDWARE, string(NETWORK))
resp, err := adm.executeMethod("GET", requestData{
relPath: "/v1/hardware",
queryValues: v,
})
defer closeResponse(resp)
if err != nil {
return nil, err
}
// Check response http status code
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
// Unmarshal the server's json response
var networkInfo []ServerNetworkHardwareInfo
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(respBytes, &networkInfo)
if err != nil {
return nil, err
}
return networkInfo, nil
}