Merge pull request #2165 from rhatdan/mount

Add --latest and --all to podman mount/umount
This commit is contained in:
OpenShift Merge Robot
2019-01-17 00:09:29 +01:00
committed by GitHub
6 changed files with 69 additions and 60 deletions

View File

@ -24,13 +24,18 @@ var (
mountFlags = []cli.Flag{ mountFlags = []cli.Flag{
cli.BoolFlag{ cli.BoolFlag{
Name: "notruncate", Name: "all, a",
Usage: "do not truncate output", Usage: "Mount all containers",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "format", Name: "format",
Usage: "Change the output format to Go template", Usage: "Change the output format to Go template",
}, },
cli.BoolFlag{
Name: "notruncate",
Usage: "do not truncate output",
},
LatestFlag,
} }
mountCommand = cli.Command{ mountCommand = cli.Command{
Name: "mount", Name: "mount",
@ -80,20 +85,31 @@ func mountCmd(c *cli.Context) error {
} }
} }
if c.Bool("all") && c.Bool("latest") {
return errors.Errorf("--all and --latest cannot be used together")
}
mountContainers, err := getAllOrLatestContainers(c, runtime, -1, "all")
if err != nil {
if len(mountContainers) == 0 {
return err
}
fmt.Println(err.Error())
}
formats := map[string]bool{ formats := map[string]bool{
"": true, "": true,
of.JSONString: true, of.JSONString: true,
} }
args := c.Args()
json := c.String("format") == of.JSONString json := c.String("format") == of.JSONString
if !formats[c.String("format")] { if !formats[c.String("format")] {
return errors.Errorf("%q is not a supported format", c.String("format")) return errors.Errorf("%q is not a supported format", c.String("format"))
} }
var lastError error var lastError error
if len(args) > 0 { if len(mountContainers) > 0 {
for _, name := range args { for _, ctr := range mountContainers {
if json { if json {
if lastError != nil { if lastError != nil {
logrus.Error(lastError) logrus.Error(lastError)
@ -101,14 +117,6 @@ func mountCmd(c *cli.Context) error {
lastError = errors.Wrapf(err, "json option cannot be used with a container id") lastError = errors.Wrapf(err, "json option cannot be used with a container id")
continue continue
} }
ctr, err := runtime.LookupContainer(name)
if err != nil {
if lastError != nil {
logrus.Error(lastError)
}
lastError = errors.Wrapf(err, "error looking up container %q", name)
continue
}
mountPoint, err := ctr.Mount() mountPoint, err := ctr.Mount()
if err != nil { if err != nil {
if lastError != nil { if lastError != nil {

View File

@ -21,6 +21,7 @@ var (
Name: "force, f", Name: "force, f",
Usage: "force the complete umount all of the currently mounted containers", Usage: "force the complete umount all of the currently mounted containers",
}, },
LatestFlag,
} }
description = ` description = `
@ -51,41 +52,20 @@ func umountCmd(c *cli.Context) error {
force := c.Bool("force") force := c.Bool("force")
umountAll := c.Bool("all") umountAll := c.Bool("all")
args := c.Args() if err := checkAllAndLatest(c); err != nil {
if len(args) == 0 && !umountAll { return err
return errors.Errorf("container ID must be specified")
} }
if len(args) > 0 && umountAll {
return errors.Errorf("when using the --all switch, you may not pass any container IDs") containers, err := getAllOrLatestContainers(c, runtime, -1, "all")
if err != nil {
if len(containers) == 0 {
return err
}
fmt.Println(err.Error())
} }
umountContainerErrStr := "error unmounting container" umountContainerErrStr := "error unmounting container"
var lastError error 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 = ctr.Unmount(force); 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 { for _, ctr := range containers {
ctrState, err := ctr.State() ctrState, err := ctr.State()
if ctrState == libpod.ContainerStateRunning || err != nil { if ctrState == libpod.ContainerStateRunning || err != nil {
@ -104,6 +84,5 @@ func umountCmd(c *cli.Context) error {
} }
fmt.Printf("%s\n", ctr.ID()) fmt.Printf("%s\n", ctr.ID())
} }
}
return lastError return lastError
} }

View File

@ -1514,6 +1514,8 @@ _podman_umount() {
-h -h
--force --force
-f -f
--latest
-l
" "
local options_with_args=" local options_with_args="
" "
@ -1531,8 +1533,12 @@ _podman_umount() {
_podman_mount() { _podman_mount() {
local boolean_options=" local boolean_options="
--all
-a
--help --help
-h -h
-l
--latest
--notruncate --notruncate
" "

View File

@ -19,10 +19,20 @@ returned.
## OPTIONS ## OPTIONS
**--all, a**
Mount all containers.
**--format** **--format**
Print the mounted containers in specified format (json) Print the mounted containers in specified format (json)
**--latest, -l**
Instead of providing the container name or ID, use the last created container.
If you use methods other than Podman to run containers such as CRI-O, the last
started container could be from either of those methods.
**--notruncate** **--notruncate**
Do not truncate IDs in output. Do not truncate IDs in output.

View File

@ -11,14 +11,14 @@ podman\-rm - Remove one or more containers
## OPTIONS ## OPTIONS
**--force, f**
Force the removal of a running and paused containers
**--all, a** **--all, a**
Remove all containers. Can be used in conjunction with -f as well. Remove all containers. Can be used in conjunction with -f as well.
**--force, f**
Force the removal of a running and paused containers
**--latest, -l** **--latest, -l**
Instead of providing the container name or ID, use the last created container. If you use methods other than Podman Instead of providing the container name or ID, use the last created container. If you use methods other than Podman

View File

@ -29,6 +29,12 @@ processes have mounted it.
Note: This could cause other processes that are using the file system to fail, Note: This could cause other processes that are using the file system to fail,
as the mount point could be removed without their knowledge. as the mount point could be removed without their knowledge.
**--latest, -l**
Instead of providing the container name or ID, use the last created container.
If you use methods other than Podman to run containers such as CRI-O, the last
started container could be from either of those methods.
## EXAMPLE ## EXAMPLE
podman umount containerID podman umount containerID