diff options
author | umohnani8 <umohnani@redhat.com> | 2018-08-08 09:50:15 -0400 |
---|---|---|
committer | Urvashi Mohnani <umohnani@redhat.com> | 2018-12-06 10:17:16 +0000 |
commit | 4c70b8a94b22b31e2c39ee710dcc21cc2f3fb337 (patch) | |
tree | d6d054bd40f9f0b02c4078b38d2839dc2dd77fc5 /libpod/options.go | |
parent | 75b19ca8abe1957f3c48035767960a6b20c10519 (diff) | |
download | podman-4c70b8a94b22b31e2c39ee710dcc21cc2f3fb337.tar.gz podman-4c70b8a94b22b31e2c39ee710dcc21cc2f3fb337.tar.bz2 podman-4c70b8a94b22b31e2c39ee710dcc21cc2f3fb337.zip |
Add "podman volume" command
Add support for podman volume and its subcommands.
The commands supported are:
podman volume create
podman volume inspect
podman volume ls
podman volume rm
podman volume prune
This is a tool to manage volumes used by podman. For now it only handle
named volumes, but eventually it will handle all volumes used by podman.
Signed-off-by: umohnani8 <umohnani@redhat.com>
Diffstat (limited to 'libpod/options.go')
-rw-r--r-- | libpod/options.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/libpod/options.go b/libpod/options.go index 3e43d73f0..352e6a506 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -327,6 +327,22 @@ func WithNamespace(ns string) RuntimeOption { } } +// WithVolumePath sets the path under which all named volumes +// should be created. +// The path changes based on whethe rthe user is running as root +// or not. +func WithVolumePath(volPath string) RuntimeOption { + return func(rt *Runtime) error { + if rt.valid { + return ErrRuntimeFinalized + } + + rt.config.VolumePath = volPath + + return nil + } +} + // WithDefaultInfraImage sets the infra image for libpod. // An infra image is used for inter-container kernel // namespace sharing within a pod. Typically, an infra @@ -1125,6 +1141,70 @@ func withIsInfra() CtrCreateOption { } } +// Volume Creation Options + +// WithVolumeName sets the name of the volume. +func WithVolumeName(name string) VolumeCreateOption { + return func(volume *Volume) error { + if volume.valid { + return ErrVolumeFinalized + } + + // Check the name against a regex + if !nameRegex.MatchString(name) { + return errors.Wrapf(ErrInvalidArg, "name must match regex [a-zA-Z0-9_-]+") + } + volume.config.Name = name + + return nil + } +} + +// WithVolumeLabels sets the labels of the volume. +func WithVolumeLabels(labels map[string]string) VolumeCreateOption { + return func(volume *Volume) error { + if volume.valid { + return ErrVolumeFinalized + } + + volume.config.Labels = make(map[string]string) + for key, value := range labels { + volume.config.Labels[key] = value + } + + return nil + } +} + +// WithVolumeDriver sets the driver of the volume. +func WithVolumeDriver(driver string) VolumeCreateOption { + return func(volume *Volume) error { + if volume.valid { + return ErrVolumeFinalized + } + + volume.config.Driver = driver + + return nil + } +} + +// WithVolumeOptions sets the options of the volume. +func WithVolumeOptions(options map[string]string) VolumeCreateOption { + return func(volume *Volume) error { + if volume.valid { + return ErrVolumeFinalized + } + + volume.config.Options = make(map[string]string) + for key, value := range options { + volume.config.Options[key] = value + } + + return nil + } +} + // Pod Creation Options // WithPodName sets the name of the pod. |