Adding batch delete nodes
diff --git a/rackspace/lb/v1/nodes/fixtures.go b/rackspace/lb/v1/nodes/fixtures.go
index 65eefe0..f0c034c 100644
--- a/rackspace/lb/v1/nodes/fixtures.go
+++ b/rackspace/lb/v1/nodes/fixtures.go
@@ -103,8 +103,8 @@
})
}
-func mockBatchDeleteLBResponse(t *testing.T, ids []int) {
- th.Mux.HandleFunc("/loadbalancers", func(w http.ResponseWriter, r *http.Request) {
+func mockBatchDeleteResponse(t *testing.T, lbID int, ids []int) {
+ th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
diff --git a/rackspace/lb/v1/nodes/requests.go b/rackspace/lb/v1/nodes/requests.go
index 338c250..abf7037 100644
--- a/rackspace/lb/v1/nodes/requests.go
+++ b/rackspace/lb/v1/nodes/requests.go
@@ -2,6 +2,7 @@
import (
"fmt"
+ "strconv"
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
@@ -89,3 +90,24 @@
return CreateResult{pagination.SinglePageBase(pr)}
}
+
+func BulkDelete(c *gophercloud.ServiceClient, loadBalancerID int, nodeIDs []int) DeleteResult {
+ var res DeleteResult
+
+ url := rootURL(c, loadBalancerID)
+ for k, v := range nodeIDs {
+ if k == 0 {
+ url += "?"
+ } else {
+ url += "&"
+ }
+ url += "id=" + strconv.Itoa(v)
+ }
+
+ _, res.Err = perigee.Request("DELETE", url, perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ OkCodes: []int{202},
+ })
+
+ return res
+}
diff --git a/rackspace/lb/v1/nodes/requests_test.go b/rackspace/lb/v1/nodes/requests_test.go
index 8e4813f..090f4fa 100644
--- a/rackspace/lb/v1/nodes/requests_test.go
+++ b/rackspace/lb/v1/nodes/requests_test.go
@@ -9,8 +9,9 @@
)
const (
- lbID = 12345
- nodeID = 67890
+ lbID = 12345
+ nodeID = 67890
+ nodeID2 = 67891
)
func TestList(t *testing.T) {
@@ -105,3 +106,15 @@
th.CheckDeepEquals(t, expected, actual)
}
+
+func TestBulkDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ ids := []int{nodeID, nodeID2}
+
+ mockBatchDeleteResponse(t, lbID, ids)
+
+ err := BulkDelete(client.ServiceClient(), lbID, ids).ExtractErr()
+ th.AssertNoErr(t, err)
+}
diff --git a/rackspace/lb/v1/nodes/results.go b/rackspace/lb/v1/nodes/results.go
index 399f5c9..449d7f6 100644
--- a/rackspace/lb/v1/nodes/results.go
+++ b/rackspace/lb/v1/nodes/results.go
@@ -2,7 +2,7 @@
import (
"github.com/mitchellh/mapstructure"
-
+ "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
)
@@ -116,9 +116,9 @@
}
// CreateResult represents the result of a create operation. Since multiple
-// nodes can be added in one operation, this result represents multiple nodes -
-// and should be treated as a typical pagination Page. Use ExtractNodes to get
-// out a slice of Node structs.
+// nodes can be added in one operation, this result represents multiple nodes
+// and should be treated as a typical pagination Page. Use its ExtractNodes
+// method to get out a slice of Node structs.
type CreateResult struct {
pagination.SinglePageBase
}
@@ -126,3 +126,7 @@
func (res CreateResult) ExtractNodes() ([]Node, error) {
return commonExtractNodes(res.Body)
}
+
+type DeleteResult struct {
+ gophercloud.ErrResult
+}