gopkg.in/docker/docker.v20@v20.10.27/volume/volume.go (about)

     1  package volume // import "github.com/docker/docker/volume"
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  )
     7  
     8  // DefaultDriverName is the driver name used for the driver
     9  // implemented in the local package.
    10  const DefaultDriverName = "local"
    11  
    12  // Scopes define if a volume has is cluster-wide (global) or local only.
    13  // Scopes are returned by the volume driver when it is queried for capabilities and then set on a volume
    14  const (
    15  	LocalScope  = "local"
    16  	GlobalScope = "global"
    17  )
    18  
    19  // Driver is for creating and removing volumes.
    20  type Driver interface {
    21  	// Name returns the name of the volume driver.
    22  	Name() string
    23  	// Create makes a new volume with the given name.
    24  	Create(name string, opts map[string]string) (Volume, error)
    25  	// Remove deletes the volume.
    26  	Remove(vol Volume) (err error)
    27  	// List lists all the volumes the driver has
    28  	List() ([]Volume, error)
    29  	// Get retrieves the volume with the requested name
    30  	Get(name string) (Volume, error)
    31  	// Scope returns the scope of the driver (e.g. `global` or `local`).
    32  	// Scope determines how the driver is handled at a cluster level
    33  	Scope() string
    34  }
    35  
    36  // Capability defines a set of capabilities that a driver is able to handle.
    37  type Capability struct {
    38  	// Scope is the scope of the driver, `global` or `local`
    39  	// A `global` scope indicates that the driver manages volumes across the cluster
    40  	// A `local` scope indicates that the driver only manages volumes resources local to the host
    41  	// Scope is declared by the driver
    42  	Scope string
    43  }
    44  
    45  // Volume is a place to store data. It is backed by a specific driver, and can be mounted.
    46  type Volume interface {
    47  	// Name returns the name of the volume
    48  	Name() string
    49  	// DriverName returns the name of the driver which owns this volume.
    50  	DriverName() string
    51  	// Path returns the absolute path to the volume.
    52  	Path() string
    53  	// Mount mounts the volume and returns the absolute path to
    54  	// where it can be consumed.
    55  	Mount(id string) (string, error)
    56  	// Unmount unmounts the volume when it is no longer in use.
    57  	Unmount(id string) error
    58  	// CreatedAt returns Volume Creation time
    59  	CreatedAt() (time.Time, error)
    60  	// Status returns low-level status information about a volume
    61  	Status() map[string]interface{}
    62  }
    63  
    64  // DetailedVolume wraps a Volume with user-defined labels, options, and cluster scope (e.g., `local` or `global`)
    65  type DetailedVolume interface {
    66  	Labels() map[string]string
    67  	Options() map[string]string
    68  	Scope() string
    69  	Volume
    70  }
    71  
    72  // LiveRestorer is an optional interface that can be implemented by a volume driver
    73  // It is used to restore any resources that are necessary for a volume to be used by a live-restored container
    74  type LiveRestorer interface {
    75  	// LiveRestoreVolume allows a volume driver which implements this interface to restore any necessary resources (such as reference counting)
    76  	// This is called only after the daemon is restarted with live-restored containers
    77  	// It is called once per live-restored container.
    78  	LiveRestoreVolume(_ context.Context, ref string) error
    79  }