diff options
author | baude <bbaude@redhat.com> | 2019-04-28 09:12:59 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-05-01 09:13:18 -0500 |
commit | adbc41a3f73fc5b7dcfacb3438b4ede6609f24ee (patch) | |
tree | 47395fd6da0d6747ff196e32f349218f1e0a3694 /pkg/adapter/containers_remote.go | |
parent | eea77b5ae3e7fb8a60d438a79d3a4b30d35bb67c (diff) | |
download | podman-adbc41a3f73fc5b7dcfacb3438b4ede6609f24ee.tar.gz podman-adbc41a3f73fc5b7dcfacb3438b4ede6609f24ee.tar.bz2 podman-adbc41a3f73fc5b7dcfacb3438b4ede6609f24ee.zip |
podman-remote port
add the port command to the remote client. this allows users to displa
port information about their host system from the remote client
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/adapter/containers_remote.go')
-rw-r--r-- | pkg/adapter/containers_remote.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/adapter/containers_remote.go b/pkg/adapter/containers_remote.go index a3a48a564..f08c36e32 100644 --- a/pkg/adapter/containers_remote.go +++ b/pkg/adapter/containers_remote.go @@ -18,6 +18,7 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/inspect" "github.com/containers/libpod/pkg/varlinkapi/virtwriter" + "github.com/cri-o/ocicni/pkg/ocicni" "github.com/docker/docker/pkg/term" "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" @@ -63,6 +64,19 @@ func (c *Container) Unpause() error { return err } +func (c *Container) PortMappings() ([]ocicni.PortMapping, error) { + // First check if the container belongs to a network namespace (like a pod) + // Taken from libpod portmappings() + if len(c.config.NetNsCtr) > 0 { + netNsCtr, err := c.Runtime.LookupContainer(c.config.NetNsCtr) + if err != nil { + return nil, errors.Wrapf(err, "unable to lookup network namespace for container %s", c.ID()) + } + return netNsCtr.PortMappings() + } + return c.config.PortMappings, nil +} + // Config returns a container config func (r *LocalRuntime) Config(name string) *libpod.ContainerConfig { // TODO the Spec being returned is not populated. Matt and I could not figure out why. Will defer @@ -888,3 +902,23 @@ func (r *LocalRuntime) Prune(ctx context.Context, maxWorkers int, force bool) ([ func (r *LocalRuntime) CleanupContainers(ctx context.Context, cli *cliconfig.CleanupValues) ([]string, map[string]error, error) { return nil, nil, errors.New("container cleanup not supported for remote clients") } + +// Port displays port information about existing containers +func (r *LocalRuntime) Port(c *cliconfig.PortValues) ([]*Container, error) { + var ( + containers []*Container + err error + ) + // This one is a bit odd because when all is used, we only use running containers. + if !c.All { + containers, err = r.GetContainersByContext(false, c.Latest, c.InputArgs) + } else { + // we need to only use running containers if all + filters := []string{libpod.ContainerStateRunning.String()} + containers, err = r.LookupContainersWithStatus(filters) + } + if err != nil { + return nil, err + } + return containers, nil +} |