Adding stats
diff --git a/rackspace/lb/v1/lbs/fixtures.go b/rackspace/lb/v1/lbs/fixtures.go
index a31fe79..5f30ec5 100644
--- a/rackspace/lb/v1/lbs/fixtures.go
+++ b/rackspace/lb/v1/lbs/fixtures.go
@@ -481,3 +481,32 @@
w.WriteHeader(http.StatusOK)
})
}
+
+func mockGetStatsResponse(t *testing.T, id int) {
+ th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/stats", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+
+ fmt.Fprintf(w, `
+{
+ "connectTimeOut": 10,
+ "connectError": 20,
+ "connectFailure": 30,
+ "dataTimedOut": 40,
+ "keepAliveTimedOut": 50,
+ "maxConn": 60,
+ "currentConn": 40,
+ "connectTimeOutSsl": 10,
+ "connectErrorSsl": 20,
+ "connectFailureSsl": 30,
+ "dataTimedOutSsl": 40,
+ "keepAliveTimedOutSsl": 50,
+ "maxConnSsl": 60,
+ "currentConnSsl": 40
+}
+ `)
+ })
+}
diff --git a/rackspace/lb/v1/lbs/requests.go b/rackspace/lb/v1/lbs/requests.go
index 2dd1595..81e7fdc 100644
--- a/rackspace/lb/v1/lbs/requests.go
+++ b/rackspace/lb/v1/lbs/requests.go
@@ -453,6 +453,7 @@
return res
}
+// GetErrorPage will retrieve the current error page for the load balancer.
func GetErrorPage(client *gophercloud.ServiceClient, id int) ErrorPageResult {
var res ErrorPageResult
@@ -465,6 +466,8 @@
return res
}
+// SetErrorPage will set the HTML of the load balancer's error page to a
+// specific value.
func SetErrorPage(client *gophercloud.ServiceClient, id int, html string) ErrorPageResult {
var res ErrorPageResult
@@ -481,6 +484,7 @@
return res
}
+// DeleteErrorPage will delete the current error page for the load balancer.
func DeleteErrorPage(client *gophercloud.ServiceClient, id int) gophercloud.ErrResult {
var res gophercloud.ErrResult
@@ -491,3 +495,16 @@
return res
}
+
+// GetStats will retrieve detailed stats related to the load balancer's usage.
+func GetStats(client *gophercloud.ServiceClient, id int) StatsResult {
+ var res StatsResult
+
+ _, res.Err = perigee.Request("GET", statsURL(client, id), perigee.Options{
+ MoreHeaders: client.AuthenticatedHeaders(),
+ Results: &res.Body,
+ OkCodes: []int{200},
+ })
+
+ return res
+}
diff --git a/rackspace/lb/v1/lbs/requests_test.go b/rackspace/lb/v1/lbs/requests_test.go
index acea25c..59b18e4 100644
--- a/rackspace/lb/v1/lbs/requests_test.go
+++ b/rackspace/lb/v1/lbs/requests_test.go
@@ -334,3 +334,31 @@
err := DeleteErrorPage(client.ServiceClient(), id1).ExtractErr()
th.AssertNoErr(t, err)
}
+
+func TestGetStats(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ mockGetStatsResponse(t, id1)
+
+ content, err := GetStats(client.ServiceClient(), id1).Extract()
+ th.AssertNoErr(t, err)
+
+ expected := &Stats{
+ ConnectTimeout: 10,
+ ConnectError: 20,
+ ConnectFailure: 30,
+ DataTimedOut: 40,
+ KeepAliveTimedOut: 50,
+ MaxConnections: 60,
+ CurrentConnections: 40,
+ SSLConnectTimeout: 10,
+ SSLConnectError: 20,
+ SSLConnectFailure: 30,
+ SSLDataTimedOut: 40,
+ SSLKeepAliveTimedOut: 50,
+ SSLMaxConnections: 60,
+ SSLCurrentConnections: 40,
+ }
+ th.AssertDeepEquals(t, expected, content)
+}
diff --git a/rackspace/lb/v1/lbs/results.go b/rackspace/lb/v1/lbs/results.go
index 21cc2dd..88ed062 100644
--- a/rackspace/lb/v1/lbs/results.go
+++ b/rackspace/lb/v1/lbs/results.go
@@ -308,3 +308,70 @@
return &response.ErrorPage, err
}
+
+// Stats represents all the key information about a load balancer's usage.
+type Stats struct {
+ // The number of connections closed by this load balancer because its
+ // ConnectTimeout interval was exceeded.
+ ConnectTimeout int `mapstructure:"connectTimeOut"`
+
+ // The number of transaction or protocol errors for this load balancer.
+ ConnectError int
+
+ // Number of connection failures for this load balancer.
+ ConnectFailure int
+
+ // Number of connections closed by this load balancer because its Timeout
+ // interval was exceeded.
+ DataTimedOut int
+
+ // Number of connections closed by this load balancer because the
+ // 'keepalive_timeout' interval was exceeded.
+ KeepAliveTimedOut int
+
+ // The maximum number of simultaneous TCP connections this load balancer has
+ // processed at any one time.
+ MaxConnections int `mapstructure:"maxConn"`
+
+ // Number of simultaneous connections active at the time of the request.
+ CurrentConnections int `mapstructure:"currentConn"`
+
+ // Number of SSL connections closed by this load balancer because the
+ // ConnectTimeout interval was exceeded.
+ SSLConnectTimeout int `mapstructure:"connectTimeOutSsl"`
+
+ // Number of SSL transaction or protocol erros in this load balancer.
+ SSLConnectError int `mapstructure:"connectErrorSsl"`
+
+ // Number of SSL connection failures in this load balancer.
+ SSLConnectFailure int `mapstructure:"connectFailureSsl"`
+
+ // Number of SSL connections closed by this load balancer because the
+ // Timeout interval was exceeded.
+ SSLDataTimedOut int `mapstructure:"dataTimedOutSsl"`
+
+ // Number of SSL connections closed by this load balancer because the
+ // 'keepalive_timeout' interval was exceeded.
+ SSLKeepAliveTimedOut int `mapstructure:"keepAliveTimedOutSsl"`
+
+ // Maximum number of simultaneous SSL connections this load balancer has
+ // processed a any one time.
+ SSLMaxConnections int `mapstructure:"maxConnSsl"`
+
+ // Number of simultaneous SSL connections active at the time of the request.
+ SSLCurrentConnections int `mapstructure:"currentConnSsl"`
+}
+
+type StatsResult struct {
+ gophercloud.Result
+}
+
+// Extract interprets any commonResult as a Stats struct, if possible.
+func (r StatsResult) Extract() (*Stats, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+ res := &Stats{}
+ err := mapstructure.Decode(r.Body, res)
+ return res, err
+}
diff --git a/rackspace/lb/v1/lbs/urls.go b/rackspace/lb/v1/lbs/urls.go
index bf1e8b5..f647073 100644
--- a/rackspace/lb/v1/lbs/urls.go
+++ b/rackspace/lb/v1/lbs/urls.go
@@ -12,6 +12,7 @@
algorithmsPath = "algorithms"
logPath = "connectionlogging"
epPath = "errorpage"
+ stPath = "stats"
)
func resourceURL(c *gophercloud.ServiceClient, id int) string {
@@ -37,3 +38,7 @@
func errorPageURL(c *gophercloud.ServiceClient, id int) string {
return c.ServiceURL(path, strconv.Itoa(id), epPath)
}
+
+func statsURL(c *gophercloud.ServiceClient, id int) string {
+ return c.ServiceURL(path, strconv.Itoa(id), stPath)
+}
diff --git a/rackspace/lb/v1/sessions/requests.go b/rackspace/lb/v1/sessions/requests.go
index fe6751a..9853ad1 100644
--- a/rackspace/lb/v1/sessions/requests.go
+++ b/rackspace/lb/v1/sessions/requests.go
@@ -48,7 +48,7 @@
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
- OkCodes: []int{200},
+ OkCodes: []int{202},
})
return res
@@ -75,7 +75,7 @@
_, res.Err = perigee.Request("DELETE", rootURL(c, lbID), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
- OkCodes: []int{200},
+ OkCodes: []int{202},
})
return res