summaryrefslogtreecommitdiff
path: root/cmd/podmanV2
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-03-19 16:50:15 -0500
committerBrent Baude <bbaude@redhat.com>2020-03-20 12:54:45 -0500
commit87293028e61d0c88c258ed9f4a82c4be7f0bc896 (patch)
treecd3c6f35eed940e41afed71e7f60f7a8abac1612 /cmd/podmanV2
parentccc30c606e843d5c98e2c62a3b393a61e60976b2 (diff)
downloadpodman-87293028e61d0c88c258ed9f4a82c4be7f0bc896.tar.gz
podman-87293028e61d0c88c258ed9f4a82c4be7f0bc896.tar.bz2
podman-87293028e61d0c88c258ed9f4a82c4be7f0bc896.zip
podmanv2 container exists|wait
enable container exists and wait for podmanv2 Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podmanV2')
-rw-r--r--cmd/podmanV2/containers/exists.go40
-rw-r--r--cmd/podmanV2/containers/inspect.go2
-rw-r--r--cmd/podmanV2/containers/wait.go68
-rw-r--r--cmd/podmanV2/images/inspect.go2
-rw-r--r--cmd/podmanV2/main.go13
-rw-r--r--cmd/podmanV2/registry/registry.go14
-rw-r--r--cmd/podmanV2/root.go3
7 files changed, 130 insertions, 12 deletions
diff --git a/cmd/podmanV2/containers/exists.go b/cmd/podmanV2/containers/exists.go
new file mode 100644
index 000000000..4f9e6c44a
--- /dev/null
+++ b/cmd/podmanV2/containers/exists.go
@@ -0,0 +1,40 @@
+package containers
+
+import (
+ "context"
+ "os"
+
+ "github.com/containers/libpod/cmd/podmanV2/registry"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/spf13/cobra"
+)
+
+var (
+ containerExistsCommand = &cobra.Command{
+ Use: "exists CONTAINER",
+ Short: "Check if a container exists in local storage",
+ Long: containerExistsDescription,
+ Example: `podman container exists containerID
+ podman container exists myctr || podman run --name myctr [etc...]`,
+ RunE: exists,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: containerExistsCommand,
+ Parent: containerCmd,
+ })
+}
+
+func exists(cmd *cobra.Command, args []string) error {
+ exists, err := registry.ContainerEngine().ContainerExists(context.Background(), args[0])
+ if err != nil {
+ return err
+ }
+ if !exists {
+ os.Exit(1)
+ }
+ return nil
+}
diff --git a/cmd/podmanV2/containers/inspect.go b/cmd/podmanV2/containers/inspect.go
index 635be4789..355924984 100644
--- a/cmd/podmanV2/containers/inspect.go
+++ b/cmd/podmanV2/containers/inspect.go
@@ -7,6 +7,8 @@ import (
)
var (
+ containerExistsDescription = `If the named container exists in local storage, podman container exists exits with 0, otherwise the exit code will be 1.`
+
// podman container _inspect_
inspectCmd = &cobra.Command{
Use: "inspect [flags] CONTAINER",
diff --git a/cmd/podmanV2/containers/wait.go b/cmd/podmanV2/containers/wait.go
new file mode 100644
index 000000000..d18064c3c
--- /dev/null
+++ b/cmd/podmanV2/containers/wait.go
@@ -0,0 +1,68 @@
+package containers
+
+import (
+ "context"
+ "fmt"
+ "time"
+
+ "github.com/containers/libpod/cmd/podmanV2/registry"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+var (
+ waitDescription = `Block until one or more containers stop and then print their exit codes.
+`
+ waitCommand = &cobra.Command{
+ Use: "wait [flags] CONTAINER [CONTAINER...]",
+ Short: "Block on one or more containers",
+ Long: waitDescription,
+ RunE: wait,
+ Example: `podman wait --latest
+ podman wait --interval 5000 ctrID
+ podman wait ctrID1 ctrID2`,
+ }
+)
+
+var waitFlags = entities.WaitOptions{}
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: waitCommand,
+ Parent: containerCmd,
+ })
+
+ waitCommand.SetHelpTemplate(registry.HelpTemplate())
+ waitCommand.SetUsageTemplate(registry.UsageTemplate())
+ flags := waitCommand.Flags()
+ flags.DurationVarP(&waitFlags.Interval, "interval", "i", time.Duration(250), "Milliseconds to wait before polling for completion")
+ flags.BoolVarP(&waitFlags.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
+ flags.StringVar(&waitFlags.Condition, "condition", "stopped", "Condition to wait on")
+}
+
+func wait(cmd *cobra.Command, args []string) error {
+ if waitFlags.Latest && len(args) > 0 {
+ return errors.New("cannot combine latest flag and arguments")
+ }
+ if waitFlags.Interval == 0 {
+ return errors.New("interval must be greater then 0")
+ }
+
+ responses, err := registry.ContainerEngine().ContainerWait(context.Background(), args, waitFlags)
+ if err != nil {
+ return err
+ }
+ for _, r := range responses {
+ if r.Error == nil {
+ fmt.Println(r.Id)
+ }
+ }
+ for _, r := range responses {
+ if r.Error != nil {
+ fmt.Println(err)
+ }
+ }
+ return nil
+}
diff --git a/cmd/podmanV2/images/inspect.go b/cmd/podmanV2/images/inspect.go
index 9c44cea35..2ecbbb201 100644
--- a/cmd/podmanV2/images/inspect.go
+++ b/cmd/podmanV2/images/inspect.go
@@ -52,7 +52,7 @@ func init() {
flags.BoolVarP(&inspectOpts.Size, "size", "s", false, "Display total file size")
flags.StringVarP(&inspectOpts.Format, "format", "f", "", "Change the output format to a Go template")
- if registry.GlobalFlags.EngineMode == entities.ABIMode {
+ if registry.EngineOpts.EngineMode == entities.ABIMode {
// TODO: This is the same as V1. We could skip creating the flag altogether in V2...
_ = flags.MarkHidden("latest")
}
diff --git a/cmd/podmanV2/main.go b/cmd/podmanV2/main.go
index 0df086352..24f21d804 100644
--- a/cmd/podmanV2/main.go
+++ b/cmd/podmanV2/main.go
@@ -5,6 +5,7 @@ import (
"os"
"reflect"
"runtime"
+ "strings"
_ "github.com/containers/libpod/cmd/podmanV2/containers"
_ "github.com/containers/libpod/cmd/podmanV2/images"
@@ -31,17 +32,19 @@ func initCobra() {
case "darwin":
fallthrough
case "windows":
- registry.GlobalFlags.EngineMode = entities.TunnelMode
+ registry.EngineOpts.EngineMode = entities.TunnelMode
case "linux":
- registry.GlobalFlags.EngineMode = entities.ABIMode
+ registry.EngineOpts.EngineMode = entities.ABIMode
default:
logrus.Errorf("%s is not a supported OS", runtime.GOOS)
os.Exit(1)
}
// TODO: Is there a Cobra way to "peek" at os.Args?
- if ok := Contains("--remote", os.Args); ok {
- registry.GlobalFlags.EngineMode = entities.TunnelMode
+ for _, v := range os.Args {
+ if strings.HasPrefix(v, "--remote") {
+ registry.EngineOpts.EngineMode = entities.TunnelMode
+ }
}
cobra.OnInitialize(func() {})
@@ -50,7 +53,7 @@ func initCobra() {
func main() {
fmt.Fprintf(os.Stderr, "Number of commands: %d\n", len(registry.Commands))
for _, c := range registry.Commands {
- if Contains(registry.GlobalFlags.EngineMode, c.Mode) {
+ if Contains(registry.EngineOpts.EngineMode, c.Mode) {
parent := rootCmd
if c.Parent != nil {
parent = c.Parent
diff --git a/cmd/podmanV2/registry/registry.go b/cmd/podmanV2/registry/registry.go
index fa51d6535..793d520a8 100644
--- a/cmd/podmanV2/registry/registry.go
+++ b/cmd/podmanV2/registry/registry.go
@@ -14,11 +14,13 @@ type CliCommand struct {
}
var (
- Commands []CliCommand
- GlobalFlags entities.EngineFlags
+ Commands []CliCommand
+
imageEngine entities.ImageEngine
containerEngine entities.ContainerEngine
- PodmanTunnel bool
+
+ EngineOpts entities.EngineOptions
+ GlobalFlags entities.EngineFlags
)
// HelpTemplate returns the help template for podman commands
@@ -63,7 +65,8 @@ func ImageEngine() entities.ImageEngine {
// NewImageEngine is a wrapper for building an ImageEngine to be used for PreRunE functions
func NewImageEngine(cmd *cobra.Command, args []string) (entities.ImageEngine, error) {
if imageEngine == nil {
- engine, err := infra.NewImageEngine(GlobalFlags.EngineMode, entities.EngineOptions{})
+ EngineOpts.FlagSet = cmd.Flags()
+ engine, err := infra.NewImageEngine(EngineOpts)
if err != nil {
return nil, err
}
@@ -79,7 +82,8 @@ func ContainerEngine() entities.ContainerEngine {
// NewContainerEngine is a wrapper for building an ContainerEngine to be used for PreRunE functions
func NewContainerEngine(cmd *cobra.Command, args []string) (entities.ContainerEngine, error) {
if containerEngine == nil {
- engine, err := infra.NewContainerEngine(GlobalFlags.EngineMode, entities.EngineOptions{})
+ EngineOpts.FlagSet = cmd.Flags()
+ engine, err := infra.NewContainerEngine(EngineOpts)
if err != nil {
return nil, err
}
diff --git a/cmd/podmanV2/root.go b/cmd/podmanV2/root.go
index 778184f28..92805ff30 100644
--- a/cmd/podmanV2/root.go
+++ b/cmd/podmanV2/root.go
@@ -24,7 +24,8 @@ func init() {
// Override default --help information of `--version` global flag}
var dummyVersion bool
rootCmd.PersistentFlags().BoolVarP(&dummyVersion, "version", "v", false, "Version of podman")
- rootCmd.PersistentFlags().BoolVarP(&registry.PodmanTunnel, "remote", "r", false, "Access service via SSH tunnel")
+ rootCmd.PersistentFlags().StringVarP(&registry.EngineOpts.Uri, "remote", "r", "", "URL to access podman service")
+ rootCmd.PersistentFlags().StringSliceVarP(&registry.EngineOpts.Identities, "identity", "i", []string{}, "path to SSH identity file")
}
func Execute() {