2017-10-31 22:03:54 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
2018-09-05 20:31:10 +00:00
|
|
|
// DashboardResp represents a dashboard received from the API
|
|
|
|
type DashboardResp struct {
|
|
|
|
Dashboard Dashboard
|
2017-10-31 22:03:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 20:31:10 +00:00
|
|
|
// Dashboard represents a dashboard
|
|
|
|
type Dashboard struct {
|
2017-10-31 22:03:54 +00:00
|
|
|
VolumesCount int `json:"volumes_count"`
|
|
|
|
RunningServersCount int `json:"running_servers_count"`
|
|
|
|
ImagesCount int `json:"images_count"`
|
|
|
|
SnapshotsCount int `json:"snapshots_count"`
|
|
|
|
ServersCount int `json:"servers_count"`
|
|
|
|
IPsCount int `json:"ips_count"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDashboard returns the dashboard
|
2018-09-05 20:31:10 +00:00
|
|
|
func (s *API) GetDashboard() (*Dashboard, error) {
|
2017-10-31 22:03:54 +00:00
|
|
|
resp, err := s.GetResponsePaginate(s.computeAPI, "dashboard", url.Values{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := s.handleHTTPError([]int{http.StatusOK}, resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-09-05 20:31:10 +00:00
|
|
|
var dashboard DashboardResp
|
2017-10-31 22:03:54 +00:00
|
|
|
|
|
|
|
if err = json.Unmarshal(body, &dashboard); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &dashboard.Dashboard, nil
|
|
|
|
}
|