This repository was archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathinfo.go
58 lines (48 loc) · 1.61 KB
/
info.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
package client
import (
"fmt"
"strings"
"github.com/docker/go-units"
gflag "github.com/jessevdk/go-flags"
)
// we need this *info* function to get the whole status from the hyper daemon
func (cli *HyperClient) HyperCmdInfo(args ...string) error {
var parser = gflag.NewParser(nil, gflag.Default)
parser.Usage = "info\n\nDisplay system-wide information"
args, err := parser.ParseArgs(args)
if err != nil {
if !strings.Contains(err.Error(), "Usage") {
return err
} else {
return nil
}
}
remoteInfo, err := cli.client.Info()
if err != nil {
return err
}
fmt.Fprintf(cli.out, "Images: %d\n", remoteInfo.GetInt("Images"))
if remoteInfo.Exists("Containers") {
fmt.Fprintf(cli.out, "Containers: %d\n", remoteInfo.GetInt("Containers"))
}
fmt.Fprintf(cli.out, "PODs: %d\n", remoteInfo.GetInt("Pods"))
fmt.Fprintf(cli.out, "Storage Driver: %s\n", remoteInfo.Get("Driver"))
var status [][]string
err = remoteInfo.GetJson("DriverStatus", &status)
if err == nil {
for _, pair := range status {
fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
}
}
fmt.Fprintf(cli.out, "Hyper Root Dir: %s\n", remoteInfo.Get("DockerRootDir"))
fmt.Fprintf(cli.out, "Index Server Address: %s\n", remoteInfo.Get("IndexServerAddress"))
fmt.Fprintf(cli.out, "Execution Driver: %s\n", remoteInfo.Get("ExecutionDriver"))
memTotal := getMemSizeString(remoteInfo.GetInt("MemTotal"))
fmt.Fprintf(cli.out, "Total Memory: %s\n", memTotal)
fmt.Fprintf(cli.out, "Operating System: %s\n", remoteInfo.Get("Operating System"))
return nil
}
func getMemSizeString(s int) string {
rtn := float64(s)
return units.HumanSize(rtn)
}