Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
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
31 changes: 28 additions & 3 deletions openstack/blockstorage/v2/volumes/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,34 @@ func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateRe
return
}

// Delete will delete the existing Volume with the provided ID.
func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
_, r.Err = client.Delete(deleteURL(client, id), nil)
//DeleteOptsBuilder is an interface by which can be able to build the query string
//of volume deletion.
type DeleteOptsBuilder interface {
ToVolumeDeleteQuery() (string, error)
}

type DeleteOpts struct {
//Specifies to delete all snapshots associated with the EVS disk.
Cascade bool `q:"cascade"`
}

func (opts DeleteOpts) ToVolumeDeleteQuery() (string, error) {
q, err := golangsdk.BuildQueryString(opts)
return q.String(), err
}

//Delete will delete the existing Volume with the provided ID
func Delete(client *golangsdk.ServiceClient, id string, opts DeleteOptsBuilder) (r DeleteResult) {
url := deleteURL(client, id)
if opts != nil {
q, err := opts.ToVolumeDeleteQuery()
if err != nil {
r.Err = err
return
}
url += q
}
_, r.Err = client.Delete(url, nil)
return
}

Expand Down
3 changes: 2 additions & 1 deletion openstack/blockstorage/v2/volumes/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func TestDelete(t *testing.T) {

MockDeleteResponse(t)

res := volumes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
deleteOpts := volumes.DeleteOpts{}
res := volumes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", deleteOpts)
th.AssertNoErr(t, res.Err)
}

Expand Down