Skip to content

Commit 469ca6a

Browse files
blockstorage: add unmanage api call
Implemented missing blockstorage api call to unmanage volume. ref. https://docs.openstack.org/api-ref/block-storage/v3/#unmanage-a-volume
1 parent ea86f48 commit 469ca6a

5 files changed

Lines changed: 49 additions & 0 deletions

File tree

openstack/blockstorage/v3/volumes/doc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,12 @@ Example of Attaching a Volume to an Instance
157157
if err != nil {
158158
panic(err)
159159
}
160+
161+
Example of Unmanaging a Volume
162+
163+
err := volumes.Unmanage(context.TODO(), client, volume.ID).ExtractErr()
164+
if err != nil {
165+
panic(err)
166+
}
160167
*/
161168
package volumes

openstack/blockstorage/v3/volumes/requests.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,14 @@ func ResetStatus(ctx context.Context, client *gophercloud.ServiceClient, id stri
763763
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
764764
return
765765
}
766+
767+
// Unmanage removes a volume from Block Storage management without
768+
// removing the back-end storage object that is associated with it.
769+
func Unmanage(ctx context.Context, client *gophercloud.ServiceClient, id string) (r UnmanageResult) {
770+
body := map[string]any{"os-unmanage": make(map[string]any)}
771+
resp, err := client.Post(ctx, actionURL(client, id), body, nil, &gophercloud.RequestOpts{
772+
OkCodes: []int{202},
773+
})
774+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
775+
return
776+
}

openstack/blockstorage/v3/volumes/results.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,8 @@ type ReImageResult struct {
399399
type ResetStatusResult struct {
400400
gophercloud.ErrResult
401401
}
402+
403+
// UnmanageResult contains the response error from a Unmanage request.
404+
type UnmanageResult struct {
405+
gophercloud.ErrResult
406+
}

openstack/blockstorage/v3/volumes/testing/fixtures_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,19 @@ func MockResetStatusResponse(t *testing.T) {
648648
w.WriteHeader(http.StatusAccepted)
649649
})
650650
}
651+
652+
func MockUnmanageResponse(t *testing.T) {
653+
th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
654+
func(w http.ResponseWriter, r *http.Request) {
655+
th.TestMethod(t, r, "POST")
656+
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
657+
th.TestHeader(t, r, "Content-Type", "application/json")
658+
th.TestJSONRequest(t, r, `
659+
{
660+
"os-unmanage": {}
661+
}
662+
`)
663+
664+
w.WriteHeader(http.StatusAccepted)
665+
})
666+
}

openstack/blockstorage/v3/volumes/testing/requests_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,13 @@ func TestResetStatus(t *testing.T) {
538538
err := volumes.ResetStatus(context.TODO(), client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
539539
th.AssertNoErr(t, err)
540540
}
541+
542+
func TestUnmanage(t *testing.T) {
543+
th.SetupHTTP()
544+
defer th.TeardownHTTP()
545+
546+
MockUnmanageResponse(t)
547+
548+
err := volumes.Unmanage(context.TODO(), client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr()
549+
th.AssertNoErr(t, err)
550+
}

0 commit comments

Comments
 (0)