Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 8bfbfb0

Browse files
committed
Add docs and type fixes
1 parent cf0c7fe commit 8bfbfb0

File tree

1 file changed

+30
-5
lines changed
  • openstack/blockstorage/v2/extensions/volumeactions

1 file changed

+30
-5
lines changed

openstack/blockstorage/v2/extensions/volumeactions/requests.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ import (
44
"github.com/rackspace/gophercloud"
55
)
66

7+
// AttachOptsBuilder allows extensions to add additional parameters to the
8+
// Attach request.
79
type AttachOptsBuilder interface {
810
ToVolumeAttachMap() (map[string]interface{}, error)
911
}
1012

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.
1123
type AttachOpts struct {
1224
// The mountpoint of this volume
1325
MountPoint string
@@ -16,9 +28,11 @@ type AttachOpts struct {
1628
// The hostname of baremetal host, can't set simultaneously with InstanceUUID
1729
HostName string
1830
// Mount mode of this volume
19-
Mode string
31+
Mode AttachMode
2032
}
2133

34+
// ToVolumeAttachMap assembles a request body based on the contents of a
35+
// AttachOpts.
2236
func (opts AttachOpts) ToVolumeAttachMap() (map[string]interface{}, error) {
2337
v := make(map[string]interface{})
2438

@@ -38,6 +52,7 @@ func (opts AttachOpts) ToVolumeAttachMap() (map[string]interface{}, error) {
3852
return map[string]interface{}{"os-attach": v}, nil
3953
}
4054

55+
// Attach will attach a volume based on the values in AttachOpts.
4156
func Attach(client *gophercloud.ServiceClient, id string, opts AttachOptsBuilder) AttachResult {
4257
var res AttachResult
4358

@@ -48,25 +63,27 @@ func Attach(client *gophercloud.ServiceClient, id string, opts AttachOptsBuilder
4863
}
4964

5065
_, res.Err = client.Post(attachURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
51-
OkCodes: []int{200, 201, 202},
66+
OkCodes: []int{202},
5267
})
5368

5469
return res
5570
}
5671

72+
// Attach will detach a volume based on volume id.
5773
func Detach(client *gophercloud.ServiceClient, id string) DetachResult {
5874
var res DetachResult
5975

6076
v := make(map[string]interface{})
6177
reqBody := map[string]interface{}{"os-detach": v}
6278

6379
_, res.Err = client.Post(detachURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
64-
OkCodes: []int{200, 201, 202},
80+
OkCodes: []int{202},
6581
})
6682

6783
return res
6884
}
6985

86+
// Reserve will reserve a volume based on volume id.
7087
func Reserve(client *gophercloud.ServiceClient, id string) ReserveResult {
7188
var res ReserveResult
7289

@@ -80,6 +97,7 @@ func Reserve(client *gophercloud.ServiceClient, id string) ReserveResult {
8097
return res
8198
}
8299

100+
// Unreserve will unreserve a volume based on volume id.
83101
func Unreserve(client *gophercloud.ServiceClient, id string) UnreserveResult {
84102
var res UnreserveResult
85103

@@ -93,21 +111,26 @@ func Unreserve(client *gophercloud.ServiceClient, id string) UnreserveResult {
93111
return res
94112
}
95113

114+
// ConnectorOptsBuilder allows extensions to add additional parameters to the
115+
// InitializeConnection request.
96116
type ConnectorOptsBuilder interface {
97117
ToConnectorMap() (map[string]interface{}, error)
98118
}
99119

120+
// ConnectorOpts hosts options for InitializeConnection.
100121
type ConnectorOpts struct {
101122
IP string
102123
Host string
103124
Initiator string
104-
Wwpns string
125+
Wwpns []string
105126
Wwnns string
106127
Multipath bool
107128
Platform string
108129
OSType string
109130
}
110131

132+
// ToConnectorMap assembles a request body based on the contents of a
133+
// ConnectorOpts.
111134
func (opts ConnectorOpts) ToConnectorMap() (map[string]interface{}, error) {
112135
v := make(map[string]interface{})
113136

@@ -120,7 +143,7 @@ func (opts ConnectorOpts) ToConnectorMap() (map[string]interface{}, error) {
120143
if opts.Initiator != "" {
121144
v["initiator"] = opts.Initiator
122145
}
123-
if opts.Wwpns != "" {
146+
if opts.Wwpns != nil {
124147
v["wwpns"] = opts.Wwpns
125148
}
126149
if opts.Wwnns != "" {
@@ -139,6 +162,7 @@ func (opts ConnectorOpts) ToConnectorMap() (map[string]interface{}, error) {
139162
return map[string]interface{}{"connector": v}, nil
140163
}
141164

165+
// InitializeConnection initializes iscsi connection.
142166
func InitializeConnection(client *gophercloud.ServiceClient, id string, opts *ConnectorOpts) InitializeConnectionResult {
143167
var res InitializeConnectionResult
144168

@@ -157,6 +181,7 @@ func InitializeConnection(client *gophercloud.ServiceClient, id string, opts *Co
157181
return res
158182
}
159183

184+
// TerminateConnection terminates iscsi connection.
160185
func TerminateConnection(client *gophercloud.ServiceClient, id string, opts *ConnectorOpts) TerminateConnectionResult {
161186
var res TerminateConnectionResult
162187

0 commit comments

Comments
 (0)