/
dobs.go
82 lines (67 loc) · 2.72 KB
/
dobs.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
package dobs
import (
gofigCore "github.com/akutz/gofig"
gofig "github.com/akutz/gofig/types"
)
const (
// Name is the name of the driver
Name = "dobs"
defaultStatusMaxAttempts = 10
defaultStatusInitDelay = "100ms"
defaultConvertUnderscores = false
/* This is hard deadline when waiting for the volume status to change to
a desired state. At minimum is has to be more than the expontential
backoff of sum 100*2^x, x=0 to 9 == 102s3ms, but should also account for
RTT of API requests, and how many API requests would be made to
exhaust retries */
defaultStatusTimeout = "2m"
// InstanceIDFieldRegion is the key used to retrive the region from the
// instance id map
InstanceIDFieldRegion = "region"
// InstanceIDFieldName is the key used to retrive the name from the instance
// id map
InstanceIDFieldName = "name"
// VolumePrefix is the value that every DO volume appears with DigitalOcean
// volumes are are found using disk/by-id, for example:
//
// /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01
//
// Please see https://goo.gl/MwReS6 for more information.
VolumePrefix = "scsi-0DO_Volume_"
// ConfigToken is the key for the token in the config file
ConfigToken = Name + ".token"
// ConfigRegion is the key for the region in the config file
ConfigRegion = Name + ".region"
// ConfigStatusMaxAttempts is the key for the maximum number of times
// a volume status will be queried when waiting for an action to finish
ConfigStatusMaxAttempts = Name + ".statusMaxAttempts"
// ConfigStatusInitDelay is the key for the initial time duration
// for exponential backoff
ConfigStatusInitDelay = Name + ".statusInitialDelay"
// ConfigStatusTimeout is the key for the time duration for a timeout
// on how long to wait for a desired volume status to appears
ConfigStatusTimeout = Name + ".statusTimeout"
// ConfigConvertUnderscores is the key for a boolean flag on whether
// incoming requests that have names with underscores should be
// converted to dashes to satisfy DO naming requirements
ConfigConvertUnderscores = Name + ".convertUnderscores"
)
func init() {
registerConfig()
}
func registerConfig() {
r := gofigCore.NewRegistration("DigitalOcean Block Storage")
r.Key(gofig.String, "", "", "The DigitalOcean access token",
ConfigToken)
r.Key(gofig.String, "", "", "The DigitalOcean region",
ConfigRegion)
r.Key(gofig.Int, "", defaultStatusMaxAttempts, "Max Status Attempts",
ConfigStatusMaxAttempts)
r.Key(gofig.String, "", defaultStatusInitDelay, "Status Initial Delay",
ConfigStatusInitDelay)
r.Key(gofig.String, "", defaultStatusTimeout, "Status Timeout",
ConfigStatusTimeout)
r.Key(gofig.Bool, "", defaultConvertUnderscores,
"Convert Underscores", ConfigConvertUnderscores)
gofigCore.Register(r)
}