Merge pull request #421 from ZettaIO/serveraction-createimage
server action to create a server image / snapshot
diff --git a/openstack/compute/v2/images/requests.go b/openstack/compute/v2/images/requests.go
index 5eb19b5..7ce5139 100644
--- a/openstack/compute/v2/images/requests.go
+++ b/openstack/compute/v2/images/requests.go
@@ -63,3 +63,10 @@
_, result.Err = client.Get(getURL(client, id), &result.Body, nil)
return result
}
+
+// Delete deletes the specified image ID.
+func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
+ var result DeleteResult
+ _, result.Err = client.Delete(deleteURL(client, id), nil)
+ return result
+}
diff --git a/openstack/compute/v2/images/requests_test.go b/openstack/compute/v2/images/requests_test.go
index 9a05f97..93a97bd 100644
--- a/openstack/compute/v2/images/requests_test.go
+++ b/openstack/compute/v2/images/requests_test.go
@@ -173,3 +173,19 @@
th.AssertNoErr(t, err)
th.CheckEquals(t, expected, actual)
}
+
+// Test Image delete
+func TestDeleteImage(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ th.Mux.HandleFunc("/images/12345678", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ res := Delete(fake.ServiceClient(), "12345678")
+ th.AssertNoErr(t, res.Err)
+}
diff --git a/openstack/compute/v2/images/results.go b/openstack/compute/v2/images/results.go
index 493d511..40e814d 100644
--- a/openstack/compute/v2/images/results.go
+++ b/openstack/compute/v2/images/results.go
@@ -11,6 +11,11 @@
gophercloud.Result
}
+// DeleteResult represents the result of an image.Delete operation.
+type DeleteResult struct {
+ gophercloud.ErrResult
+}
+
// Extract interprets a GetResult as an Image.
func (gr GetResult) Extract() (*Image, error) {
if gr.Err != nil {
diff --git a/openstack/compute/v2/images/urls.go b/openstack/compute/v2/images/urls.go
index 9b3c86d..b1bf103 100644
--- a/openstack/compute/v2/images/urls.go
+++ b/openstack/compute/v2/images/urls.go
@@ -9,3 +9,7 @@
func getURL(client *gophercloud.ServiceClient, id string) string {
return client.ServiceURL("images", id)
}
+
+func deleteURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("images", id)
+}