summaryrefslogtreecommitdiff
path: root/cmd/podman/pods
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pods')
-rw-r--r--cmd/podman/pods/common.go23
-rw-r--r--cmd/podman/pods/rm.go24
-rw-r--r--cmd/podman/pods/start.go21
-rw-r--r--cmd/podman/pods/stop.go34
4 files changed, 82 insertions, 20 deletions
diff --git a/cmd/podman/pods/common.go b/cmd/podman/pods/common.go
new file mode 100644
index 000000000..1c4195095
--- /dev/null
+++ b/cmd/podman/pods/common.go
@@ -0,0 +1,23 @@
+package pods
+
+import (
+ "io/ioutil"
+ "strings"
+
+ "github.com/pkg/errors"
+)
+
+// readPodIDFiles reads the specified files and returns their content (i.e.,
+// first line).
+func readPodIDFiles(files []string) ([]string, error) {
+ ids := []string{}
+ for _, podFile := range files {
+ content, err := ioutil.ReadFile(podFile)
+ if err != nil {
+ return nil, errors.Wrap(err, "error reading pod ID file")
+ }
+ id := strings.Split(string(content), "\n")[0]
+ ids = append(ids, id)
+ }
+ return ids, nil
+}
diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go
index 4b9882f8a..ecceda32a 100644
--- a/cmd/podman/pods/rm.go
+++ b/cmd/podman/pods/rm.go
@@ -11,7 +11,15 @@ import (
"github.com/spf13/cobra"
)
+// allows for splitting API and CLI-only options
+type podRmOptionsWrapper struct {
+ entities.PodRmOptions
+
+ PodIDFiles []string
+}
+
var (
+ rmOptions = podRmOptionsWrapper{}
podRmDescription = fmt.Sprintf(`podman rm will remove one or more stopped pods and their containers from the host.
The pod name or ID can be used. A pod with containers will not be removed without --force. If --force is specified, all containers will be stopped, then removed.`)
@@ -21,7 +29,7 @@ var (
Long: podRmDescription,
RunE: rm,
Args: func(cmd *cobra.Command, args []string) error {
- return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
+ return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true)
},
Example: `podman pod rm mywebserverpod
podman pod rm -f 860a4b23
@@ -29,10 +37,6 @@ var (
}
)
-var (
- rmOptions = entities.PodRmOptions{}
-)
-
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
@@ -45,6 +49,7 @@ func init() {
flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Force removal of a running pod by first stopping all containers, then removing all containers in the pod. The default is false")
flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing")
flags.BoolVarP(&rmOptions.Latest, "latest", "l", false, "Remove the latest pod podman is aware of")
+ flags.StringArrayVarP(&rmOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore")
@@ -55,7 +60,14 @@ func rm(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
)
- responses, err := registry.ContainerEngine().PodRm(context.Background(), args, rmOptions)
+
+ ids, err := readPodIDFiles(rmOptions.PodIDFiles)
+ if err != nil {
+ return err
+ }
+ args = append(args, ids...)
+
+ responses, err := registry.ContainerEngine().PodRm(context.Background(), args, rmOptions.PodRmOptions)
if err != nil {
return err
}
diff --git a/cmd/podman/pods/start.go b/cmd/podman/pods/start.go
index d0150a3c2..86517190d 100644
--- a/cmd/podman/pods/start.go
+++ b/cmd/podman/pods/start.go
@@ -11,6 +11,13 @@ import (
"github.com/spf13/cobra"
)
+// allows for splitting API and CLI-only options
+type podStartOptionsWrapper struct {
+ entities.PodStartOptions
+
+ PodIDFiles []string
+}
+
var (
podStartDescription = `The pod name or ID can be used.
@@ -21,7 +28,7 @@ var (
Long: podStartDescription,
RunE: start,
Args: func(cmd *cobra.Command, args []string) error {
- return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
+ return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true)
},
Example: `podman pod start podID
podman pod start --latest
@@ -30,7 +37,7 @@ var (
)
var (
- startOptions = entities.PodStartOptions{}
+ startOptions = podStartOptionsWrapper{}
)
func init() {
@@ -43,6 +50,7 @@ func init() {
flags := startCommand.Flags()
flags.BoolVarP(&startOptions.All, "all", "a", false, "Restart all running pods")
flags.BoolVarP(&startOptions.Latest, "latest", "l", false, "Restart the latest pod podman is aware of")
+ flags.StringArrayVarP(&startOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
@@ -52,7 +60,14 @@ func start(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
)
- responses, err := registry.ContainerEngine().PodStart(context.Background(), args, startOptions)
+
+ ids, err := readPodIDFiles(startOptions.PodIDFiles)
+ if err != nil {
+ return err
+ }
+ args = append(args, ids...)
+
+ responses, err := registry.ContainerEngine().PodStart(context.Background(), args, startOptions.PodStartOptions)
if err != nil {
return err
}
diff --git a/cmd/podman/pods/stop.go b/cmd/podman/pods/stop.go
index daf05d640..fd66488f9 100644
--- a/cmd/podman/pods/stop.go
+++ b/cmd/podman/pods/stop.go
@@ -11,7 +11,18 @@ import (
"github.com/spf13/cobra"
)
+// allows for splitting API and CLI-only options
+type podStopOptionsWrapper struct {
+ entities.PodStopOptions
+
+ PodIDFiles []string
+ TimeoutCLI uint
+}
+
var (
+ stopOptions = podStopOptionsWrapper{
+ PodStopOptions: entities.PodStopOptions{Timeout: -1},
+ }
podStopDescription = `The pod name or ID can be used.
This command will stop all running containers in each of the specified pods.`
@@ -22,7 +33,7 @@ var (
Long: podStopDescription,
RunE: stop,
Args: func(cmd *cobra.Command, args []string) error {
- return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
+ return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true)
},
Example: `podman pod stop mywebserverpod
podman pod stop --latest
@@ -30,13 +41,6 @@ var (
}
)
-var (
- stopOptions = entities.PodStopOptions{
- Timeout: -1,
- }
- timeout uint
-)
-
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
@@ -47,7 +51,8 @@ func init() {
flags.BoolVarP(&stopOptions.All, "all", "a", false, "Stop all running pods")
flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing")
flags.BoolVarP(&stopOptions.Latest, "latest", "l", false, "Stop the latest pod podman is aware of")
- flags.UintVarP(&timeout, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for pod stop before killing the container")
+ flags.UintVarP(&stopOptions.TimeoutCLI, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for pod stop before killing the container")
+ flags.StringArrayVarP(&stopOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore")
@@ -60,9 +65,16 @@ func stop(cmd *cobra.Command, args []string) error {
errs utils.OutputErrors
)
if cmd.Flag("time").Changed {
- stopOptions.Timeout = int(timeout)
+ stopOptions.Timeout = int(stopOptions.TimeoutCLI)
+ }
+
+ ids, err := readPodIDFiles(stopOptions.PodIDFiles)
+ if err != nil {
+ return err
}
- responses, err := registry.ContainerEngine().PodStop(context.Background(), args, stopOptions)
+ args = append(args, ids...)
+
+ responses, err := registry.ContainerEngine().PodStop(context.Background(), args, stopOptions.PodStopOptions)
if err != nil {
return err
}