summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-02-16 06:04:22 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2022-02-28 14:26:22 -0500
commit3dc1b8e83f2459a58d65f3bb918975cd6f1bb794 (patch)
tree15a3d902665203a36ad06965e79997434567e8c5 /cmd
parentc39dffe83db9fa3cfa6897b971956821f1bbcce2 (diff)
downloadpodman-3dc1b8e83f2459a58d65f3bb918975cd6f1bb794.tar.gz
podman-3dc1b8e83f2459a58d65f3bb918975cd6f1bb794.tar.bz2
podman-3dc1b8e83f2459a58d65f3bb918975cd6f1bb794.zip
Add podman volume mount support
Fixes: https://github.com/containers/podman/issues/12768 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/volumes/exists.go2
-rw-r--r--cmd/podman/volumes/mount.go51
-rw-r--r--cmd/podman/volumes/unmount.go48
3 files changed, 100 insertions, 1 deletions
diff --git a/cmd/podman/volumes/exists.go b/cmd/podman/volumes/exists.go
index 3cac27220..b1bdf9da5 100644
--- a/cmd/podman/volumes/exists.go
+++ b/cmd/podman/volumes/exists.go
@@ -10,7 +10,7 @@ var (
volumeExistsDescription = `If the given volume exists, podman volume exists exits with 0, otherwise the exit code will be 1.`
volumeExistsCommand = &cobra.Command{
Use: "exists VOLUME",
- Short: "volume exists",
+ Short: "Volume exists",
Long: volumeExistsDescription,
RunE: volumeExists,
Example: `podman volume exists myvol`,
diff --git a/cmd/podman/volumes/mount.go b/cmd/podman/volumes/mount.go
new file mode 100644
index 000000000..1f78187b8
--- /dev/null
+++ b/cmd/podman/volumes/mount.go
@@ -0,0 +1,51 @@
+package volumes
+
+import (
+ "fmt"
+
+ "github.com/containers/podman/v4/cmd/podman/common"
+ "github.com/containers/podman/v4/cmd/podman/registry"
+ "github.com/containers/podman/v4/cmd/podman/utils"
+ "github.com/spf13/cobra"
+)
+
+var (
+ volumeMountDescription = `Mount a volume and return the mountpoint`
+ volumeMountCommand = &cobra.Command{
+ Annotations: map[string]string{
+ registry.UnshareNSRequired: "",
+ registry.ParentNSRequired: "",
+ registry.EngineMode: registry.ABIMode,
+ },
+ Use: "mount NAME",
+ Short: "Mount volume",
+ Long: volumeMountDescription,
+ RunE: volumeMount,
+ Example: `podman volume mount myvol`,
+ Args: cobra.ExactArgs(1),
+ ValidArgsFunction: common.AutocompleteVolumes,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Command: volumeMountCommand,
+ Parent: volumeCmd,
+ })
+}
+
+func volumeMount(cmd *cobra.Command, args []string) error {
+ var errs utils.OutputErrors
+ reports, err := registry.ContainerEngine().VolumeMount(registry.GetContext(), args)
+ if err != nil {
+ return err
+ }
+ for _, r := range reports {
+ if r.Err == nil {
+ fmt.Println(r.Path)
+ continue
+ }
+ errs = append(errs, r.Err)
+ }
+ return errs.PrintErrors()
+}
diff --git a/cmd/podman/volumes/unmount.go b/cmd/podman/volumes/unmount.go
new file mode 100644
index 000000000..dd0cebc06
--- /dev/null
+++ b/cmd/podman/volumes/unmount.go
@@ -0,0 +1,48 @@
+package volumes
+
+import (
+ "fmt"
+
+ "github.com/containers/podman/v4/cmd/podman/common"
+ "github.com/containers/podman/v4/cmd/podman/registry"
+ "github.com/containers/podman/v4/cmd/podman/utils"
+ "github.com/spf13/cobra"
+)
+
+var (
+ volumeUnmountDescription = `Unmount a volume`
+ volumeUnmountCommand = &cobra.Command{
+ Annotations: map[string]string{registry.EngineMode: registry.ABIMode},
+ Use: "unmount NAME",
+ Short: "Unmount volume",
+ Long: volumeUnmountDescription,
+ RunE: volumeUnmount,
+ Example: `podman volume unmount myvol`,
+ Args: cobra.ExactArgs(1),
+ ValidArgsFunction: common.AutocompleteVolumes,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Command: volumeUnmountCommand,
+ Parent: volumeCmd,
+ })
+}
+
+func volumeUnmount(cmd *cobra.Command, args []string) error {
+ var errs utils.OutputErrors
+ reports, err := registry.ContainerEngine().VolumeUnmount(registry.GetContext(), args)
+ if err != nil {
+ return err
+ }
+ for _, r := range reports {
+ var errs utils.OutputErrors
+ if r.Err == nil {
+ fmt.Println(r.Id)
+ } else {
+ errs = append(errs, r.Err)
+ }
+ }
+ return errs.PrintErrors()
+}