Merge pull request #399 from jrperritt/rackconnect
RackConnect v3; Closes #364
diff --git a/acceptance/rackspace/rackconnect/v3/cloudnetworks_test.go b/acceptance/rackspace/rackconnect/v3/cloudnetworks_test.go
new file mode 100644
index 0000000..2c6287e
--- /dev/null
+++ b/acceptance/rackspace/rackconnect/v3/cloudnetworks_test.go
@@ -0,0 +1,36 @@
+// +build acceptance
+
+package v3
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/rackspace/rackconnect/v3/cloudnetworks"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestCloudNetworks(t *testing.T) {
+ c := newClient(t)
+ cnID := testListNetworks(t, c)
+ testGetNetworks(t, c, cnID)
+}
+
+func testListNetworks(t *testing.T, c *gophercloud.ServiceClient) string {
+ allPages, err := cloudnetworks.List(c).AllPages()
+ th.AssertNoErr(t, err)
+ allcn, err := cloudnetworks.ExtractCloudNetworks(allPages)
+ fmt.Printf("Listing all cloud networks: %+v\n\n", allcn)
+ var cnID string
+ if len(allcn) > 0 {
+ cnID = allcn[0].ID
+ }
+ return cnID
+}
+
+func testGetNetworks(t *testing.T, c *gophercloud.ServiceClient, id string) {
+ cn, err := cloudnetworks.Get(c, id).Extract()
+ th.AssertNoErr(t, err)
+ fmt.Printf("Retrieved cloud network: %+v\n\n", cn)
+}
diff --git a/acceptance/rackspace/rackconnect/v3/common.go b/acceptance/rackspace/rackconnect/v3/common.go
new file mode 100644
index 0000000..8c75314
--- /dev/null
+++ b/acceptance/rackspace/rackconnect/v3/common.go
@@ -0,0 +1,26 @@
+// +build acceptance
+
+package v3
+
+import (
+ "os"
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/rackspace"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func newClient(t *testing.T) *gophercloud.ServiceClient {
+ ao, err := rackspace.AuthOptionsFromEnv()
+ th.AssertNoErr(t, err)
+
+ client, err := rackspace.AuthenticatedClient(ao)
+ th.AssertNoErr(t, err)
+
+ c, err := rackspace.NewRackConnectV3(client, gophercloud.EndpointOpts{
+ Region: os.Getenv("RS_REGION_NAME"),
+ })
+ th.AssertNoErr(t, err)
+ return c
+}
diff --git a/acceptance/rackspace/rackconnect/v3/lbpools_test.go b/acceptance/rackspace/rackconnect/v3/lbpools_test.go
new file mode 100644
index 0000000..85ac931
--- /dev/null
+++ b/acceptance/rackspace/rackconnect/v3/lbpools_test.go
@@ -0,0 +1,71 @@
+// +build acceptance
+
+package v3
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/rackspace/rackconnect/v3/lbpools"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestLBPools(t *testing.T) {
+ c := newClient(t)
+ pID := testListPools(t, c)
+ testGetPools(t, c, pID)
+ nID := testListNodes(t, c, pID)
+ testListNodeDetails(t, c, pID)
+ testGetNode(t, c, pID, nID)
+ testGetNodeDetails(t, c, pID, nID)
+}
+
+func testListPools(t *testing.T, c *gophercloud.ServiceClient) string {
+ allPages, err := lbpools.List(c).AllPages()
+ th.AssertNoErr(t, err)
+ allp, err := lbpools.ExtractPools(allPages)
+ fmt.Printf("Listing all LB pools: %+v\n\n", allp)
+ var pID string
+ if len(allp) > 0 {
+ pID = allp[0].ID
+ }
+ return pID
+}
+
+func testGetPools(t *testing.T, c *gophercloud.ServiceClient, pID string) {
+ p, err := lbpools.Get(c, pID).Extract()
+ th.AssertNoErr(t, err)
+ fmt.Printf("Retrieved LB pool: %+v\n\n", p)
+}
+
+func testListNodes(t *testing.T, c *gophercloud.ServiceClient, pID string) string {
+ allPages, err := lbpools.ListNodes(c, pID).AllPages()
+ th.AssertNoErr(t, err)
+ alln, err := lbpools.ExtractNodes(allPages)
+ fmt.Printf("Listing all LB pool nodes for pool (%s): %+v\n\n", pID, alln)
+ var nID string
+ if len(alln) > 0 {
+ nID = alln[0].ID
+ }
+ return nID
+}
+
+func testListNodeDetails(t *testing.T, c *gophercloud.ServiceClient, pID string) {
+ allPages, err := lbpools.ListNodesDetails(c, pID).AllPages()
+ th.AssertNoErr(t, err)
+ alln, err := lbpools.ExtractNodesDetails(allPages)
+ fmt.Printf("Listing all LB pool nodes details for pool (%s): %+v\n\n", pID, alln)
+}
+
+func testGetNode(t *testing.T, c *gophercloud.ServiceClient, pID, nID string) {
+ n, err := lbpools.GetNode(c, pID, nID).Extract()
+ th.AssertNoErr(t, err)
+ fmt.Printf("Retrieved LB node: %+v\n\n", n)
+}
+
+func testGetNodeDetails(t *testing.T, c *gophercloud.ServiceClient, pID, nID string) {
+ n, err := lbpools.GetNodeDetails(c, pID, nID).Extract()
+ th.AssertNoErr(t, err)
+ fmt.Printf("Retrieved LB node details: %+v\n\n", n)
+}
diff --git a/acceptance/rackspace/rackconnect/v3/publicips_test.go b/acceptance/rackspace/rackconnect/v3/publicips_test.go
new file mode 100644
index 0000000..8dc6270
--- /dev/null
+++ b/acceptance/rackspace/rackconnect/v3/publicips_test.go
@@ -0,0 +1,45 @@
+// +build acceptance
+
+package v3
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/rackspace/rackconnect/v3/publicips"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestPublicIPs(t *testing.T) {
+ c := newClient(t)
+ ipID := testListIPs(t, c)
+ sID := testGetIP(t, c, ipID)
+ testListIPsForServer(t, c, sID)
+}
+
+func testListIPs(t *testing.T, c *gophercloud.ServiceClient) string {
+ allPages, err := publicips.List(c).AllPages()
+ th.AssertNoErr(t, err)
+ allip, err := publicips.ExtractPublicIPs(allPages)
+ fmt.Printf("Listing all public IPs: %+v\n\n", allip)
+ var ipID string
+ if len(allip) > 0 {
+ ipID = allip[0].ID
+ }
+ return ipID
+}
+
+func testGetIP(t *testing.T, c *gophercloud.ServiceClient, ipID string) string {
+ ip, err := publicips.Get(c, ipID).Extract()
+ th.AssertNoErr(t, err)
+ fmt.Printf("Retrieved public IP (%s): %+v\n\n", ipID, ip)
+ return ip.CloudServer.ID
+}
+
+func testListIPsForServer(t *testing.T, c *gophercloud.ServiceClient, sID string) {
+ allPages, err := publicips.ListForServer(c, sID).AllPages()
+ th.AssertNoErr(t, err)
+ allip, err := publicips.ExtractPublicIPs(allPages)
+ fmt.Printf("Listing all public IPs for server (%s): %+v\n\n", sID, allip)
+}
diff --git a/rackspace/client.go b/rackspace/client.go
index 8f1f34f..db3f305 100644
--- a/rackspace/client.go
+++ b/rackspace/client.go
@@ -202,3 +202,13 @@
}
return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil
}
+
+// NewRackConnectV3 creates a ServiceClient that may be used to access the v3 RackConnect service.
+func NewRackConnectV3(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
+ eo.ApplyDefaults("rax:rackconnect")
+ url, err := client.EndpointLocator(eo)
+ if err != nil {
+ return nil, err
+ }
+ return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil
+}
diff --git a/rackspace/rackconnect/v3/cloudnetworks/requests.go b/rackspace/rackconnect/v3/cloudnetworks/requests.go
new file mode 100644
index 0000000..33f5e04
--- /dev/null
+++ b/rackspace/rackconnect/v3/cloudnetworks/requests.go
@@ -0,0 +1,27 @@
+package cloudnetworks
+
+import (
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+// List returns all cloud networks that are associated with RackConnect. The ID
+// returned for each network is the same as the ID returned by the networks package.
+func List(c *gophercloud.ServiceClient) pagination.Pager {
+ url := listURL(c)
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return CloudNetworkPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(c, url, createPage)
+}
+
+// Get retrieves a specific cloud network (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
+}
diff --git a/rackspace/rackconnect/v3/cloudnetworks/requests_test.go b/rackspace/rackconnect/v3/cloudnetworks/requests_test.go
new file mode 100644
index 0000000..10d15dd
--- /dev/null
+++ b/rackspace/rackconnect/v3/cloudnetworks/requests_test.go
@@ -0,0 +1,87 @@
+package cloudnetworks
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
+)
+
+func TestListCloudNetworks(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/cloud_networks", 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, `[{
+ "cidr": "192.168.100.0/24",
+ "created": "2014-05-25T01:23:42Z",
+ "id": "07426958-1ebf-4c38-b032-d456820ca21a",
+ "name": "RC-CLOUD",
+ "updated": "2014-05-25T02:28:44Z"
+ }]`)
+ })
+
+ expected := []CloudNetwork{
+ CloudNetwork{
+ CIDR: "192.168.100.0/24",
+ CreatedAt: time.Date(2014, 5, 25, 1, 23, 42, 0, time.UTC),
+ ID: "07426958-1ebf-4c38-b032-d456820ca21a",
+ Name: "RC-CLOUD",
+ UpdatedAt: time.Date(2014, 5, 25, 2, 28, 44, 0, time.UTC),
+ },
+ }
+
+ count := 0
+ err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractCloudNetworks(page)
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestGetCloudNetwork(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/cloud_networks/07426958-1ebf-4c38-b032-d456820ca21a", 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, `{
+ "cidr": "192.168.100.0/24",
+ "created": "2014-05-25T01:23:42Z",
+ "id": "07426958-1ebf-4c38-b032-d456820ca21a",
+ "name": "RC-CLOUD",
+ "updated": "2014-05-25T02:28:44Z"
+ }`)
+ })
+
+ expected := &CloudNetwork{
+ CIDR: "192.168.100.0/24",
+ CreatedAt: time.Date(2014, 5, 25, 1, 23, 42, 0, time.UTC),
+ ID: "07426958-1ebf-4c38-b032-d456820ca21a",
+ Name: "RC-CLOUD",
+ UpdatedAt: time.Date(2014, 5, 25, 2, 28, 44, 0, time.UTC),
+ }
+
+ actual, err := Get(fake.ServiceClient(), "07426958-1ebf-4c38-b032-d456820ca21a").Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertDeepEquals(t, expected, actual)
+}
diff --git a/rackspace/rackconnect/v3/cloudnetworks/results.go b/rackspace/rackconnect/v3/cloudnetworks/results.go
new file mode 100644
index 0000000..f554a0d
--- /dev/null
+++ b/rackspace/rackconnect/v3/cloudnetworks/results.go
@@ -0,0 +1,113 @@
+package cloudnetworks
+
+import (
+ "fmt"
+ "reflect"
+ "time"
+
+ "github.com/mitchellh/mapstructure"
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+// CloudNetwork represents a network associated with a RackConnect configuration.
+type CloudNetwork struct {
+ // Specifies the ID of the newtork.
+ ID string `mapstructure:"id"`
+ // Specifies the user-provided name of the network.
+ Name string `mapstructure:"name"`
+ // Specifies the IP range for this network.
+ CIDR string `mapstructure:"cidr"`
+ // Specifies the time the network was created.
+ CreatedAt time.Time `mapstructure:"-"`
+ // Specifies the time the network was last updated.
+ UpdatedAt time.Time `mapstructure:"-"`
+}
+
+// CloudNetworkPage is the page returned by a pager when traversing over a
+// collection of CloudNetworks.
+type CloudNetworkPage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a CloudNetworkPage contains no CloudNetworks.
+func (r CloudNetworkPage) IsEmpty() (bool, error) {
+ cns, err := ExtractCloudNetworks(r)
+ if err != nil {
+ return true, err
+ }
+ return len(cns) == 0, nil
+}
+
+// ExtractCloudNetworks extracts and returns CloudNetworks. It is used while iterating over
+// a cloudnetworks.List call.
+func ExtractCloudNetworks(page pagination.Page) ([]CloudNetwork, error) {
+ var res []CloudNetwork
+ casted := page.(CloudNetworkPage).Body
+ err := mapstructure.Decode(casted, &res)
+
+ var rawNets []interface{}
+ switch casted.(type) {
+ case interface{}:
+ rawNets = casted.([]interface{})
+ default:
+ return res, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
+ }
+
+ for i := range rawNets {
+ thisNet := (rawNets[i]).(map[string]interface{})
+
+ if t, ok := thisNet["created"].(string); ok && t != "" {
+ creationTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].CreatedAt = creationTime
+ }
+
+ if t, ok := thisNet["updated"].(string); ok && t != "" {
+ updatedTime, err := time.Parse(time.RFC3339, t)
+ if err != nil {
+ return res, err
+ }
+ res[i].UpdatedAt = updatedTime
+ }
+ }
+
+ return res, err
+}
+
+// GetResult represents the result of a Get operation.
+type GetResult struct {
+ gophercloud.Result
+}
+
+// Extract is a function that extracts a CloudNetwork from a GetResult.
+func (r GetResult) Extract() (*CloudNetwork, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+ var res CloudNetwork
+
+ 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
+}
diff --git a/rackspace/rackconnect/v3/cloudnetworks/urls.go b/rackspace/rackconnect/v3/cloudnetworks/urls.go
new file mode 100644
index 0000000..bd6b098
--- /dev/null
+++ b/rackspace/rackconnect/v3/cloudnetworks/urls.go
@@ -0,0 +1,11 @@
+package cloudnetworks
+
+import "github.com/rackspace/gophercloud"
+
+func listURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL("cloud_networks")
+}
+
+func getURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("cloud_networks", id)
+}
diff --git a/rackspace/rackconnect/v3/doc.go b/rackspace/rackconnect/v3/doc.go
new file mode 100644
index 0000000..3a8279e
--- /dev/null
+++ b/rackspace/rackconnect/v3/doc.go
@@ -0,0 +1,4 @@
+// Package rackconnect allows Rackspace cloud accounts to leverage version 3 of
+// RackConnect, Rackspace's hybrid connectivity solution connecting dedicated
+// and cloud servers.
+package rackconnect
diff --git a/rackspace/rackconnect/v3/lbpools/doc.go b/rackspace/rackconnect/v3/lbpools/doc.go
new file mode 100644
index 0000000..f4319b8
--- /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 eligible 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..4b4a103
--- /dev/null
+++ b/rackspace/rackconnect/v3/lbpools/requests.go
@@ -0,0 +1,165 @@
+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
+}
+
+// NodeOpts are options for bulk adding/deleting nodes to LB pools.
+type NodeOpts struct {
+ ServerID string
+ PoolID string
+}
+
+// NodesOpts are a slice of NodeOpts, passed as options for bulk operations.
+type NodesOpts []NodeOpts
+
+// ToLBPoolCreateNodesMap serializes a NodesOpts into a map to send in the request.
+func (o NodesOpts) ToLBPoolCreateNodesMap() ([]map[string]interface{}, error) {
+ m := make([]map[string]interface{}, len(o))
+ for i := range o {
+ m[i] = map[string]interface{}{
+ "cloud_server": map[string]string{
+ "id": o[i].ServerID,
+ },
+ "load_balancer_pool": map[string]string{
+ "id": o[i].PoolID,
+ },
+ }
+ }
+ return m, nil
+}
+
+// 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, err := opts.ToLBPoolCreateNodesMap()
+ if err != nil {
+ res.Err = err
+ return res
+ }
+
+ _, 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, err := opts.ToLBPoolCreateNodesMap()
+ if err != nil {
+ res.Err = err
+ return res
+ }
+
+ _, res.Err = c.Request("DELETE", createNodesURL(c), gophercloud.RequestOpts{
+ JSONBody: &reqBody,
+ OkCodes: []int{204},
+ })
+ return res
+}
+
+// ListNodesDetailsForServer is similar to ListNodesDetails but only returns nodes
+// for 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..48ebcec
--- /dev/null
+++ b/rackspace/rackconnect/v3/lbpools/requests_test.go
@@ -0,0 +1,876 @@
+package lbpools
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+ "github.com/rackspace/gophercloud/testhelper/client"
+ 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{
+ NodeOpts{
+ ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ PoolID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ NodeOpts{
+ 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{
+ NodeOpts{
+ ServerID: "d95ae0c4-6ab8-4873-b82f-f8433840cff2",
+ PoolID: "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2",
+ },
+ NodeOpts{
+ 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)
+}
diff --git a/rackspace/rackconnect/v3/publicips/requests.go b/rackspace/rackconnect/v3/publicips/requests.go
new file mode 100644
index 0000000..82a5295
--- /dev/null
+++ b/rackspace/rackconnect/v3/publicips/requests.go
@@ -0,0 +1,59 @@
+package publicips
+
+import (
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+// List returns all public IPs.
+func List(c *gophercloud.ServiceClient) pagination.Pager {
+ url := listURL(c)
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return PublicIPPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(c, url, createPage)
+}
+
+// Create adds a public IP to the server with the given serverID.
+func Create(c *gophercloud.ServiceClient, serverID string) CreateResult {
+ var res CreateResult
+ reqBody := map[string]interface{}{
+ "cloud_server": map[string]string{
+ "id": serverID,
+ },
+ }
+ _, res.Err = c.Request("POST", createURL(c), gophercloud.RequestOpts{
+ JSONBody: &reqBody,
+ JSONResponse: &res.Body,
+ OkCodes: []int{201},
+ })
+ return res
+}
+
+// ListForServer returns all public IPs for the server with the given serverID.
+func ListForServer(c *gophercloud.ServiceClient, serverID string) pagination.Pager {
+ url := listForServerURL(c, serverID)
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return PublicIPPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(c, url, createPage)
+}
+
+// Get retrieves the public IP with the given 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
+}
+
+// Delete removes the public IP with the given id.
+func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
+ var res DeleteResult
+ _, res.Err = c.Request("DELETE", deleteURL(c, id), gophercloud.RequestOpts{
+ OkCodes: []int{204},
+ })
+ return res
+}
diff --git a/rackspace/rackconnect/v3/publicips/requests_test.go b/rackspace/rackconnect/v3/publicips/requests_test.go
new file mode 100644
index 0000000..61da2b0
--- /dev/null
+++ b/rackspace/rackconnect/v3/publicips/requests_test.go
@@ -0,0 +1,378 @@
+package publicips
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+ "github.com/rackspace/gophercloud/testhelper/client"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
+)
+
+func TestListIPs(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/public_ips", 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": "2d0f586b-37a7-4ae0-adac-2743d5feb450",
+ "public_ip_v4": "203.0.113.110",
+ "status": "ACTIVE",
+ "status_detail": null,
+ "updated": "2014-05-30T03:24:18Z"
+ }
+ ]`)
+ })
+
+ expected := []PublicIP{
+ PublicIP{
+ ID: "2d0f586b-37a7-4ae0-adac-2743d5feb450",
+ PublicIPv4: "203.0.113.110",
+ 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),
+ },
+ Status: "ACTIVE",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ },
+ }
+
+ count := 0
+ err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractPublicIPs(page)
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestCreateIP(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/public_ips", 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": {
+ "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": "2d0f586b-37a7-4ae0-adac-2743d5feb450",
+ "status": "ADDING"
+ }`)
+ })
+
+ expected := &PublicIP{
+ 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: "2d0f586b-37a7-4ae0-adac-2743d5feb450",
+ Status: "ADDING",
+ }
+
+ actual, err := Create(fake.ServiceClient(), "d95ae0c4-6ab8-4873-b82f-f8433840cff2").Extract()
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, expected, actual)
+}
+
+func TestGetIP(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/public_ips/2d0f586b-37a7-4ae0-adac-2743d5feb450", 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": {
+ "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": "2d0f586b-37a7-4ae0-adac-2743d5feb450",
+ "public_ip_v4": "203.0.113.110",
+ "status": "ACTIVE",
+ "status_detail": null,
+ "updated": "2014-05-30T03:24:18Z"
+ }`)
+ })
+
+ expected := &PublicIP{
+ 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: "2d0f586b-37a7-4ae0-adac-2743d5feb450",
+ Status: "ACTIVE",
+ PublicIPv4: "203.0.113.110",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ }
+
+ actual, err := Get(fake.ServiceClient(), "2d0f586b-37a7-4ae0-adac-2743d5feb450").Extract()
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, expected, actual)
+}
+
+func TestDeleteIP(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/public_ips/2d0f586b-37a7-4ae0-adac-2743d5feb450", 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 := Delete(client.ServiceClient(), "2d0f586b-37a7-4ae0-adac-2743d5feb450").ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestListForServer(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ th.Mux.HandleFunc("/public_ips", 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": "2d0f586b-37a7-4ae0-adac-2743d5feb450",
+ "public_ip_v4": "203.0.113.110",
+ "status": "ACTIVE",
+ "updated": "2014-05-30T03:24:18Z"
+ }
+ ]`)
+ })
+
+ expected := []PublicIP{
+ PublicIP{
+ 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: "2d0f586b-37a7-4ae0-adac-2743d5feb450",
+ Status: "ACTIVE",
+ PublicIPv4: "203.0.113.110",
+ UpdatedAt: time.Date(2014, 5, 30, 3, 24, 18, 0, time.UTC),
+ },
+ }
+ count := 0
+ err := ListForServer(fake.ServiceClient(), "d95ae0c4-6ab8-4873-b82f-f8433840cff2").EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractPublicIPs(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/publicips/results.go b/rackspace/rackconnect/v3/publicips/results.go
new file mode 100644
index 0000000..132cf77
--- /dev/null
+++ b/rackspace/rackconnect/v3/publicips/results.go
@@ -0,0 +1,221 @@
+package publicips
+
+import (
+ "fmt"
+ "reflect"
+ "time"
+
+ "github.com/mitchellh/mapstructure"
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+// PublicIP represents a public IP address.
+type PublicIP struct {
+ // The unique ID of the public IP.
+ ID string `mapstructure:"id"`
+ // The IPv4 address of the public IP.
+ PublicIPv4 string `mapstructure:"public_ip_v4"`
+ // The cloud server (node) of the public IP.
+ 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 status of the public IP.
+ Status string `mapstructure:"status"`
+ // The details of the status of the public IP.
+ StatusDetail string `mapstructure:"status_detail"`
+ // The time the public IP was created.
+ CreatedAt time.Time `mapstructure:"-"`
+ // The time the public IP was last updated.
+ UpdatedAt time.Time `mapstructure:"-"`
+}
+
+// PublicIPPage is the page returned by a pager when traversing over a
+// collection of PublicIPs.
+type PublicIPPage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a PublicIPPage contains no PublicIPs.
+func (r PublicIPPage) IsEmpty() (bool, error) {
+ n, err := ExtractPublicIPs(r)
+ if err != nil {
+ return true, err
+ }
+ return len(n) == 0, nil
+}
+
+// ExtractPublicIPs extracts and returns a slice of PublicIPs. It is used while iterating over
+// a publicips.List call.
+func ExtractPublicIPs(page pagination.Page) ([]PublicIP, error) {
+ var res []PublicIP
+ casted := page.(PublicIPPage).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
+}
+
+// PublicIPResult represents a result that can be extracted into a PublicIP.
+type PublicIPResult struct {
+ gophercloud.Result
+}
+
+// CreateResult represents the result of a Create operation.
+type CreateResult struct {
+ PublicIPResult
+}
+
+// GetResult represents the result of a Get operation.
+type GetResult struct {
+ PublicIPResult
+}
+
+// Extract is a function that extracts a PublicIP from a PublicIPResult.
+func (r PublicIPResult) Extract() (*PublicIP, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+ var res PublicIP
+ 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
+}
+
+// DeleteResult represents the result of a Delete operation.
+type DeleteResult struct {
+ gophercloud.ErrResult
+}
diff --git a/rackspace/rackconnect/v3/publicips/urls.go b/rackspace/rackconnect/v3/publicips/urls.go
new file mode 100644
index 0000000..6f310be
--- /dev/null
+++ b/rackspace/rackconnect/v3/publicips/urls.go
@@ -0,0 +1,25 @@
+package publicips
+
+import "github.com/rackspace/gophercloud"
+
+var root = "public_ips"
+
+func listURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL(root)
+}
+
+func createURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL(root)
+}
+
+func listForServerURL(c *gophercloud.ServiceClient, serverID string) string {
+ return c.ServiceURL(root + "?cloud_server_id=" + serverID)
+}
+
+func getURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL(root, id)
+}
+
+func deleteURL(c *gophercloud.ServiceClient, id string) string {
+ return getURL(c, id)
+}