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

detaching volume by attachment_id #617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 3 additions & 0 deletions openstack/blockstorage/v2/volumes/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down