Merge pull request #2402 from baude/remotepodinspect

podman-remote pod inspect|exists
This commit is contained in:
OpenShift Merge Robot
2019-02-22 21:12:49 +01:00
committed by GitHub
9 changed files with 125 additions and 15 deletions

21
API.md
View File

@ -89,12 +89,16 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
[func ListPods() ListPodData](#ListPods)
[func LoadImage(name: string, inputFile: string, quiet: bool, deleteFile: bool) MoreResponse](#LoadImage)
[func MountContainer(name: string) string](#MountContainer)
[func PauseContainer(name: string) string](#PauseContainer)
[func PausePod(name: string) string](#PausePod)
[func PodStateData(name: string) string](#PodStateData)
[func PullImage(name: string, certDir: string, creds: string, signaturePolicy: string, tlsVerify: ) MoreResponse](#PullImage)
[func PushImage(name: string, tag: string, tlsverify: , signaturePolicy: string, creds: string, certDir: string, compress: bool, format: string, removeSignatures: bool, signBy: string) MoreResponse](#PushImage)
@ -535,7 +539,9 @@ $ varlink call unix:/run/podman/io.podman/io.podman.GetPodStats '{"name": "7f62b
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method GetPodsByContext(all: [bool](https://godoc.org/builtin#bool), latest: [bool](https://godoc.org/builtin#bool), args: [[]string](#[]string)) [[]string](#[]string)</div>
GetPodsByContext allows you to get a list pod ids depending on all, latest, or a list of
pod names. The definition of latest pod means the latest by creation date. In a multi-
user environment, results might differ from what you expect.
### <a name="GetVersion"></a>func GetVersion
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
@ -571,7 +577,7 @@ $ varlink call -m unix:/run/podman/io.podman/io.podman.ImageExists '{"name": "im
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method ImageSave(options: [ImageSaveOptions](#ImageSaveOptions)) [MoreResponse](#MoreResponse)</div>
ImageSave allows you to save an image from the local image storage to a tarball
### <a name="ImagesPrune"></a>func ImagesPrune
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
@ -732,6 +738,11 @@ $ varlink call -m unix:/run/podman/io.podman/io.podman.ListPods
]
}
~~~
### <a name="LoadImage"></a>func LoadImage
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method LoadImage(name: [string](https://godoc.org/builtin#string), inputFile: [string](https://godoc.org/builtin#string), quiet: [bool](https://godoc.org/builtin#bool), deleteFile: [bool](https://godoc.org/builtin#bool)) [MoreResponse](#MoreResponse)</div>
LoadImage allows you to load an image into local storage from a tarball.
### <a name="MountContainer"></a>func MountContainer
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
@ -768,6 +779,12 @@ $ varlink call -m unix:/run/podman/io.podman/io.podman.PausePod '{"name": "fooba
"pod": "1840835294cf076a822e4e12ba4152411f131bd869e7f6a4e8b16df9b0ea5c7f"
}
~~~
### <a name="PodStateData"></a>func PodStateData
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method PodStateData(name: [string](https://godoc.org/builtin#string)) [string](https://godoc.org/builtin#string)</div>
PodStateData returns inspectr level information of a given pod in string form. This call is for
development of Podman only and generally should not be used.
### <a name="PullImage"></a>func PullImage
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">

View File

@ -92,8 +92,6 @@ func getContainerSubCommands() []*cobra.Command {
func getPodSubCommands() []*cobra.Command {
return []*cobra.Command{
_podCreateCommand,
_podExistsCommand,
_podInspectCommand,
_podKillCommand,
_podPauseCommand,
_podPsCommand,

View File

@ -5,7 +5,6 @@ import (
"github.com/spf13/cobra"
"os"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/adapter"
"github.com/containers/libpod/libpod/image"
@ -124,14 +123,14 @@ func podExistsCmd(c *cliconfig.PodExistsValues) error {
if len(args) > 1 || len(args) < 1 {
return errors.New("you may only check for the existence of one pod at a time")
}
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
if _, err := runtime.LookupPod(args[0]); err != nil {
if errors.Cause(err) == libpod.ErrNoSuchPod {
if errors.Cause(err) == libpod.ErrNoSuchPod || err.Error() == "io.podman.PodNotFound" {
os.Exit(1)
}
return err

View File

@ -20,6 +20,8 @@ var podCommand = cliconfig.PodmanCommand{
//podSubCommands are implemented both in local and remote clients
var podSubCommands = []*cobra.Command{
_podExistsCommand,
_podInspectCommand,
_podRmCommand,
}

View File

@ -5,8 +5,7 @@ import (
"fmt"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -37,13 +36,13 @@ func init() {
func podInspectCmd(c *cliconfig.PodInspectValues) error {
var (
pod *libpod.Pod
pod *adapter.Pod
)
if err := checkMutuallyExclusiveFlags(&c.PodmanCommand); err != nil {
return err
}
args := c.InputArgs
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}

View File

@ -1082,6 +1082,10 @@ method ContainerInspectData(name: string) -> (config: string)
# development of Podman only and generally should not be used.
method ContainerStateData(name: string) -> (config: string)
# PodStateData returns inspectr level information of a given pod in string form. This call is for
# development of Podman only and generally should not be used.
method PodStateData(name: string) -> (config: string)
# Sendfile allows a remote client to send a file to the host
method SendFile(type: string, length: int) -> (file_handle: string)
@ -1100,11 +1104,15 @@ method GetVolumes(args: []string, all: bool) -> (volumes: []Volume)
# VolumesPrune removes unused volumes on the host
method VolumesPrune() -> (prunedNames: []string, prunedErrors: []string)
# ImageSave allows you to save an image from the local image storage to a tarball
method ImageSave(options: ImageSaveOptions) -> (reply: MoreResponse)
# GetPodsByContext allows you to get a list pod ids depending on all, latest, or a list of
# pod names. The definition of latest pod means the latest by creation date. In a multi-
# user environment, results might differ from what you expect.
method GetPodsByContext(all: bool, latest: bool, args: []string) -> (pods: []string)
# LoadImage allows you to load an image into local storage from a tarball.
method LoadImage(name: string, inputFile: string, quiet: bool, deleteFile: bool) -> (reply: MoreResponse)
# ImageNotFound means the image could not be found by the provided name or ID in local storage.

View File

@ -36,3 +36,19 @@ func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValue
}
return podids, errs
}
// GetLatestPod gets the latest pod and wraps it in an adapter pod
func (r *LocalRuntime) GetLatestPod() (*Pod, error) {
pod := Pod{}
p, err := r.Runtime.GetLatestPod()
pod.Pod = p
return &pod, err
}
// LookupPod gets a pod by name or id and wraps it in an adapter pod
func (r *LocalRuntime) LookupPod(nameOrID string) (*Pod, error) {
pod := Pod{}
p, err := r.Runtime.LookupPod(nameOrID)
pod.Pod = p
return &pod, err
}

View File

@ -4,10 +4,13 @@ package adapter
import (
"context"
"encoding/json"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/varlink"
"github.com/containers/libpod/libpod"
"github.com/pkg/errors"
"github.com/ulule/deepcopier"
)
// Pod ...
@ -16,11 +19,13 @@ type Pod struct {
}
type remotepod struct {
config *libpod.PodConfig
state *libpod.PodInspectState
Runtime *LocalRuntime
config *libpod.PodConfig
state *libpod.PodInspectState
containers []libpod.PodContainerInfo
Runtime *LocalRuntime
}
// RemovePods removes one or more based on the cli context.
func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValues) ([]string, []error) {
var (
rmErrs []error
@ -42,3 +47,52 @@ func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValue
}
return rmPods, rmErrs
}
// Inspect looks up a pod by name or id and embeds its data into a remote pod
// object.
func (r *LocalRuntime) Inspect(nameOrID string) (*Pod, error) {
reply, err := iopodman.PodStateData().Call(r.Conn, nameOrID)
if err != nil {
return nil, err
}
data := libpod.PodInspect{}
if err := json.Unmarshal([]byte(reply), &data); err != nil {
return nil, err
}
pod := Pod{}
pod.Runtime = r
pod.config = data.Config
pod.state = data.State
pod.containers = data.Containers
return &pod, nil
}
// GetLatestPod gets the latest pod and wraps it in an adapter pod
func (r *LocalRuntime) GetLatestPod() (*Pod, error) {
reply, err := iopodman.GetPodsByContext().Call(r.Conn, false, true, nil)
if err != nil {
return nil, err
}
if len(reply) > 0 {
return r.Inspect(reply[0])
}
return nil, errors.New("no pods exist")
}
// LookupPod gets a pod by name or ID and wraps it in an adapter pod
func (r *LocalRuntime) LookupPod(nameOrID string) (*Pod, error) {
return r.Inspect(nameOrID)
}
// Inspect, like libpod pod inspect, returns a libpod.PodInspect object from
// the data of a remotepod data struct
func (p *Pod) Inspect() (*libpod.PodInspect, error) {
config := new(libpod.PodConfig)
deepcopier.Copy(p.remotepod.config).To(config)
inspectData := libpod.PodInspect{
Config: config,
State: p.remotepod.state,
Containers: p.containers,
}
return &inspectData, nil
}

View File

@ -286,3 +286,20 @@ func (i *LibpodAPI) GetPodsByContext(call iopodman.VarlinkCall, all, latest bool
}
return call.ReplyGetPodsByContext(podids)
}
// PodStateData returns a container's state data in string format
func (i *LibpodAPI) PodStateData(call iopodman.VarlinkCall, name string) error {
pod, err := i.Runtime.LookupPod(name)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
data, err := pod.Inspect()
if err != nil {
return call.ReplyErrorOccurred("unable to obtain pod state")
}
b, err := json.Marshal(data)
if err != nil {
return call.ReplyErrorOccurred("unable to serialize pod inspect data")
}
return call.ReplyPodStateData(string(b))
}