diff options
author | Brent Baude <bbaude@redhat.com> | 2020-06-03 14:52:01 -0500 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2020-06-03 15:20:37 -0500 |
commit | d023909c0be103f1b02f2ddac0b937fff2d4e4f0 (patch) | |
tree | 52073a9a6bef47b47f7cf30afca1f73e0b3a8e20 | |
parent | bba0a8be1a715fb0903ffc69abd5700a624d47e4 (diff) | |
download | podman-d023909c0be103f1b02f2ddac0b937fff2d4e4f0.tar.gz podman-d023909c0be103f1b02f2ddac0b937fff2d4e4f0.tar.bz2 podman-d023909c0be103f1b02f2ddac0b937fff2d4e4f0.zip |
add socket information to podman info
this is step 1 to self-discovery of remote ssh connections. we add a remotesocket struct to info to detect what the socket path might be.
Co-authored-by: Jhon Honce <jhonce@redhat.com>
Signed-off-by: Brent Baude <bbaude@redhat.com>
-rw-r--r-- | docs/source/markdown/podman-info.1.md | 7 | ||||
-rw-r--r-- | libpod/define/info.go | 7 | ||||
-rw-r--r-- | pkg/domain/infra/abi/system.go | 33 |
3 files changed, 46 insertions, 1 deletions
diff --git a/docs/source/markdown/podman-info.1.md b/docs/source/markdown/podman-info.1.md index 24ab97c91..19dd61c15 100644 --- a/docs/source/markdown/podman-info.1.md +++ b/docs/source/markdown/podman-info.1.md @@ -71,6 +71,9 @@ host: commit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 spec: 1.0.1-dev os: linux + remoteSocket: + exists: false + path: /run/user/1000/podman/podman.sock rootless: true slirp4netns: executable: /bin/slirp4netns @@ -179,6 +182,10 @@ Run podman info with JSON formatted response: "version": "runc version 1.0.0-rc8+dev\ncommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657\nspec: 1.0.1-dev" }, "os": "linux", + "remoteSocket": { + "path": "/run/user/1000/podman/podman.sock", + "exists": false + }, "rootless": true, "slirp4netns": { "executable": "/bin/slirp4netns", diff --git a/libpod/define/info.go b/libpod/define/info.go index 906aa523f..f136936f7 100644 --- a/libpod/define/info.go +++ b/libpod/define/info.go @@ -27,6 +27,7 @@ type HostInfo struct { MemTotal int64 `json:"memTotal"` OCIRuntime *OCIRuntimeInfo `json:"ociRuntime"` OS string `json:"os"` + RemoteSocket *RemoteSocket `json:"remoteSocket,omitempty"` Rootless bool `json:"rootless"` RuntimeInfo map[string]interface{} `json:"runtimeInfo,omitempty"` Slirp4NetNS SlirpInfo `json:"slirp4netns,omitempty"` @@ -36,6 +37,12 @@ type HostInfo struct { Linkmode string `json:"linkmode"` } +// RemoteSocket describes information about the API socket +type RemoteSocket struct { + Path string `json:"path,omitempty"` + Exists bool `json:"exists,omitempty"` +} + // SlirpInfo describes the slirp exectuable that // is being being used. type SlirpInfo struct { diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index 52dfaba7d..9b538b301 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -25,7 +25,38 @@ import ( ) func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) { - return ic.Libpod.Info() + info, err := ic.Libpod.Info() + if err != nil { + return nil, err + } + xdg, err := util.GetRuntimeDir() + if err != nil { + return nil, err + } + if len(xdg) == 0 { + // If no xdg is returned, assume root socket + xdg = "/run" + } + + // Glue the socket path together + socketPath := filepath.Join(xdg, "podman", "podman.sock") + rs := define.RemoteSocket{ + Path: socketPath, + Exists: false, + } + + // Check if the socket exists + if fi, err := os.Stat(socketPath); err == nil { + if fi.Mode()&os.ModeSocket != 0 { + rs.Exists = true + } + } + // TODO + // it was suggested future versions of this could perform + // a ping on the socket for greater confidence the socket is + // actually active. + info.Host.RemoteSocket = &rs + return info, err } func (ic *ContainerEngine) SetupRootless(_ context.Context, cmd *cobra.Command) error { |