github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/volume/volume.go (about) 1 package volume // import "github.com/Prakhar-Agarwal-byte/moby/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 // LiveRestorer is an optional interface that can be implemented by a volume driver 65 // It is used to restore any resources that are necessary for a volume to be used by a live-restored container 66 type LiveRestorer interface { 67 // LiveRestoreVolume allows a volume driver which implements this interface to restore any necessary resources (such as reference counting) 68 // This is called only after the daemon is restarted with live-restored containers 69 // It is called once per live-restored container. 70 LiveRestoreVolume(_ context.Context, ref string) error 71 } 72 73 // DetailedVolume wraps a Volume with user-defined labels, options, and cluster scope (e.g., `local` or `global`) 74 type DetailedVolume interface { 75 Labels() map[string]string 76 Options() map[string]string 77 Scope() string 78 Volume 79 }