forked from canonical/lxd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
59 lines (44 loc) · 1.17 KB
/
resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"net/http"
"github.com/gorilla/mux"
"github.com/lxc/lxd/lxd/util"
"github.com/lxc/lxd/shared/api"
)
// /1.0/resources
// Get system resources
func serverResourcesGet(d *Daemon, r *http.Request) Response {
res := api.Resources{}
cpu, err := util.CPUResource()
if err != nil {
return SmartError(err)
}
mem, err := util.MemoryResource()
if err != nil {
return SmartError(err)
}
res.CPU = *cpu
res.Memory = *mem
return SyncResponse(true, res)
}
var serverResourceCmd = Command{name: "resources", get: serverResourcesGet}
// /1.0/storage-pools/{name}/resources
// Get resources for a specific storage pool
func storagePoolResourcesGet(d *Daemon, r *http.Request) Response {
poolName := mux.Vars(r)["name"]
// Get the existing storage pool.
s, err := storagePoolInit(d.State(), poolName)
if err != nil {
return InternalError(err)
}
err = s.StoragePoolCheck()
if err != nil {
return InternalError(err)
}
res, err := s.StoragePoolResources()
if err != nil {
return InternalError(err)
}
return SyncResponse(true, &res)
}
var storagePoolResourcesCmd = Command{name: "storage-pools/{name}/resources", get: storagePoolResourcesGet}