Rackspace Auto Scale: Add policies Execute()
diff --git a/rackspace/autoscale/v1/policies/fixtures.go b/rackspace/autoscale/v1/policies/fixtures.go
index a0ce86e..ac54268 100644
--- a/rackspace/autoscale/v1/policies/fixtures.go
+++ b/rackspace/autoscale/v1/policies/fixtures.go
@@ -241,3 +241,19 @@
w.WriteHeader(http.StatusNoContent)
})
}
+
+// HandlePolicyExecuteSuccessfully sets up the test server to respond to a policies Execute request.
+func HandlePolicyExecuteSuccessfully(t *testing.T) {
+ groupID := "60b15dad-5ea1-43fa-9a12-a1d737b4da07"
+ policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649"
+
+ path := fmt.Sprintf("/groups/%s/policies/%s/execute", groupID, policyID)
+
+ th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+
+ w.WriteHeader(http.StatusAccepted)
+ fmt.Fprintf(w, "{}")
+ })
+}
diff --git a/rackspace/autoscale/v1/policies/requests.go b/rackspace/autoscale/v1/policies/requests.go
index 1ce7b11..8b56c2e 100644
--- a/rackspace/autoscale/v1/policies/requests.go
+++ b/rackspace/autoscale/v1/policies/requests.go
@@ -216,3 +216,15 @@
return result
}
+
+// Execute requests the given policy be executed immediately.
+func Execute(client *gophercloud.ServiceClient, groupID, policyID string) ExecuteResult {
+ var result ExecuteResult
+
+ url := executeURL(client, groupID, policyID)
+ _, result.Err = client.Post(url, nil, &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{202},
+ })
+
+ return result
+}
diff --git a/rackspace/autoscale/v1/policies/requests_test.go b/rackspace/autoscale/v1/policies/requests_test.go
index 5684595..61b94e9 100644
--- a/rackspace/autoscale/v1/policies/requests_test.go
+++ b/rackspace/autoscale/v1/policies/requests_test.go
@@ -140,3 +140,14 @@
th.AssertNoErr(t, err)
}
+
+func TestExecute(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandlePolicyExecuteSuccessfully(t)
+
+ client := client.ServiceClient()
+ err := Execute(client, groupID, webhookPolicyID).ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
diff --git a/rackspace/autoscale/v1/policies/results.go b/rackspace/autoscale/v1/policies/results.go
index 20cd2ee..b304e9d 100644
--- a/rackspace/autoscale/v1/policies/results.go
+++ b/rackspace/autoscale/v1/policies/results.go
@@ -57,6 +57,11 @@
gophercloud.ErrResult
}
+// ExecuteResult represents the result of an execute operation.
+type ExecuteResult struct {
+ gophercloud.ErrResult
+}
+
// Policy represents a scaling policy.
type Policy struct {
// UUID for the policy.
diff --git a/rackspace/autoscale/v1/policies/urls.go b/rackspace/autoscale/v1/policies/urls.go
index 27efb3e..8ee3207 100644
--- a/rackspace/autoscale/v1/policies/urls.go
+++ b/rackspace/autoscale/v1/policies/urls.go
@@ -21,3 +21,7 @@
func deleteURL(c *gophercloud.ServiceClient, groupID, policyID string) string {
return getURL(c, groupID, policyID)
}
+
+func executeURL(c *gophercloud.ServiceClient, groupID, policyID string) string {
+ return c.ServiceURL("groups", groupID, "policies", policyID, "execute")
+}