fix general issues
diff --git a/rackspace/db/v1/datastores/delegate.go b/rackspace/db/v1/datastores/delegate.go
new file mode 100644
index 0000000..573496d
--- /dev/null
+++ b/rackspace/db/v1/datastores/delegate.go
@@ -0,0 +1,28 @@
+package datastores
+
+import (
+ "github.com/rackspace/gophercloud"
+ os "github.com/rackspace/gophercloud/openstack/db/v1/datastores"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+// List will list all available flavors.
+func List(client *gophercloud.ServiceClient) pagination.Pager {
+ return os.List(client)
+}
+
+// Get retrieves the details for a particular flavor.
+func Get(client *gophercloud.ServiceClient, flavorID string) os.GetResult {
+ return os.Get(client, flavorID)
+}
+
+// ListVersions will list all of the available versions for a specified
+// datastore type.
+func ListVersions(client *gophercloud.ServiceClient, datastoreID string) pagination.Pager {
+ return os.ListVersions(client, datastoreID)
+}
+
+// GetVersion will retrieve the details of a specified datastore version.
+func GetVersion(client *gophercloud.ServiceClient, datastoreID, versionID string) os.GetVersionResult {
+ return os.GetVersion(client, datastoreID, versionID)
+}
diff --git a/rackspace/db/v1/datastores/requests_test.go b/rackspace/db/v1/datastores/delegate_test.go
similarity index 69%
rename from rackspace/db/v1/datastores/requests_test.go
rename to rackspace/db/v1/datastores/delegate_test.go
index 5246310..71111b9 100644
--- a/rackspace/db/v1/datastores/requests_test.go
+++ b/rackspace/db/v1/datastores/delegate_test.go
@@ -3,6 +3,7 @@
import (
"testing"
+ os "github.com/rackspace/gophercloud/openstack/db/v1/datastores"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
@@ -12,19 +13,19 @@
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- fixture.SetupHandler(t, "/datastores", "GET", "", listDSResp, 200)
+ fixture.SetupHandler(t, "/datastores", "GET", "", os.ListDSResp, 200)
pages := 0
err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
pages++
- actual, err := ExtractDatastores(page)
+ actual, err := os.ExtractDatastores(page)
if err != nil {
return false, err
}
- th.CheckDeepEquals(t, []Datastore{exampleDatastore}, actual)
+ th.CheckDeepEquals(t, []os.Datastore{os.ExampleDatastore}, actual)
return true, nil
})
@@ -36,29 +37,29 @@
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- fixture.SetupHandler(t, "/datastores/{dsID}", "GET", "", getDSResp, 200)
+ fixture.SetupHandler(t, "/datastores/{dsID}", "GET", "", os.GetDSResp, 200)
ds, err := Get(fake.ServiceClient(), "{dsID}").Extract()
th.AssertNoErr(t, err)
- th.AssertDeepEquals(t, &exampleDatastore, ds)
+ th.AssertDeepEquals(t, &os.ExampleDatastore, ds)
}
func TestListVersions(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- fixture.SetupHandler(t, "/datastores/{dsID}/versions", "GET", "", listVersionsResp, 200)
+ fixture.SetupHandler(t, "/datastores/{dsID}/versions", "GET", "", os.ListVersionsResp, 200)
pages := 0
err := ListVersions(fake.ServiceClient(), "{dsID}").EachPage(func(page pagination.Page) (bool, error) {
pages++
- actual, err := ExtractVersions(page)
+ actual, err := os.ExtractVersions(page)
if err != nil {
return false, err
}
- th.CheckDeepEquals(t, exampleVersions, actual)
+ th.CheckDeepEquals(t, os.ExampleVersions, actual)
return true, nil
})
@@ -70,9 +71,9 @@
func TestGetVersion(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- fixture.SetupHandler(t, "/datastores/{dsID}/versions/{versionID}", "GET", "", getVersionResp, 200)
+ fixture.SetupHandler(t, "/datastores/{dsID}/versions/{versionID}", "GET", "", os.GetVersionResp, 200)
ds, err := GetVersion(fake.ServiceClient(), "{dsID}", "{versionID}").Extract()
th.AssertNoErr(t, err)
- th.AssertDeepEquals(t, &exampleVersion1, ds)
+ th.AssertDeepEquals(t, &os.ExampleVersion1, ds)
}
diff --git a/rackspace/db/v1/datastores/doc.go b/rackspace/db/v1/datastores/doc.go
index ae14026..f36997a 100644
--- a/rackspace/db/v1/datastores/doc.go
+++ b/rackspace/db/v1/datastores/doc.go
@@ -1,3 +1 @@
-// Package datastores provides information and interaction with the datastore
-// API resource in the Rackspace Database service.
package datastores
diff --git a/rackspace/db/v1/datastores/fixtures.go b/rackspace/db/v1/datastores/fixtures.go
deleted file mode 100644
index 842aa77..0000000
--- a/rackspace/db/v1/datastores/fixtures.go
+++ /dev/null
@@ -1,100 +0,0 @@
-package datastores
-
-import (
- "fmt"
-
- "github.com/rackspace/gophercloud"
-)
-
-const version1JSON = `
-{
- "id": "b00000b0-00b0-0b00-00b0-000b000000bb",
- "links": [
- {
- "href": "https://api.staging.ord1.clouddb.rackspace.net/v1.0/1234/datastores/versions/b00000b0-00b0-0b00-00b0-000b000000bb",
- "rel": "self"
- },
- {
- "href": "https://api.staging.ord1.clouddb.rackspace.net/datastores/versions/b00000b0-00b0-0b00-00b0-000b000000bb",
- "rel": "bookmark"
- }
- ],
- "name": "5.1"
-}
-`
-
-const version2JSON = `
-{
- "id": "c00000b0-00c0-0c00-00c0-000b000000cc",
- "links": [
- {
- "href": "https://api.staging.ord1.clouddb.rackspace.net/v1.0/1234/datastores/versions/c00000b0-00c0-0c00-00c0-000b000000cc",
- "rel": "self"
- },
- {
- "href": "https://api.staging.ord1.clouddb.rackspace.net/datastores/versions/c00000b0-00c0-0c00-00c0-000b000000cc",
- "rel": "bookmark"
- }
- ],
- "name": "5.2"
-}
-`
-
-var versionsJSON = fmt.Sprintf(`"versions": [%s, %s]`, version1JSON, version2JSON)
-
-var singleDSJSON = fmt.Sprintf(`
-{
- "default_version": "c00000b0-00c0-0c00-00c0-000b000000cc",
- "id": "10000000-0000-0000-0000-000000000001",
- "links": [
- {
- "href": "https://api.staging.ord1.clouddb.rackspace.net/v1.0/1234/datastores/10000000-0000-0000-0000-000000000001",
- "rel": "self"
- },
- {
- "href": "https://api.staging.ord1.clouddb.rackspace.net/datastores/10000000-0000-0000-0000-000000000001",
- "rel": "bookmark"
- }
- ],
- "name": "mysql",
- %s
-}
-`, versionsJSON)
-
-var (
- listDSResp = fmt.Sprintf(`{"datastores":[%s]}`, singleDSJSON)
- getDSResp = fmt.Sprintf(`{"datastore":%s}`, singleDSJSON)
- listVersionsResp = fmt.Sprintf(`{%s}`, versionsJSON)
- getVersionResp = fmt.Sprintf(`{"version":%s}`, version1JSON)
-)
-
-var exampleVersion1 = Version{
- ID: "b00000b0-00b0-0b00-00b0-000b000000bb",
- Links: []gophercloud.Link{
- gophercloud.Link{Rel: "self", Href: "https://api.staging.ord1.clouddb.rackspace.net/v1.0/1234/datastores/versions/b00000b0-00b0-0b00-00b0-000b000000bb"},
- gophercloud.Link{Rel: "bookmark", Href: "https://api.staging.ord1.clouddb.rackspace.net/datastores/versions/b00000b0-00b0-0b00-00b0-000b000000bb"},
- },
- Name: "5.1",
-}
-
-var exampleVersion2 = Version{
- ID: "c00000b0-00c0-0c00-00c0-000b000000cc",
- Links: []gophercloud.Link{
- gophercloud.Link{Rel: "self", Href: "https://api.staging.ord1.clouddb.rackspace.net/v1.0/1234/datastores/versions/c00000b0-00c0-0c00-00c0-000b000000cc"},
- gophercloud.Link{Rel: "bookmark", Href: "https://api.staging.ord1.clouddb.rackspace.net/datastores/versions/c00000b0-00c0-0c00-00c0-000b000000cc"},
- },
- Name: "5.2",
-}
-
-var exampleVersions = []Version{exampleVersion1, exampleVersion2}
-
-var exampleDatastore = Datastore{
- DefaultVersion: "c00000b0-00c0-0c00-00c0-000b000000cc",
- ID: "10000000-0000-0000-0000-000000000001",
- Links: []gophercloud.Link{
- gophercloud.Link{Rel: "self", Href: "https://api.staging.ord1.clouddb.rackspace.net/v1.0/1234/datastores/10000000-0000-0000-0000-000000000001"},
- gophercloud.Link{Rel: "bookmark", Href: "https://api.staging.ord1.clouddb.rackspace.net/datastores/10000000-0000-0000-0000-000000000001"},
- },
- Name: "mysql",
- Versions: exampleVersions,
-}
diff --git a/rackspace/db/v1/datastores/requests.go b/rackspace/db/v1/datastores/requests.go
deleted file mode 100644
index 9e147ab..0000000
--- a/rackspace/db/v1/datastores/requests.go
+++ /dev/null
@@ -1,47 +0,0 @@
-package datastores
-
-import (
- "github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud/pagination"
-)
-
-// List will list all available datastore types that instances can use.
-func List(client *gophercloud.ServiceClient) pagination.Pager {
- pageFn := func(r pagination.PageResult) pagination.Page {
- return DatastorePage{pagination.SinglePageBase(r)}
- }
- return pagination.NewPager(client, baseURL(client), pageFn)
-}
-
-// Get will retrieve the details of a specified datastore type.
-func Get(client *gophercloud.ServiceClient, datastoreID string) GetResult {
- var res GetResult
-
- _, res.Err = client.Request("GET", resourceURL(client, datastoreID), gophercloud.RequestOpts{
- OkCodes: []int{200},
- JSONResponse: &res.Body,
- })
-
- return res
-}
-
-// ListVersions will list all of the available versions for a specified
-// datastore type.
-func ListVersions(client *gophercloud.ServiceClient, datastoreID string) pagination.Pager {
- pageFn := func(r pagination.PageResult) pagination.Page {
- return VersionPage{pagination.SinglePageBase(r)}
- }
- return pagination.NewPager(client, versionsURL(client, datastoreID), pageFn)
-}
-
-// GetVersion will retrieve the details of a specified datastore version.
-func GetVersion(client *gophercloud.ServiceClient, datastoreID, versionID string) GetVersionResult {
- var res GetVersionResult
-
- _, res.Err = client.Request("GET", versionURL(client, datastoreID, versionID), gophercloud.RequestOpts{
- OkCodes: []int{200},
- JSONResponse: &res.Body,
- })
-
- return res
-}
diff --git a/rackspace/db/v1/datastores/results.go b/rackspace/db/v1/datastores/results.go
deleted file mode 100644
index a86a3cc..0000000
--- a/rackspace/db/v1/datastores/results.go
+++ /dev/null
@@ -1,123 +0,0 @@
-package datastores
-
-import (
- "github.com/mitchellh/mapstructure"
- "github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud/pagination"
-)
-
-// Version represents a version API resource. Multiple versions belong to a Datastore.
-type Version struct {
- ID string
- Links []gophercloud.Link
- Name string
-}
-
-// Datastore represents a Datastore API resource.
-type Datastore struct {
- DefaultVersion string `json:"default_version" mapstructure:"default_version"`
- ID string
- Links []gophercloud.Link
- Name string
- Versions []Version
-}
-
-// DatastorePartial is a meta structure which is used in various API responses.
-// It is a lightweight and truncated version of a full Datastore resource,
-// offering details of the Version, Type and VersionID only.
-type DatastorePartial struct {
- Version string
- Type string
- VersionID string `json:"version_id" mapstructure:"version_id"`
-}
-
-// GetResult represents the result of a Get operation.
-type GetResult struct {
- gophercloud.Result
-}
-
-// GetVersionResult represents the result of getting a version.
-type GetVersionResult struct {
- gophercloud.Result
-}
-
-// DatastorePage represents a page of datastore resources.
-type DatastorePage struct {
- pagination.SinglePageBase
-}
-
-// IsEmpty indicates whether a Datastore collection is empty.
-func (r DatastorePage) IsEmpty() (bool, error) {
- is, err := ExtractDatastores(r)
- if err != nil {
- return true, err
- }
- return len(is) == 0, nil
-}
-
-// ExtractDatastores retrieves a slice of datastore structs from a paginated
-// collection.
-func ExtractDatastores(page pagination.Page) ([]Datastore, error) {
- casted := page.(DatastorePage).Body
-
- var resp struct {
- Datastores []Datastore `mapstructure:"datastores" json:"datastores"`
- }
-
- err := mapstructure.Decode(casted, &resp)
- return resp.Datastores, err
-}
-
-// Extract retrieves a single Datastore struct from an operation result.
-func (r GetResult) Extract() (*Datastore, error) {
- if r.Err != nil {
- return nil, r.Err
- }
-
- var response struct {
- Datastore Datastore `mapstructure:"datastore"`
- }
-
- err := mapstructure.Decode(r.Body, &response)
- return &response.Datastore, err
-}
-
-// DatastorePage represents a page of version resources.
-type VersionPage struct {
- pagination.SinglePageBase
-}
-
-// IsEmpty indicates whether a collection of version resources is empty.
-func (r VersionPage) IsEmpty() (bool, error) {
- is, err := ExtractVersions(r)
- if err != nil {
- return true, err
- }
- return len(is) == 0, nil
-}
-
-// ExtractVersions retrieves a slice of versions from a paginated collection.
-func ExtractVersions(page pagination.Page) ([]Version, error) {
- casted := page.(VersionPage).Body
-
- var resp struct {
- Versions []Version `mapstructure:"versions" json:"versions"`
- }
-
- err := mapstructure.Decode(casted, &resp)
- return resp.Versions, err
-}
-
-// Extract retrieves a single Version struct from an operation result.
-func (r GetVersionResult) Extract() (*Version, error) {
- if r.Err != nil {
- return nil, r.Err
- }
-
- var response struct {
- Version Version `mapstructure:"version"`
- }
-
- err := mapstructure.Decode(r.Body, &response)
- return &response.Version, err
-}
diff --git a/rackspace/db/v1/datastores/urls.go b/rackspace/db/v1/datastores/urls.go
deleted file mode 100644
index c4d5248..0000000
--- a/rackspace/db/v1/datastores/urls.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package datastores
-
-import "github.com/rackspace/gophercloud"
-
-func baseURL(c *gophercloud.ServiceClient) string {
- return c.ServiceURL("datastores")
-}
-
-func resourceURL(c *gophercloud.ServiceClient, dsID string) string {
- return c.ServiceURL("datastores", dsID)
-}
-
-func versionsURL(c *gophercloud.ServiceClient, dsID string) string {
- return c.ServiceURL("datastores", dsID, "versions")
-}
-
-func versionURL(c *gophercloud.ServiceClient, dsID, versionID string) string {
- return c.ServiceURL("datastores", dsID, "versions", versionID)
-}