diff --git a/openstack/blockstorage/v2/extensions/volumeactions/fixtures.go b/openstack/blockstorage/v2/extensions/volumeactions/fixtures.go index 905d6df0..6e6039a8 100644 --- a/openstack/blockstorage/v2/extensions/volumeactions/fixtures.go +++ b/openstack/blockstorage/v2/extensions/volumeactions/fixtures.go @@ -43,7 +43,10 @@ func MockDetachResponse(t *testing.T) { th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { - "os-detach": {} + "os-detach": + { + "attachment_id": "d8483b65-515b-4dae-b811-3ffaca3cc6e7" + } } `) diff --git a/openstack/blockstorage/v2/extensions/volumeactions/requests.go b/openstack/blockstorage/v2/extensions/volumeactions/requests.go index 842a659e..8939e1a5 100644 --- a/openstack/blockstorage/v2/extensions/volumeactions/requests.go +++ b/openstack/blockstorage/v2/extensions/volumeactions/requests.go @@ -70,10 +70,15 @@ func Attach(client *gophercloud.ServiceClient, id string, opts AttachOptsBuilder } // Attach will detach a volume based on volume id. -func Detach(client *gophercloud.ServiceClient, id string) DetachResult { +func Detach(client *gophercloud.ServiceClient, id string, attachmentId string) DetachResult { var res DetachResult v := make(map[string]interface{}) + + if attachmentId != "" { + v["attachment_id"] = attachmentId + } + reqBody := map[string]interface{}{"os-detach": v} _, res.Err = client.Post(detachURL(client, id), reqBody, nil, &gophercloud.RequestOpts{ diff --git a/openstack/blockstorage/v2/extensions/volumeactions/requests_test.go b/openstack/blockstorage/v2/extensions/volumeactions/requests_test.go index 56572874..15abdb4b 100644 --- a/openstack/blockstorage/v2/extensions/volumeactions/requests_test.go +++ b/openstack/blockstorage/v2/extensions/volumeactions/requests_test.go @@ -28,7 +28,7 @@ func TestDetach(t *testing.T) { MockDetachResponse(t) - err := Detach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr() + err := Detach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", "d8483b65-515b-4dae-b811-3ffaca3cc6e7").ExtractErr() th.AssertNoErr(t, err) } diff --git a/openstack/blockstorage/v2/volumes/results.go b/openstack/blockstorage/v2/volumes/results.go index 59fa5307..c571c75d 100644 --- a/openstack/blockstorage/v2/volumes/results.go +++ b/openstack/blockstorage/v2/volumes/results.go @@ -71,6 +71,9 @@ type Volume struct { // UserID is the id of the user who created the volume. UserID string `mapstructure:"user_id"` + + // Attachment identifier for detaching a volume from a storage + AttachmentID string `mapstructure:"attachment_id"` } // CreateResult contains the response body and error from a Create request.