Adding support for get node operation
diff --git a/rackspace/lb/v1/nodes/fixtures.go b/rackspace/lb/v1/nodes/fixtures.go
index f0c034c..3d0993c 100644
--- a/rackspace/lb/v1/nodes/fixtures.go
+++ b/rackspace/lb/v1/nodes/fixtures.go
@@ -14,6 +14,10 @@
return "/loadbalancers/" + strconv.Itoa(lbID) + "/nodes"
}
+func _nodeURL(lbID, nodeID int) string {
+ return _rootURL(lbID) + "/" + strconv.Itoa(nodeID)
+}
+
func mockListResponse(t *testing.T, lbID int) {
th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
@@ -119,16 +123,16 @@
})
}
-func mockDeleteLBResponse(t *testing.T, id int) {
- th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), func(w http.ResponseWriter, r *http.Request) {
+func mockDeleteLBResponse(t *testing.T, lbID, nodeID int) {
+ th.Mux.HandleFunc(_nodeURL(lbID, nodeID), func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.WriteHeader(http.StatusAccepted)
})
}
-func mockGetResponse(t *testing.T, id int) {
- th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), func(w http.ResponseWriter, r *http.Request) {
+func mockGetResponse(t *testing.T, lbID, nodeID int) {
+ th.Mux.HandleFunc(_nodeURL(lbID, nodeID), func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
@@ -151,8 +155,8 @@
})
}
-func mockUpdateResponse(t *testing.T, id int) {
- th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), func(w http.ResponseWriter, r *http.Request) {
+func mockUpdateResponse(t *testing.T, lbID, nodeID int) {
+ th.Mux.HandleFunc(_nodeURL(lbID, nodeID), func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
@@ -169,8 +173,8 @@
})
}
-func mockListEventsResponse(t *testing.T) {
- th.Mux.HandleFunc("/loadbalancers", func(w http.ResponseWriter, r *http.Request) {
+func mockListEventsResponse(t *testing.T, lbID, nodeID int) {
+ th.Mux.HandleFunc(_nodeURL(lbID, nodeID), func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
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 e794197..0ce8ca1 100644
--- a/rackspace/lb/v1/nodes/requests.go
+++ b/rackspace/lb/v1/nodes/requests.go
@@ -110,3 +110,15 @@
return res
}
+
+func Get(c *gophercloud.ServiceClient, lbID, nodeID int) GetResult {
+ var res GetResult
+
+ _, res.Err = perigee.Request("GET", resourceURL(c, lbID, nodeID), perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ Results: &res.Body,
+ OkCodes: []int{200},
+ })
+
+ return res
+}
diff --git a/rackspace/lb/v1/nodes/requests_test.go b/rackspace/lb/v1/nodes/requests_test.go
index 090f4fa..5fdeadd 100644
--- a/rackspace/lb/v1/nodes/requests_test.go
+++ b/rackspace/lb/v1/nodes/requests_test.go
@@ -118,3 +118,25 @@
err := BulkDelete(client.ServiceClient(), lbID, ids).ExtractErr()
th.AssertNoErr(t, err)
}
+
+func TestGet(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ mockGetResponse(t, lbID, nodeID)
+
+ node, err := Get(client.ServiceClient(), lbID, nodeID).Extract()
+ th.AssertNoErr(t, err)
+
+ expected := &Node{
+ ID: 410,
+ Address: "10.1.1.1",
+ Port: 80,
+ Condition: ENABLED,
+ Status: ONLINE,
+ Weight: 12,
+ Type: PRIMARY,
+ }
+
+ th.AssertDeepEquals(t, expected, node)
+}
diff --git a/rackspace/lb/v1/nodes/results.go b/rackspace/lb/v1/nodes/results.go
index 449d7f6..b514217 100644
--- a/rackspace/lb/v1/nodes/results.go
+++ b/rackspace/lb/v1/nodes/results.go
@@ -130,3 +130,25 @@
type DeleteResult struct {
gophercloud.ErrResult
}
+
+type commonResult struct {
+ gophercloud.Result
+}
+
+type GetResult struct {
+ commonResult
+}
+
+func (r commonResult) Extract() (*Node, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+
+ var response struct {
+ Node Node `mapstructure:"node"`
+ }
+
+ err := mapstructure.Decode(r.Body, &response)
+
+ return &response.Node, err
+}