rackconnect public ips ops and unit tests
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..de1df7a
--- /dev/null
+++ b/rackspace/rackconnect/v3/publicips/requests_test.go
@@ -0,0 +1,378 @@
+package publicips
+
+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 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)
+}