Skip to content

Commit 8d0fcd4

Browse files
Merge pull request #18383 from sstosh/info-networkbackend
libpod: Podman info output more network information
2 parents 38b8c17 + 6f82163 commit 8d0fcd4

File tree

8 files changed

+83
-105
lines changed

8 files changed

+83
-105
lines changed

docs/source/markdown/podman-info.1.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ host:
7777
logDriver: journald
7878
memFree: 1833385984
7979
memTotal: 16401895424
80+
networkBackend: cni
81+
networkBackendInfo:
82+
backend: cni
83+
dns:
84+
package: podman-plugins-3.4.4-1.fc34.x86_64
85+
path: /usr/libexec/cni/dnsname
86+
version: |-
87+
CNI dnsname plugin
88+
version: 1.3.1
89+
commit: unknown
90+
package: |-
91+
containernetworking-plugins-1.0.1-1.fc34.x86_64
92+
podman-plugins-3.4.4-1.fc34.x86_64
93+
path: /usr/libexec/cni
8094
ociRuntime:
8195
name: crun
8296
package: crun-1.0-1.fc34.x86_64
@@ -220,6 +234,17 @@ $ podman info --format json
220234
"logDriver": "journald",
221235
"memFree": 1785753600,
222236
"memTotal": 16401895424,
237+
"networkBackend": "cni",
238+
"networkBackendInfo": {
239+
"backend": "cni",
240+
"package": "containernetworking-plugins-1.0.1-1.fc34.x86_64\npodman-plugins-3.4.4-1.fc34.x86_64",
241+
"path": "/usr/libexec/cni",
242+
"dns": {
243+
"version": "CNI dnsname plugin\nversion: 1.3.1\ncommit: unknown",
244+
"package": "podman-plugins-3.4.4-1.fc34.x86_64",
245+
"path": "/usr/libexec/cni/dnsname"
246+
}
247+
},
223248
"ociRuntime": {
224249
"name": "crun",
225250
"package": "crun-1.0-1.fc34.x86_64",

libpod/define/info.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package define
22

33
import (
4+
"github.com/containers/common/libnetwork/types"
45
"github.com/containers/storage/pkg/idtools"
56
)
67

@@ -27,27 +28,28 @@ type SecurityInfo struct {
2728

2829
// HostInfo describes the libpod host
2930
type HostInfo struct {
30-
Arch string `json:"arch"`
31-
BuildahVersion string `json:"buildahVersion"`
32-
CgroupManager string `json:"cgroupManager"`
33-
CgroupsVersion string `json:"cgroupVersion"`
34-
CgroupControllers []string `json:"cgroupControllers"`
35-
Conmon *ConmonInfo `json:"conmon"`
36-
CPUs int `json:"cpus"`
37-
CPUUtilization *CPUUsage `json:"cpuUtilization"`
38-
DatabaseBackend string `json:"databaseBackend"`
39-
Distribution DistributionInfo `json:"distribution"`
40-
EventLogger string `json:"eventLogger"`
41-
FreeLocks *uint32 `json:"freeLocks,omitempty"`
42-
Hostname string `json:"hostname"`
43-
IDMappings IDMappings `json:"idMappings,omitempty"`
44-
Kernel string `json:"kernel"`
45-
LogDriver string `json:"logDriver"`
46-
MemFree int64 `json:"memFree"`
47-
MemTotal int64 `json:"memTotal"`
48-
NetworkBackend string `json:"networkBackend"`
49-
OCIRuntime *OCIRuntimeInfo `json:"ociRuntime"`
50-
OS string `json:"os"`
31+
Arch string `json:"arch"`
32+
BuildahVersion string `json:"buildahVersion"`
33+
CgroupManager string `json:"cgroupManager"`
34+
CgroupsVersion string `json:"cgroupVersion"`
35+
CgroupControllers []string `json:"cgroupControllers"`
36+
Conmon *ConmonInfo `json:"conmon"`
37+
CPUs int `json:"cpus"`
38+
CPUUtilization *CPUUsage `json:"cpuUtilization"`
39+
DatabaseBackend string `json:"databaseBackend"`
40+
Distribution DistributionInfo `json:"distribution"`
41+
EventLogger string `json:"eventLogger"`
42+
FreeLocks *uint32 `json:"freeLocks,omitempty"`
43+
Hostname string `json:"hostname"`
44+
IDMappings IDMappings `json:"idMappings,omitempty"`
45+
Kernel string `json:"kernel"`
46+
LogDriver string `json:"logDriver"`
47+
MemFree int64 `json:"memFree"`
48+
MemTotal int64 `json:"memTotal"`
49+
NetworkBackend string `json:"networkBackend"`
50+
NetworkBackendInfo types.NetworkInfo `json:"networkBackendInfo"`
51+
OCIRuntime *OCIRuntimeInfo `json:"ociRuntime"`
52+
OS string `json:"os"`
5153
// RemoteSocket returns the UNIX domain socket the Podman service is listening on
5254
RemoteSocket *RemoteSocket `json:"remoteSocket,omitempty"`
5355
RuntimeInfo map[string]interface{} `json:"runtimeInfo,omitempty"`

libpod/info.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/containers/buildah"
1616
"github.com/containers/buildah/pkg/util"
17+
cutil "github.com/containers/common/pkg/util"
1718
"github.com/containers/image/v5/pkg/sysregistriesv2"
1819
"github.com/containers/podman/v4/libpod/define"
1920
"github.com/containers/podman/v4/libpod/linkmode"
@@ -106,24 +107,25 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
106107
}
107108

108109
info := define.HostInfo{
109-
Arch: runtime.GOARCH,
110-
BuildahVersion: buildah.Version,
111-
DatabaseBackend: r.config.Engine.DBBackend,
112-
Linkmode: linkmode.Linkmode(),
113-
CPUs: runtime.NumCPU(),
114-
CPUUtilization: cpuUtil,
115-
Distribution: hostDistributionInfo,
116-
FreeLocks: locksFree,
117-
LogDriver: r.config.Containers.LogDriver,
118-
EventLogger: r.eventer.String(),
119-
Hostname: host,
120-
Kernel: kv,
121-
MemFree: mi.MemFree,
122-
MemTotal: mi.MemTotal,
123-
NetworkBackend: r.config.Network.NetworkBackend,
124-
OS: runtime.GOOS,
125-
SwapFree: mi.SwapFree,
126-
SwapTotal: mi.SwapTotal,
110+
Arch: runtime.GOARCH,
111+
BuildahVersion: buildah.Version,
112+
DatabaseBackend: r.config.Engine.DBBackend,
113+
Linkmode: linkmode.Linkmode(),
114+
CPUs: runtime.NumCPU(),
115+
CPUUtilization: cpuUtil,
116+
Distribution: hostDistributionInfo,
117+
LogDriver: r.config.Containers.LogDriver,
118+
EventLogger: r.eventer.String(),
119+
FreeLocks: locksFree,
120+
Hostname: host,
121+
Kernel: kv,
122+
MemFree: mi.MemFree,
123+
MemTotal: mi.MemTotal,
124+
NetworkBackend: r.config.Network.NetworkBackend,
125+
NetworkBackendInfo: r.network.NetworkInfo(),
126+
OS: runtime.GOOS,
127+
SwapFree: mi.SwapFree,
128+
SwapTotal: mi.SwapTotal,
127129
}
128130
if err := r.setPlatformHostInfo(&info); err != nil {
129131
return nil, err
@@ -241,14 +243,14 @@ func (r *Runtime) storeInfo() (*define.StoreInfo, error) {
241243
for _, o := range r.store.GraphOptions() {
242244
split := strings.SplitN(o, "=", 2)
243245
if strings.HasSuffix(split[0], "mount_program") {
244-
version, err := programVersion(split[1])
246+
version, err := cutil.ProgramVersion(split[1])
245247
if err != nil {
246248
logrus.Warnf("Failed to retrieve program version for %s: %v", split[1], err)
247249
}
248250
program := map[string]interface{}{}
249251
program["Executable"] = split[1]
250252
program["Version"] = version
251-
program["Package"] = packageVersion(split[1])
253+
program["Package"] = cutil.PackageVersion(split[1])
252254
graphOptions[split[0]] = program
253255
} else {
254256
graphOptions[split[0]] = split[1]

libpod/info_linux.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/containers/common/pkg/apparmor"
1212
"github.com/containers/common/pkg/cgroups"
1313
"github.com/containers/common/pkg/seccomp"
14+
"github.com/containers/common/pkg/util"
1415
"github.com/containers/podman/v4/libpod/define"
1516
"github.com/containers/podman/v4/pkg/rootless"
1617
"github.com/opencontainers/selinux/go-selinux"
@@ -59,27 +60,27 @@ func (r *Runtime) setPlatformHostInfo(info *define.HostInfo) error {
5960
slirp4netnsPath, _ = r.config.FindHelperBinary(slirp4netnsBinaryName, true)
6061
}
6162
if slirp4netnsPath != "" {
62-
version, err := programVersion(slirp4netnsPath)
63+
version, err := util.ProgramVersion(slirp4netnsPath)
6364
if err != nil {
6465
logrus.Warnf("Failed to retrieve program version for %s: %v", slirp4netnsPath, err)
6566
}
6667
program := define.SlirpInfo{
6768
Executable: slirp4netnsPath,
68-
Package: packageVersion(slirp4netnsPath),
69+
Package: util.PackageVersion(slirp4netnsPath),
6970
Version: version,
7071
}
7172
info.Slirp4NetNS = program
7273
}
7374

7475
pastaPath, _ := r.config.FindHelperBinary(pastaBinaryName, true)
7576
if pastaPath != "" {
76-
version, err := programVersion(pastaPath)
77+
version, err := util.ProgramVersion(pastaPath)
7778
if err != nil {
7879
logrus.Warnf("Failed to retrieve program version for %s: %v", pastaPath, err)
7980
}
8081
program := define.PastaInfo{
8182
Executable: pastaPath,
82-
Package: packageVersion(pastaPath),
83+
Package: util.PackageVersion(pastaPath),
8384
Version: version,
8485
}
8586
info.Pasta = program

libpod/oci_conmon_common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,8 @@ func (r *ConmonOCIRuntime) ExitFilePath(ctr *Container) (string, error) {
945945

946946
// RuntimeInfo provides information on the runtime.
947947
func (r *ConmonOCIRuntime) RuntimeInfo() (*define.ConmonInfo, *define.OCIRuntimeInfo, error) {
948-
runtimePackage := packageVersion(r.path)
949-
conmonPackage := packageVersion(r.conmonPath)
948+
runtimePackage := cutil.PackageVersion(r.path)
949+
conmonPackage := cutil.PackageVersion(r.conmonPath)
950950
runtimeVersion, err := r.getOCIRuntimeVersion()
951951
if err != nil {
952952
return nil, nil, fmt.Errorf("getting version of OCI runtime %s: %w", r.name, err)

libpod/util.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io"
88
"net/http"
99
"os"
10-
"os/exec"
1110
"path/filepath"
1211
"sort"
1312
"strings"
@@ -16,18 +15,12 @@ import (
1615
"github.com/containers/common/libnetwork/types"
1716
"github.com/containers/common/pkg/config"
1817
"github.com/containers/podman/v4/libpod/define"
19-
"github.com/containers/podman/v4/utils"
2018
"github.com/fsnotify/fsnotify"
2119
spec "github.com/opencontainers/runtime-spec/specs-go"
2220
"github.com/opencontainers/selinux/go-selinux/label"
2321
"github.com/sirupsen/logrus"
2422
)
2523

26-
// Runtime API constants
27-
const (
28-
unknownPackage = "Unknown"
29-
)
30-
3124
// FuncTimer helps measure the execution time of a function
3225
// For debug purposes, do not leave in code
3326
// used like defer FuncTimer("foo")
@@ -145,57 +138,6 @@ func JSONDeepCopy(from, to interface{}) error {
145138
return json.Unmarshal(tmp, to)
146139
}
147140

148-
func queryPackageVersion(cmdArg ...string) string {
149-
output := unknownPackage
150-
if 1 < len(cmdArg) {
151-
cmd := exec.Command(cmdArg[0], cmdArg[1:]...)
152-
if outp, err := cmd.Output(); err == nil {
153-
output = string(outp)
154-
if cmdArg[0] == "/usr/bin/dpkg" {
155-
r := strings.Split(output, ": ")
156-
queryFormat := `${Package}_${Version}_${Architecture}`
157-
cmd = exec.Command("/usr/bin/dpkg-query", "-f", queryFormat, "-W", r[0])
158-
if outp, err := cmd.Output(); err == nil {
159-
output = string(outp)
160-
}
161-
}
162-
}
163-
if cmdArg[0] == "/sbin/apk" {
164-
prefix := cmdArg[len(cmdArg)-1] + " is owned by "
165-
output = strings.Replace(output, prefix, "", 1)
166-
}
167-
}
168-
return strings.Trim(output, "\n")
169-
}
170-
171-
func packageVersion(program string) string { // program is full path
172-
packagers := [][]string{
173-
{"/usr/bin/rpm", "-q", "-f"},
174-
{"/usr/bin/dpkg", "-S"}, // Debian, Ubuntu
175-
{"/usr/bin/pacman", "-Qo"}, // Arch
176-
{"/usr/bin/qfile", "-qv"}, // Gentoo (quick)
177-
{"/usr/bin/equery", "b"}, // Gentoo (slow)
178-
{"/sbin/apk", "info", "-W"}, // Alpine
179-
{"/usr/local/sbin/pkg", "which", "-q"}, // FreeBSD
180-
}
181-
182-
for _, cmd := range packagers {
183-
cmd = append(cmd, program)
184-
if out := queryPackageVersion(cmd...); out != unknownPackage {
185-
return out
186-
}
187-
}
188-
return unknownPackage
189-
}
190-
191-
func programVersion(mountProgram string) (string, error) {
192-
output, err := utils.ExecCmd(mountProgram, "--version")
193-
if err != nil {
194-
return "", err
195-
}
196-
return strings.TrimSuffix(output, "\n"), nil
197-
}
198-
199141
// DefaultSeccompPath returns the path to the default seccomp.json file
200142
// if it exists, first it checks OverrideSeccomp and then default.
201143
// If neither exist function returns ""

test/e2e/info_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ var _ = Describe("Podman Info", func() {
160160
session.WaitWithDefaultTimeout()
161161
Expect(session).To(Exit(0))
162162
Expect(session.OutputToString()).To(Equal(want))
163+
164+
session = podmanTest.Podman([]string{"info", "--format", "{{.Host.NetworkBackendInfo.Backend}}"})
165+
session.WaitWithDefaultTimeout()
166+
Expect(session).To(Exit(0))
167+
Expect(session.OutputToString()).To(Equal(want))
163168
})
164169

165170
It("Podman info: check desired database backend", func() {

test/system/005-info.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ host.conmon.path | $expr_path
4242
host.conmon.package | .*conmon.*
4343
host.cgroupManager | \\\(systemd\\\|cgroupfs\\\)
4444
host.cgroupVersion | v[12]
45+
host.networkBackendInfo | .*dns.*package.*
4546
host.ociRuntime.path | $expr_path
4647
host.pasta | .*executable.*package.*
4748
store.configFile | $expr_path

0 commit comments

Comments
 (0)