Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 59 additions & 29 deletions cmd/podman/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"fmt"
"html/template"
"os"
rt "runtime"
"strings"

Expand All @@ -11,7 +13,6 @@ import (
"github.com/containers/libpod/pkg/adapter"
"github.com/containers/libpod/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -49,42 +50,32 @@ func init() {
}

func infoCmd(c *cliconfig.InfoValues) error {
info := map[string]interface{}{}
remoteClientInfo := map[string]interface{}{}

runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.DeferredShutdown(false)

infoArr, err := runtime.Info()
i, err := runtime.Info()
if err != nil {
return errors.Wrapf(err, "error getting info")
}

info := infoWithExtra{Info: i}
if runtime.Remote {
endpoint, err := runtime.RemoteEndpoint()
if err != nil {
logrus.Errorf("Failed to obtain server connection: %s", err.Error())
} else {
remoteClientInfo["Connection"] = endpoint.Connection
remoteClientInfo["Connection Type"] = endpoint.Type.String()
return err
}

remoteClientInfo["RemoteAPI Version"] = version.RemoteAPIVersion
remoteClientInfo["Podman Version"] = version.Version
remoteClientInfo["OS Arch"] = fmt.Sprintf("%s/%s", rt.GOOS, rt.GOARCH)
infoArr = append(infoArr, define.InfoData{Type: "client", Data: remoteClientInfo})
info.Remote = getRemote(endpoint)
}

if !runtime.Remote && c.Debug {
debugInfo := debugInfo(c)
infoArr = append(infoArr, define.InfoData{Type: "debug", Data: debugInfo})
}

for _, currInfo := range infoArr {
info[currInfo.Type] = currInfo.Data
d, err := getDebug()
if err != nil {
return err
}
info.Debug = d
}

var out formats.Writer
Expand All @@ -98,19 +89,58 @@ func infoCmd(c *cliconfig.InfoValues) error {
case "":
out = formats.YAMLStruct{Output: info}
default:
out = formats.StdoutTemplate{Output: info, Template: infoOutputFormat}
tmpl, err := template.New("info").Parse(c.Format)
if err != nil {
return err
}
err = tmpl.Execute(os.Stdout, info)
return err
}

return out.Out()
}

// top-level "debug" info
func debugInfo(c *cliconfig.InfoValues) map[string]interface{} {
info := map[string]interface{}{}
info["compiler"] = rt.Compiler
info["go version"] = rt.Version()
info["podman version"] = version.Version
version, _ := define.GetVersion()
info["git commit"] = version.GitCommit
return info
func getDebug() (*debugInfo, error) {
v, err := define.GetVersion()
if err != nil {
return nil, err
}
return &debugInfo{
Compiler: rt.Compiler,
GoVersion: rt.Version(),
PodmanVersion: v.Version,
GitCommit: v.GitCommit,
}, nil
}

func getRemote(endpoint *adapter.Endpoint) *remoteInfo {
return &remoteInfo{
Connection: endpoint.Connection,
ConnectionType: endpoint.Type.String(),
RemoteAPIVersion: string(version.RemoteAPIVersion),
PodmanVersion: version.Version,
OSArch: fmt.Sprintf("%s/%s", rt.GOOS, rt.GOARCH),
}
}

type infoWithExtra struct {
*define.Info
Remote *remoteInfo `json:"remote,omitempty"`
Debug *debugInfo `json:"debug,omitempty"`
}

type remoteInfo struct {
Connection string `json:"connection"`
ConnectionType string `json:"connectionType"`
RemoteAPIVersion string `json:"remoteAPIVersion"`
PodmanVersion string `json:"podmanVersion"`
OSArch string `json:"OSArch"`
}

type debugInfo struct {
Compiler string `json:"compiler"`
GoVersion string `json:"goVersion"`
PodmanVersion string `json:"podmanVersion"`
GitCommit string `json:"gitCommit"`
}
2 changes: 1 addition & 1 deletion docs/source/markdown/podman-info.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Run podman info with JSON formatted response:
```
Run podman info and only get the registries information.
```
$ podman info --format={{".registries"}}
$ podman info --format={{".Registries"}}
map[registries:[docker.io quay.io registry.fedoraproject.org registry.access.redhat.com]]
```

Expand Down
101 changes: 101 additions & 0 deletions libpod/define/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package define

import "github.com/containers/storage/pkg/idtools"

// Info is the overall struct that describes the host system
// running libpod/podman
type Info struct {
Comment thread
baude marked this conversation as resolved.
Outdated
Host *HostInfo `json:"host"`
Store *StoreInfo `json:"store"`
Registries map[string]interface{} `json:"registries"`
}

//HostInfo describes the libpod host
type HostInfo struct {
Arch string `json:"arch"`
BuildahVersion string `json:"buildahVersion"`
CGroupsVersion string `json:"cgroupVersion"`
Conmon *ConmonInfo `json:"conmon"`
CPUs int `json:"cpus"`
Distribution DistributionInfo `json:"distribution"`
EventLogger string `json:"eventLogger"`
Hostname string `json:"hostname"`
IDMappings IDMappings `json:"idMappings,omitempty"`
Kernel string `json:"kernel"`
MemFree int64 `json:"memFree"`
MemTotal int64 `json:"memTotal"`
OCIRuntime *OCIRuntimeInfo `json:"ociRuntime"`
OS string `json:"os"`
Rootless bool `json:"rootless"`
RuntimeInfo map[string]interface{} `json:"runtimeInfo,omitempty"`
Slirp4NetNS SlirpInfo `json:"slirp4netns,omitempty"`
SwapFree int64 `json:"swapFree"`
SwapTotal int64 `json:"swapTotal"`
Uptime string `json:"uptime"`
}

// SlirpInfo describes the slirp exectuable that
// is being being used.
type SlirpInfo struct {
Executable string `json:"executable"`
Package string `json:"package"`
Version string `json:"version"`
}

// IDMappings describe the GID and UID mappings
type IDMappings struct {
GIDMap []idtools.IDMap `json:"gidmap"`
UIDMap []idtools.IDMap `json:"uidmap"`
}

// DistributionInfo describes the host distribution
// for libpod
type DistributionInfo struct {
Distribution string `json:"distribution"`
Version string `json:"version"`
}

// ConmonInfo describes the conmon executable being used
type ConmonInfo struct {
Package string `json:"package"`
Path string `json:"path"`
Version string `json:"version"`
}

// OCIRuntimeInfo describes the runtime (crun or runc) being
// used with podman
type OCIRuntimeInfo struct {
Name string `json:"name"`
Package string `json:"package"`
Path string `json:"path"`
Version string `json:"version"`
}

// StoreInfo describes the container storage and its
// attributes
type StoreInfo struct {
ConfigFile string `json:"configFile"`
ContainerStore ContainerStore `json:"containerStore"`
GraphDriverName string `json:"graphDriverName"`
GraphOptions map[string]interface{} `json:"graphOptions"`
GraphRoot string `json:"graphRoot"`
GraphStatus map[string]string `json:"graphStatus"`
ImageStore ImageStore `json:"imageStore"`
RunRoot string `json:"runRoot"`
VolumePath string `json:"volumePath"`
}

// ImageStore describes the image store. Right now only the number
// of images present
type ImageStore struct {
Number int `json:"number"`
}

// ContainerStore describes the quantity of containers in the
// store by status
type ContainerStore struct {
Number int `json:"number"`
Paused int `json:"paused"`
Running int `json:"running"`
Stopped int `json:"stopped"`
}
Loading