diff options
author | Sujil02 <sushah@redhat.com> | 2020-03-31 00:53:50 -0400 |
---|---|---|
committer | Sujil02 <sushah@redhat.com> | 2020-04-01 15:10:49 -0400 |
commit | 7cbc09971a4d7322a6b29d86ef1d1fcb71f68f04 (patch) | |
tree | b8d482db0ee3f9d119ef208bae7ed03332aa0455 /cmd | |
parent | 0a163720351710be314c729086e8d288680ff0a8 (diff) | |
download | podman-7cbc09971a4d7322a6b29d86ef1d1fcb71f68f04.tar.gz podman-7cbc09971a4d7322a6b29d86ef1d1fcb71f68f04.tar.bz2 podman-7cbc09971a4d7322a6b29d86ef1d1fcb71f68f04.zip |
podmanv2 pod inspect
Add the ability to inspect pod in podmanv2
Signed-off-by: Sujil02 <sushah@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podmanV2/pods/inspect.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/cmd/podmanV2/pods/inspect.go b/cmd/podmanV2/pods/inspect.go new file mode 100644 index 000000000..9aab610f2 --- /dev/null +++ b/cmd/podmanV2/pods/inspect.go @@ -0,0 +1,64 @@ +package pods + +import ( + "context" + "fmt" + + "github.com/containers/libpod/cmd/podmanV2/registry" + "github.com/containers/libpod/pkg/domain/entities" + jsoniter "github.com/json-iterator/go" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +var ( + inspectOptions = entities.PodInspectOptions{} +) + +var ( + inspectDescription = fmt.Sprintf(`Display the configuration for a pod by name or id + + By default, this will render all results in a JSON array.`) + + inspectCmd = &cobra.Command{ + Use: "inspect [flags] POD [POD...]", + Short: "Displays a pod configuration", + Long: inspectDescription, + RunE: inspect, + Example: `podman pod inspect podID`, + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: inspectCmd, + Parent: podCmd, + }) + flags := inspectCmd.Flags() + flags.BoolVarP(&inspectOptions.Latest, "latest", "l", false, "Act on the latest pod podman is aware of") + if registry.IsRemote() { + _ = flags.MarkHidden("latest") + } +} + +func inspect(cmd *cobra.Command, args []string) error { + + if len(args) < 1 && !inspectOptions.Latest { + return errors.Errorf("you must provide the name or id of a running pod") + } + + if !inspectOptions.Latest { + inspectOptions.NameOrID = args[0] + } + responses, err := registry.ContainerEngine().PodInspect(context.Background(), inspectOptions) + if err != nil { + return err + } + b, err := jsoniter.MarshalIndent(responses, "", " ") + if err != nil { + return err + } + fmt.Println(string(b)) + return nil +} |