From f08a3288280dde5efc7e934854f4f920c99a8534 Mon Sep 17 00:00:00 2001 From: "simranjit.nagra" Date: Mon, 17 Sep 2018 11:06:38 +0530 Subject: [PATCH 1/2] update delete interface --- openstack/blockstorage/v2/volumes/requests.go | 31 +++++++++++++++++-- .../v2/volumes/testing/requests_test.go | 3 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/openstack/blockstorage/v2/volumes/requests.go b/openstack/blockstorage/v2/volumes/requests.go index df81e933c..b6dfc83d4 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) + + 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) } From a6189c3cbd01cdc3f5f1fabf9b518092e751cf09 Mon Sep 17 00:00:00 2001 From: "simranjit.nagra" Date: Thu, 27 Sep 2018 15:03:10 +0530 Subject: [PATCH 2/2] modify delete function with nil check --- openstack/blockstorage/v2/volumes/requests.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openstack/blockstorage/v2/volumes/requests.go b/openstack/blockstorage/v2/volumes/requests.go index b6dfc83d4..bb3ef8afd 100644 --- a/openstack/blockstorage/v2/volumes/requests.go +++ b/openstack/blockstorage/v2/volumes/requests.go @@ -80,14 +80,14 @@ func (opts DeleteOpts) ToVolumeDeleteQuery() (string, error) { //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) - - q, err := opts.ToVolumeDeleteQuery() - if err != nil { - r.Err = err - return + if opts != nil { + q, err := opts.ToVolumeDeleteQuery() + if err != nil { + r.Err = err + return + } + url += q } - - url += q _, r.Err = client.Delete(url, nil) return }