summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-11-19 13:13:51 +0100
committerGitHub <noreply@github.com>2019-11-19 13:13:51 +0100
commitf3f219a67c3a9297b5e1f0505c583b9de35661c8 (patch)
tree069f51f6a50d5234e6bc16f2045656aaefb9b313 /cmd/podman
parent741b90c2b95c533f2ee5669ae1d3b2a93c8129ce (diff)
parent061bf77588c573668646fb07ded748c9bf375130 (diff)
downloadpodman-f3f219a67c3a9297b5e1f0505c583b9de35661c8.tar.gz
podman-f3f219a67c3a9297b5e1f0505c583b9de35661c8.tar.bz2
podman-f3f219a67c3a9297b5e1f0505c583b9de35661c8.zip
Merge pull request #4523 from vrothberg/systemd-improvements
podman rm/stop --cidfile
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/checkpoint.go2
-rw-r--r--cmd/podman/cleanup.go2
-rw-r--r--cmd/podman/cliconfig/config.go18
-rw-r--r--cmd/podman/common.go37
-rw-r--r--cmd/podman/init.go2
-rw-r--r--cmd/podman/kill.go2
-rw-r--r--cmd/podman/mount.go2
-rw-r--r--cmd/podman/pod_kill.go2
-rw-r--r--cmd/podman/pod_pause.go2
-rw-r--r--cmd/podman/pod_restart.go2
-rw-r--r--cmd/podman/pod_rm.go2
-rw-r--r--cmd/podman/pod_start.go2
-rw-r--r--cmd/podman/pod_stop.go2
-rw-r--r--cmd/podman/pod_unpause.go2
-rw-r--r--cmd/podman/port.go2
-rw-r--r--cmd/podman/restart.go2
-rw-r--r--cmd/podman/restore.go2
-rw-r--r--cmd/podman/rm.go8
-rw-r--r--cmd/podman/stop.go4
-rw-r--r--cmd/podman/umount.go2
20 files changed, 63 insertions, 36 deletions
diff --git a/cmd/podman/checkpoint.go b/cmd/podman/checkpoint.go
index 22cdb1f39..07db519f8 100644
--- a/cmd/podman/checkpoint.go
+++ b/cmd/podman/checkpoint.go
@@ -26,7 +26,7 @@ var (
return checkpointCmd(&checkpointCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman container checkpoint --keep ctrID
podman container checkpoint --all
diff --git a/cmd/podman/cleanup.go b/cmd/podman/cleanup.go
index c00654162..a8bc0c116 100644
--- a/cmd/podman/cleanup.go
+++ b/cmd/podman/cleanup.go
@@ -27,7 +27,7 @@ var (
return cleanupCmd(&cleanupCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman container cleanup --latest
podman container cleanup ctrID1 ctrID2 ctrID3
diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go
index 780b68333..541b2e05d 100644
--- a/cmd/podman/cliconfig/config.go
+++ b/cmd/podman/cliconfig/config.go
@@ -480,11 +480,12 @@ type RestoreValues struct {
type RmValues struct {
PodmanCommand
- All bool
- Force bool
- Latest bool
- Storage bool
- Volumes bool
+ All bool
+ Force bool
+ Latest bool
+ Storage bool
+ Volumes bool
+ CIDFiles []string
}
type RmiValues struct {
@@ -557,9 +558,10 @@ type StatsValues struct {
type StopValues struct {
PodmanCommand
- All bool
- Latest bool
- Timeout uint
+ All bool
+ Latest bool
+ Timeout uint
+ CIDFiles []string
}
type TopValues struct {
diff --git a/cmd/podman/common.go b/cmd/podman/common.go
index 4db043f31..442823d2d 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -39,24 +39,45 @@ func shortID(id string) string {
return id
}
-// checkAllAndLatest checks that --all and --latest are used correctly
-func checkAllAndLatest(c *cobra.Command, args []string, ignoreArgLen bool) error {
+// checkAllLatestAndCIDFile checks that --all and --latest are used correctly.
+// If cidfile is set, also check for the --cidfile flag.
+func checkAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool, cidfile bool) error {
argLen := len(args)
if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
- return errors.New("unable to lookup values for 'latest' or 'all'")
+ if !cidfile {
+ return errors.New("unable to lookup values for 'latest' or 'all'")
+ } else if c.Flags().Lookup("cidfile") == nil {
+ return errors.New("unable to lookup values for 'latest', 'all' or 'cidfile'")
+ }
+ }
+
+ specifiedAll, _ := c.Flags().GetBool("all")
+ specifiedLatest, _ := c.Flags().GetBool("latest")
+ specifiedCIDFile := false
+ if cid, _ := c.Flags().GetStringArray("cidfile"); len(cid) > 0 {
+ specifiedCIDFile = true
}
- all, _ := c.Flags().GetBool("all")
- latest, _ := c.Flags().GetBool("latest")
- if all && latest {
+
+ if specifiedCIDFile && (specifiedAll || specifiedLatest) {
+ return errors.Errorf("--all, --latest and --cidfile cannot be used together")
+ } else if specifiedAll && specifiedLatest {
return errors.Errorf("--all and --latest cannot be used together")
}
+
if ignoreArgLen {
return nil
}
- if (all || latest) && argLen > 0 {
+ if (argLen > 0) && (specifiedAll || specifiedLatest) {
return errors.Errorf("no arguments are needed with --all or --latest")
+ } else if cidfile && (argLen > 0) && (specifiedAll || specifiedLatest || specifiedCIDFile) {
+ return errors.Errorf("no arguments are needed with --all, --latest or --cidfile")
}
- if argLen < 1 && !all && !latest {
+
+ if specifiedCIDFile {
+ return nil
+ }
+
+ if argLen < 1 && !specifiedAll && !specifiedLatest && !specifiedCIDFile {
return errors.Errorf("you must provide at least one name or id")
}
return nil
diff --git a/cmd/podman/init.go b/cmd/podman/init.go
index 3f97824fc..2e0b33828 100644
--- a/cmd/podman/init.go
+++ b/cmd/podman/init.go
@@ -23,7 +23,7 @@ var (
return initCmd(&initCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman init --latest
podman init 3c45ef19d893
diff --git a/cmd/podman/kill.go b/cmd/podman/kill.go
index d5056d86d..aba2008ca 100644
--- a/cmd/podman/kill.go
+++ b/cmd/podman/kill.go
@@ -24,7 +24,7 @@ var (
return killCmd(&killCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman kill mywebserver
podman kill 860a4b23
diff --git a/cmd/podman/mount.go b/cmd/podman/mount.go
index b14827592..526a236fd 100644
--- a/cmd/podman/mount.go
+++ b/cmd/podman/mount.go
@@ -35,7 +35,7 @@ var (
return mountCmd(&mountCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, true)
+ return checkAllLatestAndCIDFile(cmd, args, true, false)
},
}
)
diff --git a/cmd/podman/pod_kill.go b/cmd/podman/pod_kill.go
index 9bda77471..064946f72 100644
--- a/cmd/podman/pod_kill.go
+++ b/cmd/podman/pod_kill.go
@@ -28,7 +28,7 @@ var (
return podKillCmd(&podKillCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman pod kill podID
podman pod kill --signal TERM mywebserver
diff --git a/cmd/podman/pod_pause.go b/cmd/podman/pod_pause.go
index 45e1319ff..320072919 100644
--- a/cmd/podman/pod_pause.go
+++ b/cmd/podman/pod_pause.go
@@ -25,7 +25,7 @@ var (
return podPauseCmd(&podPauseCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman pod pause podID1 podID2
podman pod pause --latest
diff --git a/cmd/podman/pod_restart.go b/cmd/podman/pod_restart.go
index cc090bd6e..cb9f3770f 100644
--- a/cmd/podman/pod_restart.go
+++ b/cmd/podman/pod_restart.go
@@ -26,7 +26,7 @@ var (
return podRestartCmd(&podRestartCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman pod restart podID1 podID2
podman pod restart --latest
diff --git a/cmd/podman/pod_rm.go b/cmd/podman/pod_rm.go
index 82d0eb977..86d6d2f27 100644
--- a/cmd/podman/pod_rm.go
+++ b/cmd/podman/pod_rm.go
@@ -26,7 +26,7 @@ var (
return podRmCmd(&podRmCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman pod rm mywebserverpod
podman pod rm -f 860a4b23
diff --git a/cmd/podman/pod_start.go b/cmd/podman/pod_start.go
index 64c951b43..aa2e09e98 100644
--- a/cmd/podman/pod_start.go
+++ b/cmd/podman/pod_start.go
@@ -26,7 +26,7 @@ var (
return podStartCmd(&podStartCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman pod start podID
podman pod start --latest
diff --git a/cmd/podman/pod_stop.go b/cmd/podman/pod_stop.go
index edda99550..579e4f1d3 100644
--- a/cmd/podman/pod_stop.go
+++ b/cmd/podman/pod_stop.go
@@ -27,7 +27,7 @@ var (
return podStopCmd(&podStopCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman pod stop mywebserverpod
podman pod stop --latest
diff --git a/cmd/podman/pod_unpause.go b/cmd/podman/pod_unpause.go
index 833434c3f..1f80a7c79 100644
--- a/cmd/podman/pod_unpause.go
+++ b/cmd/podman/pod_unpause.go
@@ -26,7 +26,7 @@ var (
return podUnpauseCmd(&podUnpauseCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman pod unpause podID1 podID2
podman pod unpause --all
diff --git a/cmd/podman/port.go b/cmd/podman/port.go
index 4e1f9642c..eef3d4b1d 100644
--- a/cmd/podman/port.go
+++ b/cmd/podman/port.go
@@ -26,7 +26,7 @@ var (
return portCmd(&portCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, true)
+ return checkAllLatestAndCIDFile(cmd, args, true, false)
},
Example: `podman port --all
podman port ctrID 80/tcp
diff --git a/cmd/podman/restart.go b/cmd/podman/restart.go
index c97fb0dc1..996a9f7ce 100644
--- a/cmd/podman/restart.go
+++ b/cmd/podman/restart.go
@@ -23,7 +23,7 @@ var (
return restartCmd(&restartCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman restart ctrID
podman restart --latest
diff --git a/cmd/podman/restore.go b/cmd/podman/restore.go
index caefadb6d..a8db7fa94 100644
--- a/cmd/podman/restore.go
+++ b/cmd/podman/restore.go
@@ -26,7 +26,7 @@ var (
return restoreCmd(&restoreCommand, cmd)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, true)
+ return checkAllLatestAndCIDFile(cmd, args, true, false)
},
Example: `podman container restore ctrID
podman container restore --latest
diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go
index 6329a9d8e..b3bc8e1b9 100644
--- a/cmd/podman/rm.go
+++ b/cmd/podman/rm.go
@@ -25,7 +25,7 @@ var (
return rmCmd(&rmCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, true)
},
Example: `podman rm imageID
podman rm mywebserver myflaskserver 860a4b23
@@ -44,8 +44,10 @@ func init() {
flags.BoolVarP(&rmCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&rmCommand.Storage, "storage", false, "Remove container from storage library")
flags.BoolVarP(&rmCommand.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container")
+ flags.StringArrayVarP(&rmCommand.CIDFiles, "cidfile", "", nil, "Read the container ID from the file")
markFlagHiddenForRemoteClient("storage", flags)
markFlagHiddenForRemoteClient("latest", flags)
+ markFlagHiddenForRemoteClient("cidfile", flags)
}
// rmCmd removes one or more containers
@@ -58,8 +60,8 @@ func rmCmd(c *cliconfig.RmValues) error {
// Storage conflicts with --all/--latest/--volumes
if c.Storage {
- if c.All || c.Latest || c.Volumes {
- return errors.Errorf("--storage conflicts with --volumes, --all, and --latest")
+ if c.All || c.Latest || c.Volumes || c.CIDFiles != nil {
+ return errors.Errorf("--storage conflicts with --volumes, --all, --latest and --cidfile")
}
}
diff --git a/cmd/podman/stop.go b/cmd/podman/stop.go
index e04d8a12b..acecb298e 100644
--- a/cmd/podman/stop.go
+++ b/cmd/podman/stop.go
@@ -25,7 +25,7 @@ var (
return stopCmd(&stopCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, true)
},
Example: `podman stop ctrID
podman stop --latest
@@ -42,7 +42,9 @@ func init() {
flags.BoolVarP(&stopCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.UintVar(&stopCommand.Timeout, "time", define.CtrRemoveTimeout, "Seconds to wait for stop before killing the container")
flags.UintVarP(&stopCommand.Timeout, "timeout", "t", define.CtrRemoveTimeout, "Seconds to wait for stop before killing the container")
+ flags.StringArrayVarP(&stopCommand.CIDFiles, "cidfile", "", nil, "Read the container ID from the file")
markFlagHiddenForRemoteClient("latest", flags)
+ markFlagHiddenForRemoteClient("cidfile", flags)
}
// stopCmd stops a container or containers
diff --git a/cmd/podman/umount.go b/cmd/podman/umount.go
index c3d81d3a8..6ad485c2c 100644
--- a/cmd/podman/umount.go
+++ b/cmd/podman/umount.go
@@ -28,7 +28,7 @@ var (
return umountCmd(&umountCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
- return checkAllAndLatest(cmd, args, false)
+ return checkAllLatestAndCIDFile(cmd, args, false, false)
},
Example: `podman umount ctrID
podman umount ctrID1 ctrID2 ctrID3