Adding support for getting LB
diff --git a/rackspace/lb/lb/fixtures.go b/rackspace/lb/lb/fixtures.go
index 7cdcb0f..19a605d 100644
--- a/rackspace/lb/lb/fixtures.go
+++ b/rackspace/lb/lb/fixtures.go
@@ -159,3 +159,77 @@
w.WriteHeader(http.StatusAccepted)
})
}
+
+func mockGetLBResponse(t *testing.T, id int) {
+ th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), 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, `
+{
+ "loadBalancer": {
+ "id": 2000,
+ "name": "sample-loadbalancer",
+ "protocol": "HTTP",
+ "port": 80,
+ "algorithm": "RANDOM",
+ "status": "ACTIVE",
+ "timeout": 30,
+ "connectionLogging": {
+ "enabled": true
+ },
+ "virtualIps": [
+ {
+ "id": 1000,
+ "address": "206.10.10.210",
+ "type": "PUBLIC",
+ "ipVersion": "IPV4"
+ }
+ ],
+ "nodes": [
+ {
+ "id": 1041,
+ "address": "10.1.1.1",
+ "port": 80,
+ "condition": "ENABLED",
+ "status": "ONLINE"
+ },
+ {
+ "id": 1411,
+ "address": "10.1.1.2",
+ "port": 80,
+ "condition": "ENABLED",
+ "status": "ONLINE"
+ }
+ ],
+ "sessionPersistence": {
+ "persistenceType": "HTTP_COOKIE"
+ },
+ "connectionThrottle": {
+ "minConnections": 10,
+ "maxConnections": 100,
+ "maxConnectionRate": 50,
+ "rateInterval": 60
+ },
+ "cluster": {
+ "name": "c1.dfw1"
+ },
+ "created": {
+ "time": "2010-11-30T03:23:42Z"
+ },
+ "updated": {
+ "time": "2010-11-30T03:23:44Z"
+ },
+ "sourceAddresses": {
+ "ipv6Public": "2001:4801:79f1:1::1/64",
+ "ipv4Servicenet": "10.0.0.0",
+ "ipv4Public": "10.12.99.28"
+ }
+ }
+}
+ `)
+ })
+}
diff --git a/rackspace/lb/lb/requests.go b/rackspace/lb/lb/requests.go
index 0be2d4a..81a8642 100644
--- a/rackspace/lb/lb/requests.go
+++ b/rackspace/lb/lb/requests.go
@@ -227,6 +227,18 @@
return res
}
+func Get(c *gophercloud.ServiceClient, id int) GetResult {
+ var res GetResult
+
+ _, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ Results: &res.Body,
+ OkCodes: []int{200},
+ })
+
+ return res
+}
+
func BulkDelete(c *gophercloud.ServiceClient, ids []int) DeleteResult {
var res DeleteResult
diff --git a/rackspace/lb/lb/requests_test.go b/rackspace/lb/lb/requests_test.go
index 2ee81d3..6f9417f 100644
--- a/rackspace/lb/lb/requests_test.go
+++ b/rackspace/lb/lb/requests_test.go
@@ -8,6 +8,11 @@
"github.com/rackspace/gophercloud/testhelper/client"
)
+const (
+ id1 = 12345
+ id2 = 67890
+)
+
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -120,7 +125,7 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- ids := []int{12345, 67890}
+ ids := []int{id1, id2}
mockBatchDeleteLBResponse(t, ids)
@@ -132,14 +137,70 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- id := 12345
+ mockDeleteLBResponse(t, id1)
- mockDeleteLBResponse(t, id)
-
- err := Delete(client.ServiceClient(), id).ExtractErr()
+ err := Delete(client.ServiceClient(), id1).ExtractErr()
th.AssertNoErr(t, err)
}
func TestGet(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ mockGetLBResponse(t, id1)
+
+ lb, err := Get(client.ServiceClient(), id1).Extract()
+
+ expected := &LoadBalancer{
+ Name: "sample-loadbalancer",
+ ID: 2000,
+ Protocol: "HTTP",
+ Port: 80,
+ Algorithm: RAND,
+ Status: ACTIVE,
+ Timeout: 30,
+ ConnectionLogging: ConnectionLogging{Enabled: true},
+ VIPs: []VIP{
+ VIP{
+ ID: 1000,
+ Address: "206.10.10.210",
+ Type: "PUBLIC",
+ Version: "IPV4",
+ },
+ },
+ Nodes: []Node{
+ Node{
+ Address: "10.1.1.1",
+ ID: 1041,
+ Port: 80,
+ Status: "ONLINE",
+ Condition: "ENABLED",
+ },
+ Node{
+ Address: "10.1.1.2",
+ ID: 1411,
+ Port: 80,
+ Status: "ONLINE",
+ Condition: "ENABLED",
+ },
+ },
+ SessionPersistence: SessionPersistence{Type: "HTTP_COOKIE"},
+ ConnectionThrottle: ConnectionThrottle{
+ MinConns: 10,
+ MaxConns: 100,
+ MaxConnRate: 50,
+ RateInterval: 60,
+ },
+ Cluster: Cluster{Name: "c1.dfw1"},
+ Created: Datetime{Time: "2010-11-30T03:23:42Z"},
+ Updated: Datetime{Time: "2010-11-30T03:23:44Z"},
+ SourceAddrs: SourceAddrs{
+ IPv4Public: "10.12.99.28",
+ IPv4Private: "10.0.0.0",
+ IPv6Public: "2001:4801:79f1:1::1/64",
+ },
+ }
+
+ th.AssertDeepEquals(t, expected, lb)
+ th.AssertNoErr(t, err)
}
diff --git a/rackspace/lb/lb/results.go b/rackspace/lb/lb/results.go
index 45c32c5..d0ce197 100644
--- a/rackspace/lb/lb/results.go
+++ b/rackspace/lb/lb/results.go
@@ -144,6 +144,30 @@
Nodes []Node
ConnectionLogging ConnectionLogging
+
+ SessionPersistence SessionPersistence
+
+ ConnectionThrottle ConnectionThrottle
+
+ SourceAddrs SourceAddrs `mapstructure:"sourceAddresses"`
+}
+
+type SourceAddrs struct {
+ IPv4Public string `json:"ipv4Public" mapstructure:"ipv4Public"`
+ IPv4Private string `json:"ipv4Servicenet" mapstructure:"ipv4Servicenet"`
+ IPv6Public string `json:"ipv6Public" mapstructure:"ipv6Public"`
+ IPv6Private string `json:"ipv6Servicenet" mapstructure:"ipv6Servicenet"`
+}
+
+type SessionPersistence struct {
+ Type string `json:"persistenceType" mapstructure:"persistenceType"`
+}
+
+type ConnectionThrottle struct {
+ MinConns int `json:"minConnections" mapstructure:"minConnections"`
+ MaxConns int `json:"maxConnections" mapstructure:"maxConnections"`
+ MaxConnRate int `json:"maxConnectionRate" mapstructure:"maxConnectionRate"`
+ RateInterval int `json:"rateInterval" mapstructure:"rateInterval"`
}
type ConnectionLogging struct {
@@ -217,3 +241,7 @@
type DeleteResult struct {
gophercloud.ErrResult
}
+
+type GetResult struct {
+ commonResult
+}