Skip to content

Commit cf81d92

Browse files
TommyLikejtopjian
authored andcommitted
Add DELETE support in V3 volume types (gophercloud#655)
* Add basic CRUD support in volume v3 types Add Create/Delete/List/Update/Get support for volume type in volume V3. * Support volume type delete in V3 Support volume type delete in V3
1 parent bb23281 commit cf81d92

7 files changed

Lines changed: 44 additions & 1 deletion

File tree

acceptance/openstack/blockstorage/v3/volumetypes_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestVolumeTypesList(t *testing.T) {
4545
}
4646
}
4747

48-
func TestVolumeTypesCreate(t *testing.T) {
48+
func TestVolumeTypesCreateDestroy(t *testing.T) {
4949
client, err := clients.NewBlockStorageV3Client()
5050
if err != nil {
5151
t.Fatalf("Unable to create a blockstorage client: %v", err)
@@ -64,4 +64,6 @@ func TestVolumeTypesCreate(t *testing.T) {
6464
}
6565

6666
tools.PrintResource(t, vt)
67+
68+
defer volumetypes.Delete(client, vt.ID)
6769
}

openstack/blockstorage/v3/volumetypes/doc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ Example to create a Volume Type
3737
panic(err)
3838
}
3939
fmt.Println(volumeType)
40+
41+
Example to delete a Volume TYpe
42+
43+
typeID := "0fe36e73809d46aeae6705c39077b1b3"
44+
err := volumetypes.Delete(client, typeID).ExtractErr()
45+
if err != nil{
46+
panic(err)
47+
}
4048
*/
4149

4250
package volumetypes

openstack/blockstorage/v3/volumetypes/requests.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r Create
4646
return
4747
}
4848

49+
// Delete will delete the existing Volume Type with the provided ID.
50+
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
51+
_, r.Err = client.Delete(deleteURL(client, id), nil)
52+
return
53+
}
54+
4955
// Get retrieves the Volume Type with the provided ID. To extract the Volume Type object
5056
// from the response, call the Extract method on the GetResult.
5157
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {

openstack/blockstorage/v3/volumetypes/results.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ type GetResult struct {
8282
type CreateResult struct {
8383
commonResult
8484
}
85+
86+
// DeleteResult contains the response body and error from a Delete request.
87+
type DeleteResult struct {
88+
gophercloud.ErrResult
89+
}

openstack/blockstorage/v3/volumetypes/testing/fixtures.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,11 @@ func MockCreateResponse(t *testing.T) {
127127
`)
128128
})
129129
}
130+
131+
func MockDeleteResponse(t *testing.T) {
132+
th.Mux.HandleFunc("/types/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
133+
th.TestMethod(t, r, "DELETE")
134+
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
135+
w.WriteHeader(http.StatusAccepted)
136+
})
137+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,13 @@ func TestCreate(t *testing.T) {
8181
th.AssertEquals(t, n.ID, "6d0ff92a-0007-4780-9ece-acfe5876966a")
8282
th.AssertEquals(t, n.ExtraSpecs["capabilities"], "gpu")
8383
}
84+
85+
func TestDelete(t *testing.T) {
86+
th.SetupHTTP()
87+
defer th.TeardownHTTP()
88+
89+
MockDeleteResponse(t)
90+
91+
res := volumetypes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
92+
th.AssertNoErr(t, res.Err)
93+
}

openstack/blockstorage/v3/volumetypes/urls.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ func geturl(c *gophercloud.ServiceClient, id string) string {
1313
func createURL(c *gophercloud.ServiceClient) string {
1414
return c.ServiceURL("types")
1515
}
16+
17+
func deleteURL(c *gophercloud.ServiceClient, id string) string {
18+
return c.ServiceURL("types", id)
19+
}

0 commit comments

Comments
 (0)