From 6db7027e975029bc8c50fef958452d502620edea Mon Sep 17 00:00:00 2001 From: baude Date: Thu, 27 Sep 2018 12:45:01 -0500 Subject: Add buildah version and distribution to info For the sake of debug and problem reporting, we would benefit from knowing what buildah version was vendored into podman. Also, knowing the distribution and distribution version would also be handy. Signed-off-by: baude --- libpod/info.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'libpod/info.go') diff --git a/libpod/info.go b/libpod/info.go index 3add1ce0f..4cbf3f734 100644 --- a/libpod/info.go +++ b/libpod/info.go @@ -1,8 +1,10 @@ package libpod import ( + "bufio" "bytes" "fmt" + "github.com/containers/buildah" "io/ioutil" "os" "runtime" @@ -39,6 +41,7 @@ func (r *Runtime) hostInfo() (map[string]interface{}, error) { info["SwapFree"] = mi.SwapFree conmonVersion, _ := r.GetConmonVersion() ociruntimeVersion, _ := r.GetOCIRuntimeVersion() + hostDistributionInfo := r.GetHostDistributionInfo() info["Conmon"] = map[string]interface{}{ "path": r.conmonPath, "package": r.ociRuntime.conmonPackage(), @@ -49,7 +52,12 @@ func (r *Runtime) hostInfo() (map[string]interface{}, error) { "package": r.ociRuntime.pathPackage(), "version": ociruntimeVersion, } + info["Distribution"] = map[string]interface{}{ + "distribution": hostDistributionInfo["Distribution"], + "version": hostDistributionInfo["Version"], + } + info["BuildahVersion"] = buildah.Version kv, err := readKernelVersion() if err != nil { return nil, errors.Wrapf(err, "error reading kernel version") @@ -178,3 +186,30 @@ func (r *Runtime) GetOCIRuntimeVersion() (string, error) { } return strings.TrimSuffix(output, "\n"), nil } + +// GetHostDistributionInfo returns a map containing the host's distribution and version +func (r *Runtime) GetHostDistributionInfo() map[string]string { + dist := make(map[string]string) + + // Populate values in case we cannot find the values + // or the file + dist["Distribution"] = "unknown" + dist["Version"] = "unknown" + + f, err := os.Open("/etc/os-release") + if err != nil { + return dist + } + defer f.Close() + + l := bufio.NewScanner(f) + for l.Scan() { + if strings.HasPrefix(l.Text(), "ID=") { + dist["Distribution"] = strings.TrimPrefix(l.Text(), "ID=") + } + if strings.HasPrefix(l.Text(), "VERSION_ID=") { + dist["Version"] = strings.Trim(strings.TrimPrefix(l.Text(), "VERSION_ID="), "\"") + } + } + return dist +} -- cgit v1.2.3-54-g00ecf