Adding list events
diff --git a/rackspace/lb/v1/nodes/fixtures.go b/rackspace/lb/v1/nodes/fixtures.go
index de769c7..d5eed13 100644
--- a/rackspace/lb/v1/nodes/fixtures.go
+++ b/rackspace/lb/v1/nodes/fixtures.go
@@ -176,7 +176,7 @@
}
func mockListEventsResponse(t *testing.T, lbID, nodeID int) {
- th.Mux.HandleFunc(_nodeURL(lbID, nodeID), func(w http.ResponseWriter, r *http.Request) {
+ th.Mux.HandleFunc(_nodeURL(lbID, nodeID)+"/events", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
@@ -200,21 +200,6 @@
"title": "Node Status Updated",
"author": "Rackspace Cloud",
"created": "10-30-2012 10:18:23"
- },
- {
- "detailedMessage": "Invalid HTTP response received; premature end of headers",
- "nodeId": 373,
- "id": 8,
- "type": "UPDATE_NODE",
- "description": "Node '373' status changed to 'OFFLINE' for load balancer '323'",
- "category": "UPDATE",
- "severity": "INFO",
- "relativeUri": "/406271/loadbalancers/323/nodes/373/events",
- "accountId": 406271,
- "loadbalancerId": 323,
- "title": "Node Status Updated",
- "author": "Rackspace Cloud",
- "created": "10-30-2012 11:22:25"
}
]
}
diff --git a/rackspace/lb/v1/nodes/requests.go b/rackspace/lb/v1/nodes/requests.go
index c46252b..f3f2850 100644
--- a/rackspace/lb/v1/nodes/requests.go
+++ b/rackspace/lb/v1/nodes/requests.go
@@ -194,11 +194,16 @@
func Delete(c *gophercloud.ServiceClient, lbID, nodeID int) DeleteResult {
var res DeleteResult
-
_, res.Err = perigee.Request("DELETE", resourceURL(c, lbID, nodeID), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
OkCodes: []int{200},
})
-
return res
}
+
+func ListEvents(client *gophercloud.ServiceClient, loadBalancerID, nodeID int) pagination.Pager {
+ url := eventsURL(client, loadBalancerID, nodeID)
+ return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
+ return NodeEventPage{pagination.SinglePageBase(r)}
+ })
+}
diff --git a/rackspace/lb/v1/nodes/requests_test.go b/rackspace/lb/v1/nodes/requests_test.go
index 5951b24..f50dae6 100644
--- a/rackspace/lb/v1/nodes/requests_test.go
+++ b/rackspace/lb/v1/nodes/requests_test.go
@@ -167,3 +167,43 @@
err := Delete(client.ServiceClient(), lbID, nodeID).ExtractErr()
th.AssertNoErr(t, err)
}
+
+func TestListEvents(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ mockListEventsResponse(t, lbID, nodeID)
+
+ count := 0
+
+ err := ListEvents(client.ServiceClient(), lbID, nodeID).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractNodeEvents(page)
+ th.AssertNoErr(t, err)
+
+ expected := []NodeEvent{
+ NodeEvent{
+ DetailedMessage: "Node is ok",
+ NodeID: 373,
+ ID: 7,
+ Type: "UPDATE_NODE",
+ Description: "Node '373' status changed to 'ONLINE' for load balancer '323'",
+ Category: "UPDATE",
+ Severity: "INFO",
+ RelativeURI: "/406271/loadbalancers/323/nodes/373/events",
+ AccountID: 406271,
+ LoadBalancerID: 323,
+ Title: "Node Status Updated",
+ Author: "Rackspace Cloud",
+ Created: "10-30-2012 10:18:23",
+ },
+ }
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, 1, count)
+}
diff --git a/rackspace/lb/v1/nodes/results.go b/rackspace/lb/v1/nodes/results.go
index ca218f9..69a57cd 100644
--- a/rackspace/lb/v1/nodes/results.go
+++ b/rackspace/lb/v1/nodes/results.go
@@ -156,3 +156,41 @@
return &response.Node, err
}
+
+type NodeEvent struct {
+ ID int
+ DetailedMessage string
+ NodeID int
+ Type string
+ Description string
+ Category string
+ Severity string
+ RelativeURI string
+ AccountID int
+ LoadBalancerID int
+ Title string
+ Author string
+ Created string
+}
+
+type NodeEventPage struct {
+ pagination.SinglePageBase
+}
+
+func (r NodeEventPage) IsEmpty() (bool, error) {
+ is, err := ExtractNodeEvents(r)
+ if err != nil {
+ return true, err
+ }
+ return len(is) == 0, nil
+}
+
+func ExtractNodeEvents(page pagination.Page) ([]NodeEvent, error) {
+ var resp struct {
+ Events []NodeEvent `mapstructure:"nodeServiceEvents" json:"nodeServiceEvents"`
+ }
+
+ err := mapstructure.Decode(page.(NodeEventPage).Body, &resp)
+
+ return resp.Events, err
+}
diff --git a/rackspace/lb/v1/nodes/urls.go b/rackspace/lb/v1/nodes/urls.go
index d2ae7c3..69444c8 100644
--- a/rackspace/lb/v1/nodes/urls.go
+++ b/rackspace/lb/v1/nodes/urls.go
@@ -7,8 +7,9 @@
)
const (
- lbPath = "loadbalancers"
- nodePath = "nodes"
+ lbPath = "loadbalancers"
+ nodePath = "nodes"
+ eventPath = "events"
)
func resourceURL(c *gophercloud.ServiceClient, lbID, nodeID int) string {
@@ -18,3 +19,7 @@
func rootURL(c *gophercloud.ServiceClient, lbID int) string {
return c.ServiceURL(lbPath, strconv.Itoa(lbID), nodePath)
}
+
+func eventsURL(c *gophercloud.ServiceClient, lbID, nodeID int) string {
+ return c.ServiceURL(lbPath, strconv.Itoa(lbID), nodePath, strconv.Itoa(nodeID), eventPath)
+}