diff --git a/openstack/blockstorage/v2/volumes/requests.go b/openstack/blockstorage/v2/volumes/requests.go index df81e933c..bb3ef8afd 100644 --- a/openstack/blockstorage/v2/volumes/requests.go +++ b/openstack/blockstorage/v2/volumes/requests.go @@ -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 } diff --git a/openstack/blockstorage/v2/volumes/testing/requests_test.go b/openstack/blockstorage/v2/volumes/testing/requests_test.go index abd1188f5..1f428c163 100644 --- a/openstack/blockstorage/v2/volumes/testing/requests_test.go +++ b/openstack/blockstorage/v2/volumes/testing/requests_test.go @@ -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) }