rackconnect lb pools ops and unit tests
diff --git a/rackspace/rackconnect/v3/lbpools/doc.go b/rackspace/rackconnect/v3/lbpools/doc.go
new file mode 100644
index 0000000..68e5f67
--- /dev/null
+++ b/rackspace/rackconnect/v3/lbpools/doc.go
@@ -0,0 +1,14 @@
+// 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.
+// 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
+// unless the Load Balancer Pool is renamed on your hardware load balancer.
+// All Load Balancer Pools will currently return a status of ACTIVE. Future
+// features may introduce additional statuses.
+// Node status values are ADDING, ACTIVE, REMOVING, ADD_FAILED, and REMOVE_FAILED.
+// The cloud_servers node count will only include Cloud Servers from the specified
+// cloud account. Any dedicated servers or cloud servers from another cloud account
+// on the same RackConnect Configuration will be counted as external nodes.
+package lbpools
diff --git a/rackspace/rackconnect/v3/lbpools/requests.go b/rackspace/rackconnect/v3/lbpools/requests.go
new file mode 100644
index 0000000..23425d0
--- /dev/null
+++ b/rackspace/rackconnect/v3/lbpools/requests.go
@@ -0,0 +1,156 @@
+package lbpools
+
+import (
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+// List returns all load balancer pools that are associated with RackConnect.
+func List(c *gophercloud.ServiceClient) pagination.Pager {
+ url := listURL(c)
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return PoolPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(c, url, createPage)
+}
+
+// Get retrieves a specific load balancer pool (that is associated with RackConnect)
+// based on its unique ID.
+func Get(c *gophercloud.ServiceClient, id string) GetResult {
+ var res GetResult
+ _, res.Err = c.Request("GET", getURL(c, id), gophercloud.RequestOpts{
+ JSONResponse: &res.Body,
+ OkCodes: []int{200},
+ })
+ return res
+}
+
+// ListNodes returns all load balancer pool nodes that are associated with RackConnect
+// for the given LB pool ID.
+func ListNodes(c *gophercloud.ServiceClient, id string) pagination.Pager {
+ url := listNodesURL(c, id)
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return NodePage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(c, url, createPage)
+}
+
+// CreateNode adds the cloud server with the given serverID to the load balancer
+// pool with the given poolID.
+func CreateNode(c *gophercloud.ServiceClient, poolID, serverID string) CreateNodeResult {
+ var res CreateNodeResult
+ reqBody := map[string]interface{}{
+ "cloud_server": map[string]string{
+ "id": serverID,
+ },
+ }
+ _, res.Err = c.Request("POST", createNodeURL(c, poolID), gophercloud.RequestOpts{
+ JSONBody: &reqBody,
+ JSONResponse: &res.Body,
+ OkCodes: []int{201},
+ })
+ return res
+}
+
+// ListNodesDetails returns all load balancer pool nodes that are associated with RackConnect
+// for the given LB pool ID with all their details.
+func ListNodesDetails(c *gophercloud.ServiceClient, id string) pagination.Pager {
+ url := listNodesDetailsURL(c, id)
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return NodeDetailsPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(c, url, createPage)
+}
+
+// GetNode retrieves a specific LB pool node (that is associated with RackConnect)
+// based on its unique ID and the LB pool's unique ID.
+func GetNode(c *gophercloud.ServiceClient, poolID, nodeID string) GetNodeResult {
+ var res GetNodeResult
+ _, res.Err = c.Request("GET", nodeURL(c, poolID, nodeID), gophercloud.RequestOpts{
+ JSONResponse: &res.Body,
+ OkCodes: []int{200},
+ })
+ return res
+}
+
+// DeleteNode removes the node with the given nodeID from the LB pool with the
+// given poolID.
+func DeleteNode(c *gophercloud.ServiceClient, poolID, nodeID string) DeleteNodeResult {
+ var res DeleteNodeResult
+ _, res.Err = c.Request("DELETE", deleteNodeURL(c, poolID, nodeID), gophercloud.RequestOpts{
+ OkCodes: []int{204},
+ })
+ return res
+}
+
+// GetNodeDetails retrieves a specific LB pool node's details based on its unique
+// ID and the LB pool's unique ID.
+func GetNodeDetails(c *gophercloud.ServiceClient, poolID, nodeID string) GetNodeDetailsResult {
+ var res GetNodeDetailsResult
+ _, res.Err = c.Request("GET", nodeDetailsURL(c, poolID, nodeID), gophercloud.RequestOpts{
+ JSONResponse: &res.Body,
+ OkCodes: []int{200},
+ })
+ return res
+}
+
+// NodesOpts are options for bulk adding/deleting nodes to LB pools.
+type NodesOpts 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{}{
+ "cloud_server": map[string]string{
+ "id": opts[i].ServerID,
+ },
+ "load_balancer_pool": map[string]string{
+ "id": opts[i].PoolID,
+ },
+ }
+ }
+ _, res.Err = c.Request("POST", createNodesURL(c), gophercloud.RequestOpts{
+ JSONBody: &reqBody,
+ JSONResponse: &res.Body,
+ OkCodes: []int{201},
+ })
+ return res
+}
+
+// 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 {
+ 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,
+ },
+ }
+ }
+ _, res.Err = c.Request("DELETE", createNodesURL(c), gophercloud.RequestOpts{
+ JSONBody: &reqBody,
+ OkCodes: []int{204},
+ })
+ 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.
+func ListNodesDetailsForServer(c *gophercloud.ServiceClient, serverID string) pagination.Pager {
+ url := listNodesForServerURL(c, serverID)
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return NodeDetailsForServerPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(c, url, createPage)
+}
diff --git a/rackspace/rackconnect/v3/lbpools/requests_test.go b/rackspace/rackconnect/v3/lbpools/requests_test.go
new file mode 100644
index 0000000..2286d47
--- /dev/null
+++ b/rackspace/rackconnect/v3/lbpools/requests_test.go
@@ -0,0 +1,876 @@
+package lbpools
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/jrperritt/gophercloud/testhelper/client"
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
+)
+
+func TestListPools(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ w.Header().Set("Content-Type", "application/json")
+ fmt.Fprintf(w, `[
+ {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ "name": "RCv3Test",
+ "node_counts": {
+ "cloud_servers": 3,
+ "external": 4,
+ "total": 7
+ },
+ "port": 80,
+ "status": "ACTIVE",
+ "status_detail": null,
+ "virtual_ip": "203.0.113.5"
+ },
+ {
+ "id": "33021100-4abf-4836-9080-465a6d87ab68",
+ "name": "RCv3Test2",
+ "node_counts": {
+ "cloud_servers": 1,
+ "external": 0,
+ "total": 1
+ },
+ "port": 80,
+ "status": "ACTIVE",
+ "status_detail": null,
+ "virtual_ip": "203.0.113.7"
+ },
+ {
+ "id": "b644350a-301b-47b5-a411-c6e0f933c347",
+ "name": "RCv3Test3",
+ "node_counts": {
+ "cloud_servers": 2,
+ "external": 3,
+ "total": 5
+ },
+ "port": 443,
+ "status": "ACTIVE",
+ "status_detail": null,
+ "virtual_ip": "203.0.113.15"
+ }
+ ]`)
+ })
+
+ expected := []Pool{
+ Pool{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ Name: "RCv3Test",
+ NodeCounts: struct {
+ CloudServers int `mapstructure:"cloud_servers"`
+ External int `mapstructure:"external"`
+ Total int `mapstructure:"total"`
+ }{
+ CloudServers: 3,
+ External: 4,
+ Total: 7,
+ },
+ Port: 80,
+ Status: "ACTIVE",
+ VirtualIP: "203.0.113.5",
+ },
+ Pool{
+ ID: "33021100-4abf-4836-9080-465a6d87ab68",
+ Name: "RCv3Test2",
+ NodeCounts: struct {
+ CloudServers int `mapstructure:"cloud_servers"`
+ External int `mapstructure:"external"`
+ Total int `mapstructure:"total"`
+ }{
+ CloudServers: 1,
+ External: 0,
+ Total: 1,
+ },
+ Port: 80,
+ Status: "ACTIVE",
+ VirtualIP: "203.0.113.7",
+ },
+ Pool{
+ ID: "b644350a-301b-47b5-a411-c6e0f933c347",
+ Name: "RCv3Test3",
+ NodeCounts: struct {
+ CloudServers int `mapstructure:"cloud_servers"`
+ External int `mapstructure:"external"`
+ Total int `mapstructure:"total"`
+ }{
+ CloudServers: 2,
+ External: 3,
+ Total: 5,
+ },
+ Port: 443,
+ Status: "ACTIVE",
+ VirtualIP: "203.0.113.15",
+ },
+ }
+
+ count := 0
+ err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractPools(page)
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestGetLBPool(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `{
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ "name": "RCv3Test",
+ "node_counts": {
+ "cloud_servers": 3,
+ "external": 4,
+ "total": 7
+ },
+ "port": 80,
+ "status": "ACTIVE",
+ "status_detail": null,
+ "virtual_ip": "203.0.113.5"
+ }`)
+ })
+
+ expected := &Pool{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ Name: "RCv3Test",
+ NodeCounts: struct {
+ CloudServers int `mapstructure:"cloud_servers"`
+ External int `mapstructure:"external"`
+ Total int `mapstructure:"total"`
+ }{
+ CloudServers: 3,
+ External: 4,
+ Total: 7,
+ },
+ Port: 80,
+ Status: "ACTIVE",
+ VirtualIP: "203.0.113.5",
+ }
+
+ actual, err := Get(fake.ServiceClient(), "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2").Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertDeepEquals(t, expected, actual)
+}
+
+func TestListNodes(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2/nodes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ w.Header().Set("Content-Type", "application/json")
+ fmt.Fprintf(w, `[
+ {
+ "created": "2014-05-30T03:23:42Z",
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "id": "1860451d-fb89-45b8-b54e-151afceb50e5",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
+ },
+ "status": "ACTIVE",
+ "updated": "2014-05-30T03:24:18Z"
+ },
+ {
+ "created": "2014-05-31T08:23:12Z",
+ "cloud_server": {
+ "id": "f28b870f-a063-498a-8b12-7025e5b1caa6"
+ },
+ "id": "b70481dd-7edf-4dbb-a44b-41cc7679d4fb",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
+ },
+ "status": "ADDING",
+ "updated": "2014-05-31T08:23:26Z"
+ },
+ {
+ "created": "2014-05-31T08:23:18Z",
+ "cloud_server": {
+ "id": "a3d3a6b3-e4e4-496f-9a3d-5c987163e458"
+ },
+ "id": "ced9ddc8-6fae-4e72-9457-16ead52b5515",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
+ },
+ "status": "ADD_FAILED",
+ "status_detail": "Unable to communicate with network device",
+ "updated": "2014-05-31T08:24:36Z"
+ }
+ ]`)
+ })
+
+ expected := []Node{
+ Node{
+ CreatedAt: time.Date(2014, 5, 30, 3, 23, 42, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ },
+ ID: "1860451d-fb89-45b8-b54e-151afceb50e5",
+ LoadBalancerPool: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ Status: "ACTIVE",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ },
+ Node{
+ CreatedAt: time.Date(2014, 5, 31, 8, 23, 12, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "f28b870f-a063-498a-8b12-7025e5b1caa6",
+ },
+ ID: "b70481dd-7edf-4dbb-a44b-41cc7679d4fb",
+ LoadBalancerPool: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ Status: "ADDING",
+ UpdatedAt: time.Date(2014, 5, 31, 8, 23, 26, 0, time.UTC),
+ },
+ Node{
+ CreatedAt: time.Date(2014, 5, 31, 8, 23, 18, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "a3d3a6b3-e4e4-496f-9a3d-5c987163e458",
+ },
+ ID: "ced9ddc8-6fae-4e72-9457-16ead52b5515",
+ LoadBalancerPool: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ Status: "ADD_FAILED",
+ StatusDetail: "Unable to communicate with network device",
+ UpdatedAt: time.Date(2014, 5, 31, 8, 24, 36, 0, time.UTC),
+ },
+ }
+
+ count := 0
+ err := ListNodes(fake.ServiceClient(), "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2").EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractNodes(page)
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestCreateNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2/nodes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+ {
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ }
+ }
+ `)
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusCreated)
+ fmt.Fprintf(w, `
+ {
+ "created": "2014-05-30T03:23:42Z",
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "id": "1860451d-fb89-45b8-b54e-151afceb50e5",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
+ },
+ "status": "ACTIVE",
+ "status_detail": null,
+ "updated": "2014-05-30T03:24:18Z"
+ }
+ `)
+ })
+
+ expected := &Node{
+ CreatedAt: time.Date(2014, 5, 30, 3, 23, 42, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ },
+ ID: "1860451d-fb89-45b8-b54e-151afceb50e5",
+ LoadBalancerPool: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ Status: "ACTIVE",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ }
+
+ actual, err := CreateNode(fake.ServiceClient(), "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2", "d95ae0c4-6ab8-4873-b82f-f8433840cff2").Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertDeepEquals(t, expected, actual)
+}
+
+func TestListNodesDetails(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2/nodes/details", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ w.Header().Set("Content-Type", "application/json")
+ fmt.Fprintf(w, `
+ [
+ {
+ "created": "2014-05-30T03:23:42Z",
+ "cloud_server": {
+ "cloud_network": {
+ "cidr": "192.168.100.0/24",
+ "created": "2014-05-25T01:23:42Z",
+ "id": "07426958-1ebf-4c38-b032-d456820ca21a",
+ "name": "RC-CLOUD",
+ "private_ip_v4": "192.168.100.5",
+ "updated": "2014-05-25T02:28:44Z"
+ },
+ "created": "2014-05-30T02:18:42Z",
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ "name": "RCv3TestServer1",
+ "updated": "2014-05-30T02:19:18Z"
+ },
+ "id": "1860451d-fb89-45b8-b54e-151afceb50e5",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ "name": "RCv3Test",
+ "node_counts": {
+ "cloud_servers": 3,
+ "external": 4,
+ "total": 7
+ },
+ "port": 80,
+ "status": "ACTIVE",
+ "status_detail": null,
+ "virtual_ip": "203.0.113.5"
+ },
+ "status": "ACTIVE",
+ "status_detail": null,
+ "updated": "2014-05-30T03:24:18Z"
+ }
+ ]
+ `)
+ })
+
+ expected := []NodeDetails{
+ NodeDetails{
+ CreatedAt: time.Date(2014, 5, 30, 3, 23, 42, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ Name string `mapstructure:"name"`
+ CloudNetwork struct {
+ ID string `mapstructure:"id"`
+ Name string `mapstructure:"name"`
+ PrivateIPv4 string `mapstructure:"private_ip_v4"`
+ CIDR string `mapstructure:"cidr"`
+ CreatedAt time.Time `mapstructure:"-"`
+ UpdatedAt time.Time `mapstructure:"-"`
+ } `mapstructure:"cloud_network"`
+ CreatedAt time.Time `mapstructure:"-"`
+ UpdatedAt time.Time `mapstructure:"-"`
+ }{
+ ID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ CloudNetwork: struct {
+ ID string `mapstructure:"id"`
+ Name string `mapstructure:"name"`
+ PrivateIPv4 string `mapstructure:"private_ip_v4"`
+ CIDR string `mapstructure:"cidr"`
+ CreatedAt time.Time `mapstructure:"-"`
+ UpdatedAt time.Time `mapstructure:"-"`
+ }{
+ ID: "07426958-1ebf-4c38-b032-d456820ca21a",
+ CIDR: "192.168.100.0/24",
+ CreatedAt: time.Date(2014, 5, 25, 1, 23, 42, 0, time.UTC),
+ Name: "RC-CLOUD",
+ PrivateIPv4: "192.168.100.5",
+ UpdatedAt: time.Date(2014, 5, 25, 2, 28, 44, 0, time.UTC),
+ },
+ CreatedAt: time.Date(2014, 5, 30, 2, 18, 42, 0, time.UTC),
+ Name: "RCv3TestServer1",
+ UpdatedAt: time.Date(2014, 5, 30, 2, 19, 18, 0, time.UTC),
+ },
+ ID: "1860451d-fb89-45b8-b54e-151afceb50e5",
+ LoadBalancerPool: Pool{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ Name: "RCv3Test",
+ NodeCounts: struct {
+ CloudServers int `mapstructure:"cloud_servers"`
+ External int `mapstructure:"external"`
+ Total int `mapstructure:"total"`
+ }{
+ CloudServers: 3,
+ External: 4,
+ Total: 7,
+ },
+ Port: 80,
+ Status: "ACTIVE",
+ VirtualIP: "203.0.113.5",
+ },
+ Status: "ACTIVE",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ },
+ }
+ count := 0
+ err := ListNodesDetails(fake.ServiceClient(), "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2").EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractNodesDetails(page)
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestGetNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2/nodes/1860451d-fb89-45b8-b54e-151afceb50e5", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `
+ {
+ "created": "2014-05-30T03:23:42Z",
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "id": "1860451d-fb89-45b8-b54e-151afceb50e5",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
+ },
+ "status": "ACTIVE",
+ "status_detail": null,
+ "updated": "2014-05-30T03:24:18Z"
+ }
+ `)
+ })
+
+ expected := &Node{
+ CreatedAt: time.Date(2014, 5, 30, 3, 23, 42, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ },
+ ID: "1860451d-fb89-45b8-b54e-151afceb50e5",
+ LoadBalancerPool: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ Status: "ACTIVE",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ }
+
+ actual, err := GetNode(fake.ServiceClient(), "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2", "1860451d-fb89-45b8-b54e-151afceb50e5").Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertDeepEquals(t, expected, actual)
+}
+
+func TestDeleteNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2/nodes/1860451d-fb89-45b8-b54e-151afceb50e5", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ err := DeleteNode(client.ServiceClient(), "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2", "1860451d-fb89-45b8-b54e-151afceb50e5").ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestGetNodeDetails(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2/nodes/d95ae0c4-6ab8-4873-b82f-f8433840cff2/details", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ w.Header().Set("Content-Type", "application/json")
+ fmt.Fprintf(w, `
+ {
+ "created": "2014-05-30T03:23:42Z",
+ "cloud_server": {
+ "cloud_network": {
+ "cidr": "192.168.100.0/24",
+ "created": "2014-05-25T01:23:42Z",
+ "id": "07426958-1ebf-4c38-b032-d456820ca21a",
+ "name": "RC-CLOUD",
+ "private_ip_v4": "192.168.100.5",
+ "updated": "2014-05-25T02:28:44Z"
+ },
+ "created": "2014-05-30T02:18:42Z",
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ "name": "RCv3TestServer1",
+ "updated": "2014-05-30T02:19:18Z"
+ },
+ "id": "1860451d-fb89-45b8-b54e-151afceb50e5",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ "name": "RCv3Test",
+ "node_counts": {
+ "cloud_servers": 3,
+ "external": 4,
+ "total": 7
+ },
+ "port": 80,
+ "status": "ACTIVE",
+ "status_detail": null,
+ "virtual_ip": "203.0.113.5"
+ },
+ "status": "ACTIVE",
+ "status_detail": null,
+ "updated": "2014-05-30T03:24:18Z"
+ }
+ `)
+ })
+
+ expected := &NodeDetails{
+ CreatedAt: time.Date(2014, 5, 30, 3, 23, 42, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ Name string `mapstructure:"name"`
+ CloudNetwork struct {
+ ID string `mapstructure:"id"`
+ Name string `mapstructure:"name"`
+ PrivateIPv4 string `mapstructure:"private_ip_v4"`
+ CIDR string `mapstructure:"cidr"`
+ CreatedAt time.Time `mapstructure:"-"`
+ UpdatedAt time.Time `mapstructure:"-"`
+ } `mapstructure:"cloud_network"`
+ CreatedAt time.Time `mapstructure:"-"`
+ UpdatedAt time.Time `mapstructure:"-"`
+ }{
+ ID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ CloudNetwork: struct {
+ ID string `mapstructure:"id"`
+ Name string `mapstructure:"name"`
+ PrivateIPv4 string `mapstructure:"private_ip_v4"`
+ CIDR string `mapstructure:"cidr"`
+ CreatedAt time.Time `mapstructure:"-"`
+ UpdatedAt time.Time `mapstructure:"-"`
+ }{
+ ID: "07426958-1ebf-4c38-b032-d456820ca21a",
+ CIDR: "192.168.100.0/24",
+ CreatedAt: time.Date(2014, 5, 25, 1, 23, 42, 0, time.UTC),
+ Name: "RC-CLOUD",
+ PrivateIPv4: "192.168.100.5",
+ UpdatedAt: time.Date(2014, 5, 25, 2, 28, 44, 0, time.UTC),
+ },
+ CreatedAt: time.Date(2014, 5, 30, 2, 18, 42, 0, time.UTC),
+ Name: "RCv3TestServer1",
+ UpdatedAt: time.Date(2014, 5, 30, 2, 19, 18, 0, time.UTC),
+ },
+ ID: "1860451d-fb89-45b8-b54e-151afceb50e5",
+ LoadBalancerPool: Pool{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ Name: "RCv3Test",
+ NodeCounts: struct {
+ CloudServers int `mapstructure:"cloud_servers"`
+ External int `mapstructure:"external"`
+ Total int `mapstructure:"total"`
+ }{
+ CloudServers: 3,
+ External: 4,
+ Total: 7,
+ },
+ Port: 80,
+ Status: "ACTIVE",
+ VirtualIP: "203.0.113.5",
+ },
+ Status: "ACTIVE",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ }
+
+ actual, err := GetNodeDetails(fake.ServiceClient(), "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2", "d95ae0c4-6ab8-4873-b82f-f8433840cff2").Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, expected, actual)
+}
+
+func TestCreateNodes(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/nodes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+ [
+ {
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
+ }
+ },
+ {
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "load_balancer_pool": {
+ "id": "33021100-4abf-4836-9080-465a6d87ab68"
+ }
+ }
+ ]
+ `)
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusCreated)
+ fmt.Fprintf(w, `
+ [
+ {
+ "created": "2014-05-30T03:23:42Z",
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "id": "1860451d-fb89-45b8-b54e-151afceb50e5",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
+ },
+ "status": "ADDING",
+ "status_detail": null,
+ "updated": null
+ },
+ {
+ "created": "2014-05-31T08:23:12Z",
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "id": "b70481dd-7edf-4dbb-a44b-41cc7679d4fb",
+ "load_balancer_pool": {
+ "id": "33021100-4abf-4836-9080-465a6d87ab68"
+ },
+ "status": "ADDING",
+ "status_detail": null,
+ "updated": null
+ }
+ ]
+ `)
+ })
+
+ expected := []Node{
+ Node{
+ CreatedAt: time.Date(2014, 5, 30, 3, 23, 42, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ },
+ ID: "1860451d-fb89-45b8-b54e-151afceb50e5",
+ LoadBalancerPool: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ Status: "ADDING",
+ },
+ Node{
+ CreatedAt: time.Date(2014, 5, 31, 8, 23, 12, 0, time.UTC),
+ CloudServer: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ },
+ ID: "b70481dd-7edf-4dbb-a44b-41cc7679d4fb",
+ LoadBalancerPool: struct {
+ ID string `mapstructure:"id"`
+ }{
+ ID: "33021100-4abf-4836-9080-465a6d87ab68",
+ },
+ Status: "ADDING",
+ },
+ }
+
+ opts := []NodesOpts{
+ NodesOpts{
+ ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ PoolID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ NodesOpts{
+ ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ PoolID: "33021100-4abf-4836-9080-465a6d87ab68",
+ },
+ }
+ actual, err := CreateNodes(fake.ServiceClient(), opts).Extract()
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, expected, actual)
+}
+
+func TestDeleteNodes(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/nodes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+ [
+ {
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
+ }
+ },
+ {
+ "cloud_server": {
+ "id": "d95ae0c4-6ab8-4873-b82f-f8433840cff2"
+ },
+ "load_balancer_pool": {
+ "id": "33021100-4abf-4836-9080-465a6d87ab68"
+ }
+ }
+ ]
+ `)
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusNoContent)
+ })
+
+ opts := []NodesOpts{
+ NodesOpts{
+ ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ PoolID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ NodesOpts{
+ ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ PoolID: "33021100-4abf-4836-9080-465a6d87ab68",
+ },
+ }
+ err := DeleteNodes(client.ServiceClient(), opts).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestListNodesForServerDetails(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/load_balancer_pools/nodes/details", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ w.Header().Set("Content-Type", "application/json")
+ fmt.Fprintf(w, `
+ [
+ {
+ "created": "2014-05-30T03:23:42Z",
+ "id": "1860451d-fb89-45b8-b54e-151afceb50e5",
+ "load_balancer_pool": {
+ "id": "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ "name": "RCv3Test",
+ "node_counts": {
+ "cloud_servers": 3,
+ "external": 4,
+ "total": 7
+ },
+ "port": 80,
+ "status": "ACTIVE",
+ "status_detail": null,
+ "virtual_ip": "203.0.113.5"
+ },
+ "status": "ACTIVE",
+ "status_detail": null,
+ "updated": "2014-05-30T03:24:18Z"
+ }
+ ]
+ `)
+ })
+
+ expected := []NodeDetailsForServer{
+ NodeDetailsForServer{
+ CreatedAt: time.Date(2014, 5, 30, 3, 23, 42, 0, time.UTC),
+ ID: "1860451d-fb89-45b8-b54e-151afceb50e5",
+ LoadBalancerPool: Pool{
+ ID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ Name: "RCv3Test",
+ NodeCounts: struct {
+ CloudServers int `mapstructure:"cloud_servers"`
+ External int `mapstructure:"external"`
+ Total int `mapstructure:"total"`
+ }{
+ CloudServers: 3,
+ External: 4,
+ Total: 7,
+ },
+ Port: 80,
+ Status: "ACTIVE",
+ VirtualIP: "203.0.113.5",
+ },
+ Status: "ACTIVE",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ },
+ }
+ count := 0
+ err := ListNodesDetailsForServer(fake.ServiceClient(), "07426958-1ebf-4c38-b032-d456820ca21a").EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractNodesDetailsForServer(page)
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
diff --git a/rackspace/rackconnect/v3/lbpools/results.go b/rackspace/rackconnect/v3/lbpools/results.go
new file mode 100644
index 0000000..e5e914b
--- /dev/null
+++ b/rackspace/rackconnect/v3/lbpools/results.go
@@ -0,0 +1,505 @@
+package lbpools
+
+import (
+ "fmt"
+ "reflect"
+ "time"
+
+ "github.com/mitchellh/mapstructure"
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+// Pool represents a load balancer pool associated with a RackConnect configuration.
+type Pool struct {
+ // The unique ID of the load balancer pool.
+ ID string `mapstructure:"id"`
+ // The name of the load balancer pool.
+ Name string `mapstructure:"name"`
+ // The node counts associated witht the load balancer pool.
+ NodeCounts struct {
+ // The number of nodes associated with this LB pool for this account.
+ CloudServers int `mapstructure:"cloud_servers"`
+ // The number of nodes associated with this LB pool from other accounts.
+ External int `mapstructure:"external"`
+ // The total number of nodes associated with this LB pool.
+ Total int `mapstructure:"total"`
+ } `mapstructure:"node_counts"`
+ // The port of the LB pool
+ Port int `mapstructure:"port"`
+ // The status of the LB pool
+ Status string `mapstructure:"status"`
+ // The details of the status of the LB pool
+ StatusDetail string `mapstructure:"status_detail"`
+ // The virtual IP of the LB pool
+ VirtualIP string `mapstructure:"virtual_ip"`
+}
+
+// PoolPage is the page returned by a pager when traversing over a
+// collection of Pools.
+type PoolPage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a PoolPage contains no Pools.
+func (r PoolPage) IsEmpty() (bool, error) {
+ cns, err := ExtractPools(r)
+ if err != nil {
+ return true, err
+ }
+ return len(cns) == 0, nil
+}
+
+// ExtractPools extracts and returns Pools. It is used while iterating over
+// an lbpools.List call.
+func ExtractPools(page pagination.Page) ([]Pool, error) {
+ var res []Pool
+ err := mapstructure.Decode(page.(PoolPage).Body, &res)
+ return res, err
+}
+
+// GetResult represents the result of a Get operation.
+type GetResult struct {
+ gophercloud.Result
+}
+
+// Extract is a function that extracts an LBPool from a GetResult.
+func (r GetResult) Extract() (*Pool, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+ var res Pool
+ err := mapstructure.Decode(r.Body, &res)
+ return &res, err
+}
+
+// Node represents a load balancer pool node associated with a RackConnect configuration.
+type Node struct {
+ // The unique ID of the LB node.
+ ID string `mapstructure:"id"`
+ // The cloud server (node) of the load balancer pool.
+ CloudServer struct {
+ // The cloud server ID.
+ ID string `mapstructure:"id"`
+ } `mapstructure:"cloud_server"`
+ // The load balancer pool.
+ LoadBalancerPool struct {
+ // The LB pool ID.
+ ID string `mapstructure:"id"`
+ } `mapstructure:"load_balancer_pool"`
+ // The status of the LB pool.
+ Status string `mapstructure:"status"`
+ // The details of the status of the LB pool.
+ StatusDetail string `mapstructure:"status_detail"`
+ // The time the LB node was created.
+ CreatedAt time.Time `mapstructure:"-"`
+ // The time the LB node was last updated.
+ UpdatedAt time.Time `mapstructure:"-"`
+}
+
+// NodePage is the page returned by a pager when traversing over a
+// collection of Nodes.
+type NodePage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a NodePage contains no Nodes.
+func (r NodePage) IsEmpty() (bool, error) {
+ n, err := ExtractNodes(r)
+ if err != nil {
+ return true, err
+ }
+ return len(n) == 0, nil
+}
+
+// ExtractNodes extracts and returns a slice of Nodes. It is used while iterating over
+// an lbpools.ListNodes call.
+func ExtractNodes(page pagination.Page) ([]Node, error) {
+ var res []Node
+ casted := page.(NodePage).Body
+ err := mapstructure.Decode(casted, &res)
+
+ var rawNodes []interface{}
+ switch casted.(type) {
+ case interface{}:
+ rawNodes = casted.([]interface{})
+ default:
+ return res, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
+ }
+
+ for i := range rawNodes {
+ thisNode := (rawNodes[i]).(map[string]interface{})
+
+ if t, ok := thisNode["created"].(string); ok && t != "" {
+ creationTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].CreatedAt = creationTime
+ }
+
+ if t, ok := thisNode["updated"].(string); ok && t != "" {
+ updatedTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].UpdatedAt = updatedTime
+ }
+ }
+
+ return res, err
+}
+
+// NodeResult represents a result that can be extracted as a Node.
+type NodeResult struct {
+ gophercloud.Result
+}
+
+// CreateNodeResult represents the result of an CreateNode operation.
+type CreateNodeResult struct {
+ NodeResult
+}
+
+// GetNodeResult represents the result of an GetNode operation.
+type GetNodeResult struct {
+ NodeResult
+}
+
+// Extract is a function that extracts a Node from a NodeResult.
+func (r NodeResult) Extract() (*Node, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+ var res Node
+ err := mapstructure.Decode(r.Body, &res)
+
+ b := r.Body.(map[string]interface{})
+
+ if date, ok := b["created"]; ok && date != nil {
+ t, err := time.Parse(time.RFC3339, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ res.CreatedAt = t
+ }
+
+ if date, ok := b["updated"]; ok && date != nil {
+ t, err := time.Parse(time.RFC3339, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ res.UpdatedAt = t
+ }
+
+ return &res, err
+}
+
+// NodeDetails represents a load balancer pool node associated with a RackConnect configuration
+// with all its details.
+type NodeDetails struct {
+ // The unique ID of the LB node.
+ ID string `mapstructure:"id"`
+ // The cloud server (node) of the load balancer pool.
+ CloudServer struct {
+ // The cloud server ID.
+ ID string `mapstructure:"id"`
+ // The name of the server.
+ Name string `mapstructure:"name"`
+ // The cloud network for the cloud server.
+ CloudNetwork struct {
+ // The network ID.
+ ID string `mapstructure:"id"`
+ // The network name.
+ Name string `mapstructure:"name"`
+ // The network's private IPv4 address.
+ PrivateIPv4 string `mapstructure:"private_ip_v4"`
+ // The IP range for the network.
+ CIDR string `mapstructure:"cidr"`
+ // The datetime the network was created.
+ CreatedAt time.Time `mapstructure:"-"`
+ // The last datetime the network was updated.
+ UpdatedAt time.Time `mapstructure:"-"`
+ } `mapstructure:"cloud_network"`
+ // The datetime the server was created.
+ CreatedAt time.Time `mapstructure:"-"`
+ // The datetime the server was last updated.
+ UpdatedAt time.Time `mapstructure:"-"`
+ } `mapstructure:"cloud_server"`
+ // The load balancer pool.
+ LoadBalancerPool Pool `mapstructure:"load_balancer_pool"`
+ // The status of the LB pool.
+ Status string `mapstructure:"status"`
+ // The details of the status of the LB pool.
+ StatusDetail string `mapstructure:"status_detail"`
+ // The time the LB node was created.
+ CreatedAt time.Time `mapstructure:"-"`
+ // The time the LB node was last updated.
+ UpdatedAt time.Time `mapstructure:"-"`
+}
+
+// NodeDetailsPage is the page returned by a pager when traversing over a
+// collection of NodeDetails.
+type NodeDetailsPage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a NodeDetailsPage contains no NodeDetails.
+func (r NodeDetailsPage) IsEmpty() (bool, error) {
+ n, err := ExtractNodesDetails(r)
+ if err != nil {
+ return true, err
+ }
+ return len(n) == 0, nil
+}
+
+// ExtractNodesDetails extracts and returns a slice of NodeDetails. It is used while iterating over
+// an lbpools.ListNodesDetails call.
+func ExtractNodesDetails(page pagination.Page) ([]NodeDetails, error) {
+ var res []NodeDetails
+ casted := page.(NodeDetailsPage).Body
+ err := mapstructure.Decode(casted, &res)
+
+ var rawNodesDetails []interface{}
+ switch casted.(type) {
+ case interface{}:
+ rawNodesDetails = casted.([]interface{})
+ default:
+ return res, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
+ }
+
+ for i := range rawNodesDetails {
+ thisNodeDetails := (rawNodesDetails[i]).(map[string]interface{})
+
+ if t, ok := thisNodeDetails["created"].(string); ok && t != "" {
+ creationTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].CreatedAt = creationTime
+ }
+
+ if t, ok := thisNodeDetails["updated"].(string); ok && t != "" {
+ updatedTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].UpdatedAt = updatedTime
+ }
+
+ if cs, ok := thisNodeDetails["cloud_server"].(map[string]interface{}); ok {
+ if t, ok := cs["created"].(string); ok && t != "" {
+ creationTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].CloudServer.CreatedAt = creationTime
+ }
+ if t, ok := cs["updated"].(string); ok && t != "" {
+ updatedTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].CloudServer.UpdatedAt = updatedTime
+ }
+ if cn, ok := cs["cloud_network"].(map[string]interface{}); ok {
+ if t, ok := cn["created"].(string); ok && t != "" {
+ creationTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].CloudServer.CloudNetwork.CreatedAt = creationTime
+ }
+ if t, ok := cn["updated"].(string); ok && t != "" {
+ updatedTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].CloudServer.CloudNetwork.UpdatedAt = updatedTime
+ }
+ }
+ }
+ }
+
+ return res, err
+}
+
+// GetNodeDetailsResult represents the result of an NodeDetails operation.
+type GetNodeDetailsResult struct {
+ gophercloud.Result
+}
+
+// Extract is a function that extracts a NodeDetails from a NodeDetailsResult.
+func (r GetNodeDetailsResult) Extract() (*NodeDetails, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+ var res NodeDetails
+ err := mapstructure.Decode(r.Body, &res)
+
+ b := r.Body.(map[string]interface{})
+
+ if date, ok := b["created"]; ok && date != nil {
+ t, err := time.Parse(time.RFC3339, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ res.CreatedAt = t
+ }
+
+ if date, ok := b["updated"]; ok && date != nil {
+ t, err := time.Parse(time.RFC3339, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ res.UpdatedAt = t
+ }
+
+ if cs, ok := b["cloud_server"].(map[string]interface{}); ok {
+ if t, ok := cs["created"].(string); ok && t != "" {
+ creationTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return &res, err
+ }
+ res.CloudServer.CreatedAt = creationTime
+ }
+ if t, ok := cs["updated"].(string); ok && t != "" {
+ updatedTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return &res, err
+ }
+ res.CloudServer.UpdatedAt = updatedTime
+ }
+ if cn, ok := cs["cloud_network"].(map[string]interface{}); ok {
+ if t, ok := cn["created"].(string); ok && t != "" {
+ creationTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return &res, err
+ }
+ res.CloudServer.CloudNetwork.CreatedAt = creationTime
+ }
+ if t, ok := cn["updated"].(string); ok && t != "" {
+ updatedTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return &res, err
+ }
+ res.CloudServer.CloudNetwork.UpdatedAt = updatedTime
+ }
+ }
+ }
+
+ return &res, err
+}
+
+// DeleteNodeResult represents the result of a DeleteNode operation.
+type DeleteNodeResult struct {
+ gophercloud.ErrResult
+}
+
+// CreateNodesResult represents the result of a CreateNodes operation.
+type CreateNodesResult struct {
+ gophercloud.Result
+}
+
+// Extract is a function that extracts a slice of Nodes from a CreateNodesResult.
+func (r CreateNodesResult) Extract() ([]Node, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+ var res []Node
+ err := mapstructure.Decode(r.Body, &res)
+
+ b := r.Body.([]interface{})
+ for i := range b {
+ if date, ok := b[i].(map[string]interface{})["created"]; ok && date != nil {
+ t, err := time.Parse(time.RFC3339, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ res[i].CreatedAt = t
+ }
+ if date, ok := b[i].(map[string]interface{})["updated"]; ok && date != nil {
+ t, err := time.Parse(time.RFC3339, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ res[i].UpdatedAt = t
+ }
+ }
+
+ return res, err
+}
+
+// DeleteNodesResult represents the result of a DeleteNodes operation.
+type DeleteNodesResult struct {
+ gophercloud.ErrResult
+}
+
+// NodeDetailsForServer represents a load balancer pool node associated with a RackConnect configuration
+// with all its details for a particular server.
+type NodeDetailsForServer struct {
+ // The unique ID of the LB node.
+ ID string `mapstructure:"id"`
+ // The load balancer pool.
+ LoadBalancerPool Pool `mapstructure:"load_balancer_pool"`
+ // The status of the LB pool.
+ Status string `mapstructure:"status"`
+ // The details of the status of the LB pool.
+ StatusDetail string `mapstructure:"status_detail"`
+ // The time the LB node was created.
+ CreatedAt time.Time `mapstructure:"-"`
+ // The time the LB node was last updated.
+ UpdatedAt time.Time `mapstructure:"-"`
+}
+
+// NodeDetailsForServerPage is the page returned by a pager when traversing over a
+// collection of NodeDetailsForServer.
+type NodeDetailsForServerPage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a NodeDetailsForServerPage contains no NodeDetailsForServer.
+func (r NodeDetailsForServerPage) IsEmpty() (bool, error) {
+ n, err := ExtractNodesDetailsForServer(r)
+ if err != nil {
+ return true, err
+ }
+ return len(n) == 0, nil
+}
+
+// ExtractNodesDetailsForServer extracts and returns a slice of NodeDetailsForServer. It is used while iterating over
+// an lbpools.ListNodesDetailsForServer call.
+func ExtractNodesDetailsForServer(page pagination.Page) ([]NodeDetailsForServer, error) {
+ var res []NodeDetailsForServer
+ casted := page.(NodeDetailsForServerPage).Body
+ err := mapstructure.Decode(casted, &res)
+
+ var rawNodesDetails []interface{}
+ switch casted.(type) {
+ case interface{}:
+ rawNodesDetails = casted.([]interface{})
+ default:
+ return res, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
+ }
+
+ for i := range rawNodesDetails {
+ thisNodeDetails := (rawNodesDetails[i]).(map[string]interface{})
+
+ if t, ok := thisNodeDetails["created"].(string); ok && t != "" {
+ creationTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].CreatedAt = creationTime
+ }
+
+ if t, ok := thisNodeDetails["updated"].(string); ok && t != "" {
+ updatedTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].UpdatedAt = updatedTime
+ }
+ }
+
+ return res, err
+}
diff --git a/rackspace/rackconnect/v3/lbpools/urls.go b/rackspace/rackconnect/v3/lbpools/urls.go
new file mode 100644
index 0000000..c238239
--- /dev/null
+++ b/rackspace/rackconnect/v3/lbpools/urls.go
@@ -0,0 +1,49 @@
+package lbpools
+
+import "github.com/rackspace/gophercloud"
+
+var root = "load_balancer_pools"
+
+func listURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL(root)
+}
+
+func getURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL(root, id)
+}
+
+func listNodesURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL(root, id, "nodes")
+}
+
+func createNodeURL(c *gophercloud.ServiceClient, id string) string {
+ return listNodesURL(c, id)
+}
+
+func listNodesDetailsURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL(root, id, "nodes", "details")
+}
+
+func nodeURL(c *gophercloud.ServiceClient, poolID, nodeID string) string {
+ return c.ServiceURL(root, poolID, "nodes", nodeID)
+}
+
+func deleteNodeURL(c *gophercloud.ServiceClient, poolID, nodeID string) string {
+ return nodeURL(c, poolID, nodeID)
+}
+
+func nodeDetailsURL(c *gophercloud.ServiceClient, poolID, nodeID string) string {
+ return c.ServiceURL(root, poolID, "nodes", nodeID, "details")
+}
+
+func createNodesURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL(root, "nodes")
+}
+
+func deleteNodesURL(c *gophercloud.ServiceClient) string {
+ return createNodesURL(c)
+}
+
+func listNodesForServerURL(c *gophercloud.ServiceClient, serverID string) string {
+ return c.ServiceURL(root, "nodes", "details?cloud_server_id="+serverID)
+}