forked from thecodeteam/libstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_drivers_storage.go
389 lines (328 loc) · 11.2 KB
/
types_drivers_storage.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
package types
import "strconv"
// LibStorageDriverName is the name of the libStorage storage driver.
const LibStorageDriverName = "libstorage"
// NewStorageDriver is a function that constructs a new StorageDriver.
type NewStorageDriver func() StorageDriver
// VolumeAttachmentsTypes is the type of the volume attachments bitmask.
type VolumeAttachmentsTypes int
const (
// VolumeAttachmentsRequested indicates attachment information is requested.
VolumeAttachmentsRequested VolumeAttachmentsTypes = 1 << iota // 1
// VolumeAttachmentsMine indicates attachment information should
// be returned for volumes attached to the instance specified in the
// instance ID request header. If this bit is set then the instance ID
// header is required.
VolumeAttachmentsMine // 2
// VolumeAttachmentsDevices indicates an attempt should made to map devices
// provided via the local devices request header to the appropriate
// attachment information. If this bit is set then the instance ID and
// local device headers are required.
VolumeAttachmentsDevices // 4
// VolumeAttachmentsAttached indicates only volumes that are attached
// should be returned.
VolumeAttachmentsAttached // 8
// VolumeAttachmentsUnattached indicates only volumes that are unattached
// should be returned.
VolumeAttachmentsUnattached // 16
)
const (
// VolAttNone is the default value. This indicates no attachment
// information is requested.
VolAttNone VolumeAttachmentsTypes = 0
// VolAttFalse is an alias for VolAttNone.
VolAttFalse = VolAttNone
// VolAttReq requests attachment information for all retrieved volumes.
//
// Mask: 1
VolAttReq = VolumeAttachmentsRequested
// VolAttReqForInstance requests attachment information for volumes attached
// to the instance provided in the instance ID
//
// Mask: 1 | 2
VolAttReqForInstance = VolAttReq | VolumeAttachmentsMine
// VolAttReqWithDevMapForInstance requests attachment information for
// volumes attached to the instance provided in the instance ID and perform
// device mappings where possible.
//
// Mask: 1 | 2 | 4
VolAttReqWithDevMapForInstance = VolAttReqForInstance |
VolumeAttachmentsDevices
// VolAttReqOnlyAttachedVols requests attachment information for all
// retrieved volumes and return only volumes that are attached to some
// instance.
//
// Mask: 1 | 8
VolAttReqOnlyAttachedVols = VolAttReq | VolumeAttachmentsAttached
// VolAttReqOnlyUnattachedVols requests attachment information for
// all retrieved volumes and return only volumes that are not attached to
// any instance.
//
// Mask: 1 | 16
VolAttReqOnlyUnattachedVols = VolAttReq | VolumeAttachmentsUnattached
// VolAttReqOnlyVolsAttachedToInstance requests attachment
// information for all retrieved volumes and return only volumes that
// attached to the instance provided in the instance ID.
//
// Mask: 1 | 2 | 8
VolAttReqOnlyVolsAttachedToInstance = VolAttReqForInstance |
VolumeAttachmentsAttached
// VolAttReqWithDevMapOnlyVolsAttachedToInstance requests attachment
// information for all retrieved volumes and return only volumes that
// attached to the instance provided in the instance ID and perform device
// mappings where possible.
//
// Mask: 1 | 2 | 4 | 8
VolAttReqWithDevMapOnlyVolsAttachedToInstance = VolumeAttachmentsDevices |
VolAttReqOnlyVolsAttachedToInstance
// VolAttReqTrue is an alias for
// VolAttReqWithDevMapOnlyVolsAttachedToInstance.
VolAttReqTrue = VolAttReqWithDevMapOnlyVolsAttachedToInstance
// VolumeAttachmentsTrue is an alias for VolAttReqTrue.
VolumeAttachmentsTrue = VolAttReqTrue
// VolAttReqOnlyVolsAttachedToInstanceOrUnattachedVols requests attachment
// information for all retrieved volumes and return only volumes that
// attached to the instance provided in the instance ID or are not attached
// to any instance at all. tl;dr - Attached To Me or Available
//
// Mask: 1 | 2 | 8 | 16
VolAttReqOnlyVolsAttachedToInstanceOrUnattachedVols = 0 |
VolAttReqOnlyVolsAttachedToInstance |
VolumeAttachmentsUnattached
// VolAttReqWithDevMapOnlyVolsAttachedToInstanceOrUnattachedVols requests
// attachment information for all retrieved volumes and return only volumes
// that attached to the instance provided in the instance ID or are not
// attached to any instance at all and perform device mappings where
// possible. tl;dr - Attached To Me With Device Mappings or Available
//
// Mask: 1 | 2 | 4 | 8 | 16
VolAttReqWithDevMapOnlyVolsAttachedToInstanceOrUnattachedVols = 0 |
VolumeAttachmentsDevices |
VolAttReqOnlyVolsAttachedToInstanceOrUnattachedVols
)
// ParseVolumeAttachmentTypes parses a value into a VolumeAttachmentsTypes
// value.
func ParseVolumeAttachmentTypes(v interface{}) VolumeAttachmentsTypes {
switch tv := v.(type) {
case VolumeAttachmentsTypes:
return tv
case int:
return VolumeAttachmentsTypes(tv)
case uint:
return VolumeAttachmentsTypes(tv)
case int8:
return VolumeAttachmentsTypes(tv)
case uint8:
return VolumeAttachmentsTypes(tv)
case int16:
return VolumeAttachmentsTypes(tv)
case uint16:
return VolumeAttachmentsTypes(tv)
case int32:
return VolumeAttachmentsTypes(tv)
case uint32:
return VolumeAttachmentsTypes(tv)
case int64:
return VolumeAttachmentsTypes(tv)
case uint64:
return VolumeAttachmentsTypes(tv)
case string:
if i, err := strconv.ParseInt(tv, 10, 64); err == nil {
return ParseVolumeAttachmentTypes(i)
}
if b, err := strconv.ParseBool(tv); err == nil {
return ParseVolumeAttachmentTypes(b)
}
case bool:
if tv {
return VolumeAttachmentsTrue
}
return VolumeAttachmentsRequested
}
return VolAttNone
}
// RequiresInstanceID returns a flag that indicates whether the attachment
// bit requires an instance ID to perform successfully.
func (v VolumeAttachmentsTypes) RequiresInstanceID() bool {
return v.Mine() || v.Devices()
}
// Requested returns a flag that indicates attachment information is requested.
func (v VolumeAttachmentsTypes) Requested() bool {
return v.bitSet(VolumeAttachmentsRequested)
}
// Mine returns a flag that indicates attachment information should
// be returned for volumes attached to the instance specified in the
// instance ID request header. If this bit is set then the instance ID
// header is required.
func (v VolumeAttachmentsTypes) Mine() bool {
return v.bitSet(VolumeAttachmentsMine)
}
// Devices returns a flag that indicates an attempt should made to map devices
// provided via the local devices request header to the appropriate
// attachment information. If this bit is set then the instance ID and
// local device headers are required.
func (v VolumeAttachmentsTypes) Devices() bool {
return v.bitSet(VolumeAttachmentsDevices)
}
// Attached returns a flag that indicates only volumes that are attached should
// be returned.
func (v VolumeAttachmentsTypes) Attached() bool {
return v.bitSet(VolumeAttachmentsAttached)
}
// Unattached returns a flag that indicates only volumes that are unattached
// should be returned.
func (v VolumeAttachmentsTypes) Unattached() bool {
return v.bitSet(VolumeAttachmentsUnattached)
}
func (v VolumeAttachmentsTypes) bitSet(b VolumeAttachmentsTypes) bool {
return v&b == b
}
// VolumesOpts are options when inspecting a volume.
type VolumesOpts struct {
Attachments VolumeAttachmentsTypes
Opts Store
}
// VolumeInspectOpts are options when inspecting a volume.
type VolumeInspectOpts struct {
Attachments VolumeAttachmentsTypes
Opts Store
}
// VolumeCreateOpts are options when creating a new volume.
type VolumeCreateOpts struct {
AvailabilityZone *string
IOPS *int64
Size *int64
Type *string
Encrypted *bool
EncryptionKey *string
Opts Store
}
// VolumeAttachOpts are options for attaching a volume.
type VolumeAttachOpts struct {
NextDevice *string
Force bool
Opts Store
}
// VolumeDetachOpts are options for detaching a volume.
type VolumeDetachOpts struct {
Force bool
Opts Store
}
// VolumeRemoveOpts are options for removing a volume.
type VolumeRemoveOpts struct {
Force bool
Opts Store
}
// StorageDriverManager is the management wrapper for a StorageDriver.
type StorageDriverManager interface {
StorageDriver
// Driver returns the underlying driver.
Driver() StorageDriver
}
/*
StorageDriver is a libStorage driver used by the routes to implement the
backend functionality.
Functions that inspect a resource or send an operation to a resource should
always return ErrResourceNotFound if the acted upon resource cannot be found.
*/
type StorageDriver interface {
Driver
// NextDeviceInfo returns the information about the driver's next available
// device workflow.
NextDeviceInfo(
ctx Context) (*NextDeviceInfo, error)
// Type returns the type of storage the driver provides.
Type(
ctx Context) (StorageType, error)
// InstanceInspect returns an instance.
InstanceInspect(
ctx Context,
opts Store) (*Instance, error)
// Volumes returns all volumes or a filtered list of volumes.
Volumes(
ctx Context,
opts *VolumesOpts) ([]*Volume, error)
// VolumeInspect inspects a single volume.
VolumeInspect(
ctx Context,
volumeID string,
opts *VolumeInspectOpts) (*Volume, error)
// VolumeCreate creates a new volume.
VolumeCreate(
ctx Context,
name string,
opts *VolumeCreateOpts) (*Volume, error)
// VolumeCreateFromSnapshot creates a new volume from an existing snapshot.
VolumeCreateFromSnapshot(
ctx Context,
snapshotID,
volumeName string,
opts *VolumeCreateOpts) (*Volume, error)
// VolumeCopy copies an existing volume.
VolumeCopy(
ctx Context,
volumeID,
volumeName string,
opts Store) (*Volume, error)
// VolumeSnapshot snapshots a volume.
VolumeSnapshot(
ctx Context,
volumeID,
snapshotName string,
opts Store) (*Snapshot, error)
// VolumeRemove removes a volume.
VolumeRemove(
ctx Context,
volumeID string,
opts *VolumeRemoveOpts) error
// VolumeAttach attaches a volume and provides a token clients can use
// to validate that device has appeared locally.
VolumeAttach(
ctx Context,
volumeID string,
opts *VolumeAttachOpts) (*Volume, string, error)
// VolumeDetach detaches a volume.
VolumeDetach(
ctx Context,
volumeID string,
opts *VolumeDetachOpts) (*Volume, error)
// Snapshots returns all volumes or a filtered list of snapshots.
Snapshots(
ctx Context,
opts Store) ([]*Snapshot, error)
// SnapshotInspect inspects a single snapshot.
SnapshotInspect(
ctx Context,
snapshotID string,
opts Store) (*Snapshot, error)
// SnapshotCopy copies an existing snapshot.
SnapshotCopy(
ctx Context,
snapshotID,
snapshotName,
destinationID string,
opts Store) (*Snapshot, error)
// SnapshotRemove removes a snapshot.
SnapshotRemove(
ctx Context,
snapshotID string,
opts Store) error
}
// StorageDriverWithLogin is a StorageDriver with a Login function.
type StorageDriverWithLogin interface {
StorageDriver
// Login creates a new connection to the storage platform for the provided
// context.
Login(
ctx Context) (interface{}, error)
}
// StorageDriverVolInspectByName is a StorageDriver with a VolumeInspectByName
// function
type StorageDriverVolInspectByName interface {
StorageDriver
// VolumeInspectByName inspects a single volume by name.
VolumeInspectByName(
ctx Context,
volumeName string,
opts *VolumeInspectOpts) (*Volume, error)
}