forked from libopenstorage/openstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storageops.go
99 lines (91 loc) · 3.74 KB
/
storageops.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
package storageops
import "fmt"
const (
// SetIdentifierNone is a default identifier to group all disks from a
// particular set
SetIdentifierNone = "None"
)
// Custom storage operation error codes.
const (
_ = iota + 5000
// ErrVolDetached is code for a volume is detached on the instance
ErrVolDetached
// ErrVolInval is the code for a invalid volume
ErrVolInval
// ErrVolAttachedOnRemoteNode is code when a volume is not attached locally
// but attached on a remote node
ErrVolAttachedOnRemoteNode
// ErrVolNotFound is code when a volume is not found
ErrVolNotFound
// ErrInvalidDevicePath is code when a volume/disk has invalid device path
ErrInvalidDevicePath
)
// ErrNotSupported is returned when a particular operation is not supported
var ErrNotSupported = fmt.Errorf("operation not supported")
// StorageError error returned for storage operations
type StorageError struct {
// Code is one of storage operation driver error codes.
Code int
// Msg is human understandable error message.
Msg string
// Instance provides more information on the error.
Instance string
}
// Ops interface to perform basic storage operations.
type Ops interface {
// Name returns name of the storage operations driver
Name() string
// InstanceID returns the ID of the instance of the default instance the operations are performed on
InstanceID() string
// Create volume based on input template volume and also apply given labels.
Create(template interface{}, labels map[string]string) (interface{}, error)
// GetDeviceID returns ID/Name of the given device/disk or snapshot
GetDeviceID(template interface{}) (string, error)
// Attach volumeID.
// Return attach path.
Attach(volumeID string) (string, error)
// Detach volumeID.
Detach(volumeID string) error
// DetachFrom detaches the disk/volume with given ID from the given instance ID
DetachFrom(volumeID, instanceID string) error
// Delete volumeID.
Delete(volumeID string) error
// DeleteFrom deletes the given volume/disk from the given instanceID
DeleteFrom(volumeID, instanceID string) error
// Desribe an instance
Describe() (interface{}, error)
// FreeDevices returns free block devices on the instance.
// blockDeviceMappings is a data structure that contains all block devices on
// the instance and where they are mapped to
FreeDevices(blockDeviceMappings []interface{}, rootDeviceName string) ([]string, error)
// Inspect volumes specified by volumeID
Inspect(volumeIds []*string) ([]interface{}, error)
// DeviceMappings returns map[local_attached_volume_path]->volume ID/NAME
DeviceMappings() (map[string]string, error)
// Enumerate volumes that match given filters. Organize them into
// sets identified by setIdentifier.
// labels can be nil, setIdentifier can be empty string.
Enumerate(volumeIds []*string,
labels map[string]string,
setIdentifier string,
) (map[string][]interface{}, error)
// DevicePath for the given volume i.e path where it's attached
DevicePath(volumeID string) (string, error)
// Snapshot the volume with given volumeID
Snapshot(volumeID string, readonly bool) (interface{}, error)
// SnapshotDelete deletes the snapshot with given ID
SnapshotDelete(snapID string) error
// ApplyTags will apply given labels/tags on the given volume
ApplyTags(volumeID string, labels map[string]string) error
// RemoveTags removes labels/tags from the given volume
RemoveTags(volumeID string, labels map[string]string) error
// Tags will list the existing labels/tags on the given volume
Tags(volumeID string) (map[string]string, error)
}
// NewStorageError creates a new custom storage error instance
func NewStorageError(code int, msg string, instance string) error {
return &StorageError{Code: code, Msg: msg, Instance: instance}
}
func (e *StorageError) Error() string {
return e.Msg
}