From 4855998f1cf533b27e48b2ded5541841fe6a3ea6 Mon Sep 17 00:00:00 2001 From: umohnani8 Date: Mon, 11 Jun 2018 15:27:42 -0400 Subject: Add --volumes-from flag to podman run and create podman now supports --volumes-from flag, which allows users to add all the volumes an existing container has to a new one. Signed-off-by: umohnani8 Closes: #931 Approved by: mheon --- cmd/podman/create.go | 5 +++++ cmd/podman/create_cli.go | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/create.go b/cmd/podman/create.go index 19e87c306..d61f85442 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -302,6 +302,10 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim return nil, err } + if err = parseVolumesFrom(c.StringSlice("volumes-from")); err != nil { + return nil, err + } + tty := c.Bool("tty") pidMode := container.PidMode(c.String("pid")) @@ -596,6 +600,7 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim Volumes: c.StringSlice("volume"), WorkDir: workDir, Rootfs: rootfs, + VolumesFrom: c.StringSlice("volumes-from"), } if !config.Privileged { diff --git a/cmd/podman/create_cli.go b/cmd/podman/create_cli.go index 8ae4b6c64..d0ad28595 100644 --- a/cmd/podman/create_cli.go +++ b/cmd/podman/create_cli.go @@ -75,9 +75,6 @@ func addWarning(warnings []string, msg string) []string { } func parseVolumes(volumes []string) error { - if len(volumes) == 0 { - return nil - } for _, volume := range volumes { arr := strings.SplitN(volume, ":", 3) if len(arr) < 2 { @@ -98,6 +95,21 @@ func parseVolumes(volumes []string) error { return nil } +func parseVolumesFrom(volumesFrom []string) error { + for _, vol := range volumesFrom { + arr := strings.SplitN(vol, ":", 2) + if len(arr) == 2 { + if strings.Contains(arr[1], "Z") || strings.Contains(arr[1], "private") || strings.Contains(arr[1], "slave") || strings.Contains(arr[1], "shared") { + return errors.Errorf("invalid options %q, can only specify 'ro', 'rw', and 'z", arr[1]) + } + if err := validateVolumeOpts(arr[1]); err != nil { + return err + } + } + } + return nil +} + func validateVolumeHostDir(hostDir string) error { if !filepath.IsAbs(hostDir) { return errors.Errorf("invalid host path, must be an absolute path %q", hostDir) @@ -121,20 +133,20 @@ func validateVolumeOpts(option string) error { for _, opt := range options { switch opt { case "rw", "ro": + foundRWRO++ if foundRWRO > 1 { return errors.Errorf("invalid options %q, can only specify 1 'rw' or 'ro' option", option) } - foundRWRO++ case "z", "Z": + foundLabelChange++ if foundLabelChange > 1 { return errors.Errorf("invalid options %q, can only specify 1 'z' or 'Z' option", option) } - foundLabelChange++ case "private", "rprivate", "shared", "rshared", "slave", "rslave": + foundRootPropagation++ if foundRootPropagation > 1 { return errors.Errorf("invalid options %q, can only specify 1 '[r]shared', '[r]private' or '[r]slave' option", option) } - foundRootPropagation++ default: return errors.Errorf("invalid option type %q", option) } -- cgit v1.2.3-54-g00ecf