changes after PR review
diff --git a/rackspace/rackconnect/v3/lbpools/doc.go b/rackspace/rackconnect/v3/lbpools/doc.go
index 68e5f67..f4319b8 100644
--- a/rackspace/rackconnect/v3/lbpools/doc.go
+++ b/rackspace/rackconnect/v3/lbpools/doc.go
@@ -1,6 +1,6 @@
// Package lbpools provides access to load balancer pools associated with a
// RackConnect configuration. Load Balancer Pools must be configured in advance
-// by your Network Security team to be elegible for use with RackConnect.
+// by your Network Security team to be eligible for use with RackConnect.
// If you do not see a pool that you expect to see, contact your Support team
// for further assistance. The Load Balancer Pool id returned by these calls is
// automatically generated by the RackConnect automation and will remain constant
diff --git a/rackspace/rackconnect/v3/lbpools/requests.go b/rackspace/rackconnect/v3/lbpools/requests.go
index 23425d0..4b4a103 100644
--- a/rackspace/rackconnect/v3/lbpools/requests.go
+++ b/rackspace/rackconnect/v3/lbpools/requests.go
@@ -94,27 +94,41 @@
return res
}
-// NodesOpts are options for bulk adding/deleting nodes to LB pools.
-type NodesOpts struct {
+// NodeOpts are options for bulk adding/deleting nodes to LB pools.
+type NodeOpts struct {
ServerID string
PoolID string
}
-// CreateNodes adds the cloud servers with the given serverIDs to the corresponding
-// load balancer pools with the given poolIDs.
-func CreateNodes(c *gophercloud.ServiceClient, opts []NodesOpts) CreateNodesResult {
- var res CreateNodesResult
- reqBody := make([]map[string]interface{}, len(opts))
- for i := range opts {
- reqBody[i] = map[string]interface{}{
+// NodesOpts are a slice of NodeOpts, passed as options for bulk operations.
+type NodesOpts []NodeOpts
+
+// ToLBPoolCreateNodesMap serializes a NodesOpts into a map to send in the request.
+func (o NodesOpts) ToLBPoolCreateNodesMap() ([]map[string]interface{}, error) {
+ m := make([]map[string]interface{}, len(o))
+ for i := range o {
+ m[i] = map[string]interface{}{
"cloud_server": map[string]string{
- "id": opts[i].ServerID,
+ "id": o[i].ServerID,
},
"load_balancer_pool": map[string]string{
- "id": opts[i].PoolID,
+ "id": o[i].PoolID,
},
}
}
+ return m, nil
+}
+
+// CreateNodes adds the cloud servers with the given serverIDs to the corresponding
+// load balancer pools with the given poolIDs.
+func CreateNodes(c *gophercloud.ServiceClient, opts NodesOpts) CreateNodesResult {
+ var res CreateNodesResult
+ reqBody, err := opts.ToLBPoolCreateNodesMap()
+ if err != nil {
+ res.Err = err
+ return res
+ }
+
_, res.Err = c.Request("POST", createNodesURL(c), gophercloud.RequestOpts{
JSONBody: &reqBody,
JSONResponse: &res.Body,
@@ -125,19 +139,14 @@
// DeleteNodes removes the cloud servers with the given serverIDs to the corresponding
// load balancer pools with the given poolIDs.
-func DeleteNodes(c *gophercloud.ServiceClient, opts []NodesOpts) DeleteNodesResult {
+func DeleteNodes(c *gophercloud.ServiceClient, opts NodesOpts) DeleteNodesResult {
var res DeleteNodesResult
- reqBody := make([]map[string]interface{}, len(opts))
- for i := range opts {
- reqBody[i] = map[string]interface{}{
- "cloud_server": map[string]string{
- "id": opts[i].ServerID,
- },
- "load_balancer_pool": map[string]string{
- "id": opts[i].PoolID,
- },
- }
+ reqBody, err := opts.ToLBPoolCreateNodesMap()
+ if err != nil {
+ res.Err = err
+ return res
}
+
_, res.Err = c.Request("DELETE", createNodesURL(c), gophercloud.RequestOpts{
JSONBody: &reqBody,
OkCodes: []int{204},
@@ -145,8 +154,8 @@
return res
}
-// ListNodesDetailsForServer returns all load balancer pool nodes that are associated with RackConnect
-// for the given LB pool ID with all their details for the server with the given serverID.
+// ListNodesDetailsForServer is similar to ListNodesDetails but only returns nodes
+// for the given serverID.
func ListNodesDetailsForServer(c *gophercloud.ServiceClient, serverID string) pagination.Pager {
url := listNodesForServerURL(c, serverID)
createPage := func(r pagination.PageResult) pagination.Page {
diff --git a/rackspace/rackconnect/v3/lbpools/requests_test.go b/rackspace/rackconnect/v3/lbpools/requests_test.go
index 4cf7214..48ebcec 100644
--- a/rackspace/rackconnect/v3/lbpools/requests_test.go
+++ b/rackspace/rackconnect/v3/lbpools/requests_test.go
@@ -741,12 +741,12 @@
},
}
- opts := []NodesOpts{
- NodesOpts{
+ opts := NodesOpts{
+ NodeOpts{
ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
PoolID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
},
- NodesOpts{
+ NodeOpts{
ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
PoolID: "33021100-4abf-4836-9080-465a6d87ab68",
},
@@ -788,12 +788,12 @@
w.WriteHeader(http.StatusNoContent)
})
- opts := []NodesOpts{
- NodesOpts{
+ opts := NodesOpts{
+ NodeOpts{
ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
PoolID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
},
- NodesOpts{
+ NodeOpts{
ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
PoolID: "33021100-4abf-4836-9080-465a6d87ab68",
},