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

Commit e881b4a

Browse files
committed
This is a patch for detaching volume by attachment_id,
when using in attaching a same volume to multiple hosts. This patch, Of course, support both 1:1 and 1:N attachment. Currently, detaching logic in gophercloud can only support on 1:1(volume:host) attachment. But many users want to be able to attach the same volume to multiple hosts. (for example : clustered application(A:P)) BP : https://specs.openstack.org/openstack/cinder-specs/specs/kilo/multi-attach-volume.html Signed-off-by: Jangseon Ryu <[email protected]>
1 parent e00690e commit e881b4a

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ func MockDetachResponse(t *testing.T) {
4343
th.TestHeader(t, r, "Accept", "application/json")
4444
th.TestJSONRequest(t, r, `
4545
{
46-
"os-detach": {}
46+
"os-detach":
47+
{
48+
"attachment_id": "d8483b65-515b-4dae-b811-3ffaca3cc6e7"
49+
}
4750
}
4851
`)
4952

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,15 @@ func Attach(client *gophercloud.ServiceClient, id string, opts AttachOptsBuilder
7070
}
7171

7272
// Attach will detach a volume based on volume id.
73-
func Detach(client *gophercloud.ServiceClient, id string) DetachResult {
73+
func Detach(client *gophercloud.ServiceClient, id string, attachmentId string) DetachResult {
7474
var res DetachResult
7575

7676
v := make(map[string]interface{})
77+
78+
if attachmentId != "" {
79+
v["attachment_id"] = attachmentId
80+
}
81+
7782
reqBody := map[string]interface{}{"os-detach": v}
7883

7984
_, res.Err = client.Post(detachURL(client, id), reqBody, nil, &gophercloud.RequestOpts{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestDetach(t *testing.T) {
2828

2929
MockDetachResponse(t)
3030

31-
err := Detach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr()
31+
err := Detach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", "d8483b65-515b-4dae-b811-3ffaca3cc6e7").ExtractErr()
3232
th.AssertNoErr(t, err)
3333
}
3434

openstack/blockstorage/v2/volumes/results.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ type Volume struct {
7171

7272
// UserID is the id of the user who created the volume.
7373
UserID string `mapstructure:"user_id"`
74+
75+
// Attachment identifier for detaching a volume from a storage
76+
AttachmentID string `mapstructure:"attachment_id"`
7477
}
7578

7679
// CreateResult contains the response body and error from a Create request.

0 commit comments

Comments
 (0)