/
driver.go
148 lines (116 loc) · 3.68 KB
/
driver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package storage
import (
"errors"
"time"
"github.com/contiv/errored"
)
var (
// ErrVolumeExist indicates that a volume already exists.
ErrVolumeExist = errors.New("Volume already exists")
)
// Params are parameters that relate directly to the location of the storage.
type Params map[string]string
// A Mount is the resulting attributes of a Mount or Unmount operation.
type Mount struct {
Device string
Path string
DevMajor uint
DevMinor uint
Volume Volume
}
// FSOptions encapsulates the parameters to create and manipulate filesystems.
type FSOptions struct {
Type string
CreateCommand string
}
// DriverOptions are options frequently passed as the keystone for operations.
// See Driver for more information.
type DriverOptions struct {
Source string
Volume Volume
FSOptions FSOptions
Timeout time.Duration
Options map[string]string
}
// ListOptions is a set of parameters used for the List operation of Driver.
type ListOptions struct {
Params Params
}
// Volume is the basic representation of a volume name and its parameters.
type Volume struct {
Name string
Size uint64
Params Params
}
// NamedDriver is a named driver and has a method called Name()
type NamedDriver interface {
// Name returns the string associated with the storage backed of the driver
Name() string
}
// ValidatingDriver implements Validate() against storage.DriverOptions.
type ValidatingDriver interface {
Validate(*DriverOptions) error
}
// MountDriver mounts volumes.
type MountDriver interface {
NamedDriver
ValidatingDriver
// Mount a Volume
Mount(DriverOptions) (*Mount, error)
// Unmount a volume
Unmount(DriverOptions) error
// Mounted shows any volumes that belong to volplugin on the host, in
// their native representation. They yield a *Mount.
Mounted(time.Duration) ([]*Mount, error)
// MountPath describes the path at which the volume should be mounted.
MountPath(DriverOptions) (string, error)
}
// CRUDDriver performs CRUD operations.
type CRUDDriver interface {
NamedDriver
ValidatingDriver
// Create a volume.
Create(DriverOptions) error
// Format a volume.
Format(DriverOptions) error
// Destroy a volume.
Destroy(DriverOptions) error
// List Volumes. May be scoped by storage parameters or other data.
List(ListOptions) ([]Volume, error)
// Exists returns true if a volume exists. Otherwise, it returns false.
Exists(DriverOptions) (bool, error)
}
// SnapshotDriver manages snapshots.
type SnapshotDriver interface {
NamedDriver
ValidatingDriver
// CreateSnapshot creates a named snapshot for the volume. Any error will be returned.
CreateSnapshot(string, DriverOptions) error
// RemoveSnapshot removes a named snapshot for the volume. Any error will be returned.
RemoveSnapshot(string, DriverOptions) error
// ListSnapshots returns an array of snapshot names provided a maximum number
// of snapshots to be returned. Any error will be returned.
ListSnapshots(DriverOptions) ([]string, error)
// CopySnapshot copies a snapshot into a new volume. Takes a DriverOptions,
// snap and volume name (string). Returns error on failure.
CopySnapshot(DriverOptions, string, string) error
}
// Validate validates driver options to ensure they are compatible with all
// storage drivers.
func (do *DriverOptions) Validate() error {
if do.Timeout == 0 {
return errored.Errorf("Missing timeout in storage driver")
}
return do.Volume.Validate()
}
// Validate validates volume options to ensure they are compatible with all
// storage drivers.
func (v Volume) Validate() error {
if v.Name == "" {
return errored.Errorf("Name is missing in storage driver")
}
if v.Params == nil {
return errored.Errorf("Params are nil in storage driver")
}
return nil
}