volume.go 2.9 KB

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