Add Instance result struct
diff --git a/rackspace/db/v1/instances/delegate.go b/rackspace/db/v1/instances/delegate.go
index 93f4ce4..3e5596f 100644
--- a/rackspace/db/v1/instances/delegate.go
+++ b/rackspace/db/v1/instances/delegate.go
@@ -223,6 +223,7 @@
resp, err := perigee.Request("POST", createURL(client), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
ReqBody: &reqBody,
+ Results: &res.Body,
OkCodes: []int{200},
})
diff --git a/rackspace/db/v1/instances/delegate_test.go b/rackspace/db/v1/instances/delegate_test.go
index 8470c0c..d995365 100644
--- a/rackspace/db/v1/instances/delegate_test.go
+++ b/rackspace/db/v1/instances/delegate_test.go
@@ -3,6 +3,7 @@
import (
"testing"
+ "github.com/rackspace/gophercloud"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
)
@@ -33,5 +34,29 @@
RestorePoint: "1234567890",
}
- _ = Create(fake.ServiceClient(), opts)
+ instance, err := Create(fake.ServiceClient(), opts).Extract()
+
+ expected := &Instance{
+ Created: "2014-02-13T21:47:13",
+ Updated: "2014-02-13T21:47:13",
+ Datastore: Datastore{Type: "mysql", Version: "5.6"},
+ Flavor: Flavor{
+ ID: "1",
+ Links: []gophercloud.Link{
+ gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
+ gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
+ },
+ },
+ Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
+ ID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
+ Links: []gophercloud.Link{
+ gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
+ },
+ Name: "json_rack_instance",
+ Status: "BUILD",
+ Volume: Volume{Size: 2},
+ }
+
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, expected, instance)
}
diff --git a/rackspace/db/v1/instances/fixtures.go b/rackspace/db/v1/instances/fixtures.go
index 7fde6e5..79537ab 100644
--- a/rackspace/db/v1/instances/fixtures.go
+++ b/rackspace/db/v1/instances/fixtures.go
@@ -54,11 +54,35 @@
fmt.Fprintf(w, `
{
"instance": {
- "flavorRef": 1,
- "name": "json_restore",
- "restorePoint": {
- "backupRef": "61f12fef-edb1-4561-8122-e7c00ef26a82"
+ "created": "2014-02-13T21:47:13",
+ "datastore": {
+ "type": "mysql",
+ "version": "5.6"
},
+ "flavor": {
+ "id": "1",
+ "links": [
+ {
+ "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
+ "rel": "self"
+ },
+ {
+ "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ "links": [
+ {
+ "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
+ "rel": "self"
+ }
+ ],
+ "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
+ "id": "d4603f69-ec7e-4e9b-803f-600b9205576f",
+ "name": "json_rack_instance",
+ "status": "BUILD",
+ "updated": "2014-02-13T21:47:13",
"volume": {
"size": 2
}
diff --git a/rackspace/db/v1/instances/results.go b/rackspace/db/v1/instances/results.go
index 2d44e08..66b3ce1 100644
--- a/rackspace/db/v1/instances/results.go
+++ b/rackspace/db/v1/instances/results.go
@@ -1,8 +1,59 @@
package instances
-import "github.com/rackspace/gophercloud"
+import (
+ "github.com/mitchellh/mapstructure"
+ "github.com/rackspace/gophercloud"
+)
+
+type Datastore struct {
+ Type string
+ Version string
+}
+
+type Flavor struct {
+ ID string
+ Links []gophercloud.Link
+}
+
+type Volume struct {
+ Size int
+}
+
+type Instance struct {
+ Created string //time.Time
+ Updated string //time.Time
+ Datastore Datastore
+ Flavor Flavor
+ Hostname string
+ ID string
+ Links []gophercloud.Link
+ Name string
+ Status string
+ Volume Volume
+}
// CreateResult represents the result of a Create operation.
type CreateResult struct {
gophercloud.Result
}
+
+// func handleInstanceConversion(from reflect.Kind, to reflect.Kind, data interface{}) (interface{}, error) {
+// if (from == reflect.String) && (to == reflect.Map) {
+// return map[string]interface{}{}, nil
+// }
+// return data, nil
+// }
+
+func (r CreateResult) Extract() (*Instance, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+
+ var response struct {
+ Instance Instance `mapstructure:"instance"`
+ }
+
+ err := mapstructure.Decode(r.Body, &response)
+
+ return &response.Instance, err
+}