mirror of
https://github.com/minio/minio.git
synced 2025-11-20 18:06:10 -05:00
committed by
Harshavardhana
parent
3adc311c1c
commit
18cb15559d
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user