Delegate to common from networking, too.
diff --git a/openstack/networking/v2/extensions/delegate.go b/openstack/networking/v2/extensions/delegate.go
new file mode 100644
index 0000000..d08e1fd
--- /dev/null
+++ b/openstack/networking/v2/extensions/delegate.go
@@ -0,0 +1,41 @@
+package extensions
+
+import (
+ "github.com/rackspace/gophercloud"
+ common "github.com/rackspace/gophercloud/openstack/common/extensions"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+// Extension is a single OpenStack extension.
+type Extension struct {
+ common.Extension
+}
+
+// GetResult wraps a GetResult from common.
+type GetResult struct {
+ common.GetResult
+}
+
+// ExtractExtensions interprets a Page as a slice of Extensions.
+func ExtractExtensions(page pagination.Page) ([]Extension, error) {
+ inner, err := common.ExtractExtensions(page)
+ if err != nil {
+ return nil, err
+ }
+ outer := make([]Extension, len(inner))
+ for index, ext := range inner {
+ outer[index] = Extension{ext}
+ }
+ return outer, nil
+}
+
+// Get retrieves information for a specific extension using its alias.
+func Get(c *gophercloud.ServiceClient, alias string) GetResult {
+ return GetResult{common.Get(c, alias)}
+}
+
+// List returns a Pager which allows you to iterate over the full collection of extensions.
+// It does not accept query parameters.
+func List(c *gophercloud.ServiceClient) pagination.Pager {
+ return common.List(c)
+}
diff --git a/openstack/networking/v2/extensions/requests_test.go b/openstack/networking/v2/extensions/delegate_test.go
similarity index 84%
rename from openstack/networking/v2/extensions/requests_test.go
rename to openstack/networking/v2/extensions/delegate_test.go
index 5741280..5cc7c12 100644
--- a/openstack/networking/v2/extensions/requests_test.go
+++ b/openstack/networking/v2/extensions/delegate_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/rackspace/gophercloud"
+ common "github.com/rackspace/gophercloud/openstack/common/extensions"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
)
@@ -44,7 +45,7 @@
}
]
}
- `)
+ `)
})
count := 0
@@ -58,12 +59,14 @@
expected := []Extension{
Extension{
- Updated: "2013-01-20T00:00:00-00:00",
- Name: "Neutron Service Type Management",
- Links: []interface{}{},
- Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
- Alias: "service-type",
- Description: "API for retrieving service providers for Neutron advanced services",
+ common.Extension{
+ Updated: "2013-01-20T00:00:00-00:00",
+ Name: "Neutron Service Type Management",
+ Links: []interface{}{},
+ Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
+ Alias: "service-type",
+ Description: "API for retrieving service providers for Neutron advanced services",
+ },
},
}
@@ -99,7 +102,7 @@
"description": "The agent management extension."
}
}
- `)
+ `)
ext, err := Get(ServiceClient(), "agent").Extract()
th.AssertNoErr(t, err)
diff --git a/openstack/networking/v2/extensions/doc.go b/openstack/networking/v2/extensions/doc.go
deleted file mode 100644
index 7942c39..0000000
--- a/openstack/networking/v2/extensions/doc.go
+++ /dev/null
@@ -1,15 +0,0 @@
-// Package extensions provides information and interaction with the different
-// extensions available for the OpenStack Neutron service.
-//
-// The purpose of Networking API v2.0 extensions is to:
-//
-// - Introduce new features in the API without requiring a version change.
-// - Introduce vendor-specific niche functionality.
-// - Act as a proving ground for experimental functionalities that might be
-// included in a future version of the API.
-//
-// Extensions usually have tags that prevent conflicts with other extensions
-// that define attributes or resources with the same names, and with core
-// resources and attributes. Because an extension might not be supported by all
-// plug-ins, its availability varies with deployments and the specific plug-in.
-package extensions
diff --git a/openstack/networking/v2/extensions/errors.go b/openstack/networking/v2/extensions/errors.go
deleted file mode 100644
index aeec0fa..0000000
--- a/openstack/networking/v2/extensions/errors.go
+++ /dev/null
@@ -1 +0,0 @@
-package extensions
diff --git a/openstack/networking/v2/extensions/requests.go b/openstack/networking/v2/extensions/requests.go
deleted file mode 100644
index 8f7fd67..0000000
--- a/openstack/networking/v2/extensions/requests.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package extensions
-
-import (
- "github.com/racker/perigee"
- "github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud/pagination"
-)
-
-// Get retrieves information for a specific extension using its alias.
-func Get(c *gophercloud.ServiceClient, alias string) GetResult {
- var res GetResult
- _, err := perigee.Request("GET", extensionURL(c, alias), perigee.Options{
- MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
- OkCodes: []int{200},
- })
- res.Err = err
- return res
-}
-
-// List returns a Pager which allows you to iterate over the full collection of
-// extensions. It does not accept query parameters.
-func List(c *gophercloud.ServiceClient) pagination.Pager {
- return pagination.NewPager(c, listExtensionURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
- return ExtensionPage{pagination.SinglePageBase(r)}
- })
-}
diff --git a/openstack/networking/v2/extensions/results.go b/openstack/networking/v2/extensions/results.go
deleted file mode 100644
index 2b8408d..0000000
--- a/openstack/networking/v2/extensions/results.go
+++ /dev/null
@@ -1,71 +0,0 @@
-package extensions
-
-import (
- "fmt"
-
- "github.com/mitchellh/mapstructure"
- "github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud/pagination"
-)
-
-type GetResult struct {
- gophercloud.CommonResult
-}
-
-func (r GetResult) Extract() (*Extension, error) {
- if r.Err != nil {
- return nil, r.Err
- }
-
- var res struct {
- Extension *Extension `json:"extension"`
- }
-
- err := mapstructure.Decode(r.Resp, &res)
- if err != nil {
- return nil, fmt.Errorf("Error decoding Neutron extension: %v", err)
- }
-
- return res.Extension, nil
-}
-
-// Extension is a struct that represents a Neutron extension.
-type Extension struct {
- Updated string `json:"updated"`
- Name string `json:"name"`
- Links []interface{} `json:"links"`
- Namespace string `json:"namespace"`
- Alias string `json:"alias"`
- Description string `json:"description"`
-}
-
-// ExtensionPage is the page returned by a pager when traversing over a
-// collection of extensions.
-type ExtensionPage struct {
- pagination.SinglePageBase
-}
-
-// IsEmpty checks whether an ExtensionPage struct is empty.
-func (r ExtensionPage) IsEmpty() (bool, error) {
- is, err := ExtractExtensions(r)
- if err != nil {
- return true, err
- }
- return len(is) == 0, nil
-}
-
-// ExtractExtensions accepts a Page struct, specifically an ExtensionPage
-// struct, and extracts the elements into a slice of Extension structs. In other
-// words, a generic collection is mapped into a relevant slice.
-func ExtractExtensions(page pagination.Page) ([]Extension, error) {
- var resp struct {
- Extensions []Extension `mapstructure:"extensions"`
- }
-
- err := mapstructure.Decode(page.(ExtensionPage).Body, &resp)
- if err != nil {
- return nil, err
- }
-
- return resp.Extensions, nil
-}
diff --git a/openstack/networking/v2/extensions/urls.go b/openstack/networking/v2/extensions/urls.go
deleted file mode 100644
index e31e76c..0000000
--- a/openstack/networking/v2/extensions/urls.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package extensions
-
-import "github.com/rackspace/gophercloud"
-
-const version = "v2.0"
-
-func extensionURL(c *gophercloud.ServiceClient, name string) string {
- return c.ServiceURL(version, "extensions", name)
-}
-
-func listExtensionURL(c *gophercloud.ServiceClient) string {
- return c.ServiceURL(version, "extensions")
-}
diff --git a/openstack/networking/v2/extensions/urls_test.go b/openstack/networking/v2/extensions/urls_test.go
deleted file mode 100644
index 2a1e6a1..0000000
--- a/openstack/networking/v2/extensions/urls_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package extensions
-
-import (
- "testing"
-
- "github.com/rackspace/gophercloud"
- th "github.com/rackspace/gophercloud/testhelper"
-)
-
-const endpoint = "http://localhost:57909/"
-
-func endpointClient() *gophercloud.ServiceClient {
- return &gophercloud.ServiceClient{Endpoint: endpoint}
-}
-
-func TestExtensionURL(t *testing.T) {
- actual := extensionURL(endpointClient(), "agent")
- expected := endpoint + "v2.0/extensions/agent"
- th.AssertEquals(t, expected, actual)
-}
-
-func TestListExtensionURL(t *testing.T) {
- actual := listExtensionURL(endpointClient())
- expected := endpoint + "v2.0/extensions"
- th.AssertEquals(t, expected, actual)
-}