summaryrefslogtreecommitdiff
path: root/pkg/varlinkapi/system.go
blob: a64dc4217e9a733b49560a9689b12a3e5cb694ac (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package varlinkapi

import (
	goruntime "runtime"
	"strings"
	"time"

	"github.com/containers/libpod/cmd/podman/varlink"
	"github.com/containers/libpod/libpod"
)

// GetVersion ...
func (i *LibpodAPI) GetVersion(call iopodman.VarlinkCall) error {
	versionInfo, err := libpod.GetVersion()
	if err != nil {
		return err
	}

	return call.ReplyGetVersion(iopodman.Version{
		Remote_api_version: versionInfo.RemoteAPIVersion,
		Version:            versionInfo.Version,
		Go_version:         versionInfo.GoVersion,
		Git_commit:         versionInfo.GitCommit,
		Built:              time.Unix(versionInfo.Built, 0).Format(time.RFC3339),
		Os_arch:            versionInfo.OsArch,
	})
}

// GetInfo returns details about the podman host and its stores
func (i *LibpodAPI) GetInfo(call iopodman.VarlinkCall) error {
	versionInfo, err := libpod.GetVersion()
	if err != nil {
		return err
	}
	var (
		registries, insecureRegistries []string
	)
	podmanInfo := iopodman.PodmanInfo{}
	info, err := i.Runtime.Info()
	if err != nil {
		return call.ReplyErrorOccurred(err.Error())
	}

	host := info[0].Data
	distribution := iopodman.InfoDistribution{
		Distribution: host["Distribution"].(map[string]interface{})["distribution"].(string),
		Version:      host["Distribution"].(map[string]interface{})["version"].(string),
	}
	infoHost := iopodman.InfoHost{
		Buildah_version: host["BuildahVersion"].(string),
		Distribution:    distribution,
		Mem_free:        host["MemFree"].(int64),
		Mem_total:       host["MemTotal"].(int64),
		Swap_free:       host["SwapFree"].(int64),
		Arch:            host["arch"].(string),
		Cpus:            int64(host["cpus"].(int)),
		Hostname:        host["hostname"].(string),
		Kernel:          host["kernel"].(string),
		Os:              host["os"].(string),
		Uptime:          host["uptime"].(string),
	}
	podmanInfo.Host = infoHost
	store := info[1].Data
	pmaninfo := iopodman.InfoPodmanBinary{
		Compiler:       goruntime.Compiler,
		Go_version:     goruntime.Version(),
		Podman_version: versionInfo.Version,
		Git_commit:     versionInfo.GitCommit,
	}

	graphStatus := iopodman.InfoGraphStatus{
		Backing_filesystem:  store["GraphStatus"].(map[string]string)["Backing Filesystem"],
		Native_overlay_diff: store["GraphStatus"].(map[string]string)["Native Overlay Diff"],
		Supports_d_type:     store["GraphStatus"].(map[string]string)["Supports d_type"],
	}
	infoStore := iopodman.InfoStore{
		Graph_driver_name:    store["GraphDriverName"].(string),
		Containers:           int64(store["ContainerStore"].(map[string]interface{})["number"].(int)),
		Images:               int64(store["ImageStore"].(map[string]interface{})["number"].(int)),
		Run_root:             store["RunRoot"].(string),
		Graph_root:           store["GraphRoot"].(string),
		Graph_driver_options: strings.Join(store["GraphOptions"].([]string), ", "),
		Graph_status:         graphStatus,
	}

	registriesInterface := info[2].Data["registries"]
	insecureRegistriesInterface := info[3].Data["registries"]
	if registriesInterface != nil {
		registries = registriesInterface.([]string)
	}
	if insecureRegistriesInterface != nil {
		insecureRegistries = insecureRegistriesInterface.([]string)
	}

	podmanInfo.Store = infoStore
	podmanInfo.Podman = pmaninfo
	podmanInfo.Registries = registries
	podmanInfo.Insecure_registries = insecureRegistries
	return call.ReplyGetInfo(podmanInfo)
}