Adds block storage extend's action support (#67)
* created Godeps dependency tree
* added vendor folder to gitignore
* added support for extend size action to volumes's client
* Revert "created Godeps dependency tree"
This reverts commit b9366e292c2e99e262240b98151c98f49c69df32.
* Revert "added vendor folder to gitignore"
This reverts commit 34403f85dad4f0514d7e0d8ce882b1712b82cd87.
* set volumeactions.ExtendSizeOpts.NewSize as required
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/requests.go b/openstack/blockstorage/v2/extensions/volumeactions/requests.go
index 05a76f7..d2a2c79 100644
--- a/openstack/blockstorage/v2/extensions/volumeactions/requests.go
+++ b/openstack/blockstorage/v2/extensions/volumeactions/requests.go
@@ -172,3 +172,36 @@
})
return
}
+
+// ExtendSizeOptsBuilder allows extensions to add additional parameters to the
+// ExtendSize request.
+type ExtendSizeOptsBuilder interface {
+ ToVolumeExtendSizeMap() (map[string]interface{}, error)
+}
+
+// ExtendSizeOpts contain options for extending the size of an existing Volume. This object is passed
+// to the volumes.ExtendSize function.
+type ExtendSizeOpts struct {
+ // NewSize is the new size of the volume, in GB
+ NewSize int `json:"new_size" required:"true"`
+}
+
+// ToVolumeExtendSizeMap assembles a request body based on the contents of an
+// ExtendSizeOpts.
+func (opts ExtendSizeOpts) ToVolumeExtendSizeMap() (map[string]interface{}, error) {
+ return gophercloud.BuildRequestBody(opts, "os-extend")
+}
+
+// ExtendSize will extend the size of the volume based on the provided information.
+// This operation does not return a response body.
+func ExtendSize(client *gophercloud.ServiceClient, id string, opts ExtendSizeOptsBuilder) (r ExtendSizeResult) {
+ b, err := opts.ToVolumeExtendSizeMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+ _, r.Err = client.Post(extendSizeURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{202},
+ })
+ return
+}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/results.go b/openstack/blockstorage/v2/extensions/volumeactions/results.go
index 9bf6a7b..f9e8120 100644
--- a/openstack/blockstorage/v2/extensions/volumeactions/results.go
+++ b/openstack/blockstorage/v2/extensions/volumeactions/results.go
@@ -44,3 +44,8 @@
type InitializeConnectionResult struct {
commonResult
}
+
+// ExtendSizeResult contains the response body and error from an ExtendSize request.
+type ExtendSizeResult struct {
+ gophercloud.ErrResult
+}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/testing/fixtures.go b/openstack/blockstorage/v2/extensions/volumeactions/testing/fixtures.go
index da661a6..34df070 100644
--- a/openstack/blockstorage/v2/extensions/volumeactions/testing/fixtures.go
+++ b/openstack/blockstorage/v2/extensions/volumeactions/testing/fixtures.go
@@ -181,3 +181,26 @@
fmt.Fprintf(w, `{}`)
})
}
+
+func MockExtendSizeResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
+ func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "os-extend":
+ {
+ "new_size": 3
+ }
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `{}`)
+ })
+}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/testing/requests_test.go b/openstack/blockstorage/v2/extensions/volumeactions/testing/requests_test.go
index dac4e01..38a5bd2 100644
--- a/openstack/blockstorage/v2/extensions/volumeactions/testing/requests_test.go
+++ b/openstack/blockstorage/v2/extensions/volumeactions/testing/requests_test.go
@@ -89,3 +89,17 @@
err := volumeactions.TerminateConnection(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
th.AssertNoErr(t, err)
}
+
+func TestExtendSize(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockExtendSizeResponse(t)
+
+ options := &volumeactions.ExtendSizeOpts{
+ NewSize: 3,
+ }
+
+ err := volumeactions.ExtendSize(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
+ th.AssertNoErr(t, err)
+}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/urls.go b/openstack/blockstorage/v2/extensions/volumeactions/urls.go
index 4ddcca0..a61ee7d 100644
--- a/openstack/blockstorage/v2/extensions/volumeactions/urls.go
+++ b/openstack/blockstorage/v2/extensions/volumeactions/urls.go
@@ -25,3 +25,7 @@
func teminateConnectionURL(c *gophercloud.ServiceClient, id string) string {
return attachURL(c, id)
}
+
+func extendSizeURL(c *gophercloud.ServiceClient, id string) string {
+ return attachURL(c, id)
+}