summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorTomSweeneyRedHat <tsweeney@redhat.com>2018-06-27 13:34:10 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-06-29 15:01:21 +0000
commit41bd607c120dbd8b315eb30feb0fe63e079c821d (patch)
tree4fd1d8ca408b7190023e52839bad48dfe42e9662 /cmd
parent3a90b5224df686e6efbf78e6b6cbb5333115ea82 (diff)
downloadpodman-41bd607c120dbd8b315eb30feb0fe63e079c821d.tar.gz
podman-41bd607c120dbd8b315eb30feb0fe63e079c821d.tar.bz2
podman-41bd607c120dbd8b315eb30feb0fe63e079c821d.zip
Allow multiple containers and all for umount
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com> Closes: #1012 Approved by: rhatdan
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/umount.go78
1 files changed, 69 insertions, 9 deletions
diff --git a/cmd/podman/umount.go b/cmd/podman/umount.go
index 803cf034a..0fd7ff144 100644
--- a/cmd/podman/umount.go
+++ b/cmd/podman/umount.go
@@ -1,17 +1,29 @@
package main
import (
+ "fmt"
+
"github.com/pkg/errors"
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
+ "github.com/projectatomic/libpod/libpod"
+ "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var (
+ umountFlags = []cli.Flag{
+ cli.BoolFlag{
+ Name: "all, a",
+ Usage: "umount all of the currently mounted containers",
+ },
+ }
+
umountCommand = cli.Command{
Name: "umount",
Aliases: []string{"unmount"},
- Usage: "Unmount a working container's root filesystem",
- Description: "Unmounts a working container's root filesystem",
+ Usage: "Unmounts working container's root filesystem",
+ Description: "Unmounts working container's root filesystem",
+ Flags: umountFlags,
Action: umountCmd,
ArgsUsage: "CONTAINER-NAME-OR-ID",
}
@@ -24,18 +36,66 @@ func umountCmd(c *cli.Context) error {
}
defer runtime.Shutdown(false)
+ umountAll := c.Bool("all")
args := c.Args()
- if len(args) == 0 {
+ if len(args) == 0 && !umountAll {
return errors.Errorf("container ID must be specified")
}
- if len(args) > 1 {
- return errors.Errorf("too many arguments specified")
+ if len(args) > 0 && umountAll {
+ return errors.Errorf("when using the --all switch, you may not pass any container IDs")
}
- ctr, err := runtime.LookupContainer(args[0])
- if err != nil {
- return errors.Wrapf(err, "error looking up container %q", args[0])
+ umountContainerErrStr := "error unmounting container"
+ var lastError error
+ if len(args) > 0 {
+ for _, name := range args {
+ ctr, err := runtime.LookupContainer(name)
+ if err != nil {
+ if lastError != nil {
+ logrus.Error(lastError)
+ }
+ lastError = errors.Wrapf(err, "%s %s", umountContainerErrStr, name)
+ continue
+ }
+
+ if err = unmountContainer(ctr); err != nil {
+ if lastError != nil {
+ logrus.Error(lastError)
+ }
+ lastError = errors.Wrapf(err, "%s %s", umountContainerErrStr, name)
+ continue
+ }
+ fmt.Printf("%s\n", ctr.ID())
+ }
+ } else {
+ containers, err := runtime.GetContainers()
+ if err != nil {
+ return errors.Wrapf(err, "error reading Containers")
+ }
+ for _, ctr := range containers {
+ ctrState, err := ctr.State()
+ if ctrState == libpod.ContainerStateRunning || err != nil {
+ continue
+ }
+
+ if err = unmountContainer(ctr); err != nil {
+ if lastError != nil {
+ logrus.Error(lastError)
+ }
+ lastError = errors.Wrapf(err, "%s %s", umountContainerErrStr, ctr.ID())
+ continue
+ }
+ fmt.Printf("%s\n", ctr.ID())
+ }
}
+ return lastError
+}
- return ctr.Unmount()
+func unmountContainer(ctr *libpod.Container) error {
+ if mounted, err := ctr.Mounted(); mounted {
+ return ctr.Unmount()
+ } else {
+ return err
+ }
+ return errors.Errorf("container is not mounted")
}