@@ -4,10 +4,22 @@ import (
4
4
"github.com/rackspace/gophercloud"
5
5
)
6
6
7
+ // AttachOptsBuilder allows extensions to add additional parameters to the
8
+ // Attach request.
7
9
type AttachOptsBuilder interface {
8
10
ToVolumeAttachMap () (map [string ]interface {}, error )
9
11
}
10
12
13
+ // AttachMode describes the attachment mode for volumes.
14
+ type AttachMode string
15
+
16
+ // These constants determine how a volume is attached
17
+ const (
18
+ ReadOnly AttachMode = "ro"
19
+ ReadWrite AttachMode = "rw"
20
+ )
21
+
22
+ // AttachOpts contains options for attaching a Volume.
11
23
type AttachOpts struct {
12
24
// The mountpoint of this volume
13
25
MountPoint string
@@ -16,9 +28,11 @@ type AttachOpts struct {
16
28
// The hostname of baremetal host, can't set simultaneously with InstanceUUID
17
29
HostName string
18
30
// Mount mode of this volume
19
- Mode string
31
+ Mode AttachMode
20
32
}
21
33
34
+ // ToVolumeAttachMap assembles a request body based on the contents of a
35
+ // AttachOpts.
22
36
func (opts AttachOpts ) ToVolumeAttachMap () (map [string ]interface {}, error ) {
23
37
v := make (map [string ]interface {})
24
38
@@ -38,6 +52,7 @@ func (opts AttachOpts) ToVolumeAttachMap() (map[string]interface{}, error) {
38
52
return map [string ]interface {}{"os-attach" : v }, nil
39
53
}
40
54
55
+ // Attach will attach a volume based on the values in AttachOpts.
41
56
func Attach (client * gophercloud.ServiceClient , id string , opts AttachOptsBuilder ) AttachResult {
42
57
var res AttachResult
43
58
@@ -48,25 +63,27 @@ func Attach(client *gophercloud.ServiceClient, id string, opts AttachOptsBuilder
48
63
}
49
64
50
65
_ , res .Err = client .Post (attachURL (client , id ), reqBody , & res .Body , & gophercloud.RequestOpts {
51
- OkCodes : []int {200 , 201 , 202 },
66
+ OkCodes : []int {202 },
52
67
})
53
68
54
69
return res
55
70
}
56
71
72
+ // Attach will detach a volume based on volume id.
57
73
func Detach (client * gophercloud.ServiceClient , id string ) DetachResult {
58
74
var res DetachResult
59
75
60
76
v := make (map [string ]interface {})
61
77
reqBody := map [string ]interface {}{"os-detach" : v }
62
78
63
79
_ , res .Err = client .Post (detachURL (client , id ), reqBody , & res .Body , & gophercloud.RequestOpts {
64
- OkCodes : []int {200 , 201 , 202 },
80
+ OkCodes : []int {202 },
65
81
})
66
82
67
83
return res
68
84
}
69
85
86
+ // Reserve will reserve a volume based on volume id.
70
87
func Reserve (client * gophercloud.ServiceClient , id string ) ReserveResult {
71
88
var res ReserveResult
72
89
@@ -80,6 +97,7 @@ func Reserve(client *gophercloud.ServiceClient, id string) ReserveResult {
80
97
return res
81
98
}
82
99
100
+ // Unreserve will unreserve a volume based on volume id.
83
101
func Unreserve (client * gophercloud.ServiceClient , id string ) UnreserveResult {
84
102
var res UnreserveResult
85
103
@@ -93,21 +111,26 @@ func Unreserve(client *gophercloud.ServiceClient, id string) UnreserveResult {
93
111
return res
94
112
}
95
113
114
+ // ConnectorOptsBuilder allows extensions to add additional parameters to the
115
+ // InitializeConnection request.
96
116
type ConnectorOptsBuilder interface {
97
117
ToConnectorMap () (map [string ]interface {}, error )
98
118
}
99
119
120
+ // ConnectorOpts hosts options for InitializeConnection.
100
121
type ConnectorOpts struct {
101
122
IP string
102
123
Host string
103
124
Initiator string
104
- Wwpns string
125
+ Wwpns [] string
105
126
Wwnns string
106
127
Multipath bool
107
128
Platform string
108
129
OSType string
109
130
}
110
131
132
+ // ToConnectorMap assembles a request body based on the contents of a
133
+ // ConnectorOpts.
111
134
func (opts ConnectorOpts ) ToConnectorMap () (map [string ]interface {}, error ) {
112
135
v := make (map [string ]interface {})
113
136
@@ -120,7 +143,7 @@ func (opts ConnectorOpts) ToConnectorMap() (map[string]interface{}, error) {
120
143
if opts .Initiator != "" {
121
144
v ["initiator" ] = opts .Initiator
122
145
}
123
- if opts .Wwpns != "" {
146
+ if opts .Wwpns != nil {
124
147
v ["wwpns" ] = opts .Wwpns
125
148
}
126
149
if opts .Wwnns != "" {
@@ -139,6 +162,7 @@ func (opts ConnectorOpts) ToConnectorMap() (map[string]interface{}, error) {
139
162
return map [string ]interface {}{"connector" : v }, nil
140
163
}
141
164
165
+ // InitializeConnection initializes iscsi connection.
142
166
func InitializeConnection (client * gophercloud.ServiceClient , id string , opts * ConnectorOpts ) InitializeConnectionResult {
143
167
var res InitializeConnectionResult
144
168
@@ -157,6 +181,7 @@ func InitializeConnection(client *gophercloud.ServiceClient, id string, opts *Co
157
181
return res
158
182
}
159
183
184
+ // TerminateConnection terminates iscsi connection.
160
185
func TerminateConnection (client * gophercloud.ServiceClient , id string , opts * ConnectorOpts ) TerminateConnectionResult {
161
186
var res TerminateConnectionResult
162
187
0 commit comments