blob: b6006ab4b9cd9f4e7aa1f929f35e051ef240a91b [file] [log] [blame]
Ash Wilson318666f2014-10-03 08:38:39 -04001package extensions
2
3import (
4 "github.com/rackspace/gophercloud"
5 common "github.com/rackspace/gophercloud/openstack/common/extensions"
6 "github.com/rackspace/gophercloud/pagination"
7)
8
9// Extension is a single OpenStack extension.
10type Extension struct {
11 common.Extension
12}
13
14// GetResult wraps a GetResult from common.
15type GetResult struct {
16 common.GetResult
17}
18
19// ExtractExtensions interprets a Page as a slice of Extensions.
20func ExtractExtensions(page pagination.Page) ([]Extension, error) {
21 inner, err := common.ExtractExtensions(page)
22 if err != nil {
23 return nil, err
24 }
25 outer := make([]Extension, len(inner))
26 for index, ext := range inner {
27 outer[index] = Extension{ext}
28 }
29 return outer, nil
30}
31
Ash Wilsonf2f6c0a2014-10-06 14:27:20 -040032// rebased is a temporary workaround to isolate changes to this package. FIXME: set ResourceBase
33// in the NewNetworkV2 method and remove the version string from URL generation methods in
34// networking resources.
35func rebased(c *gophercloud.ServiceClient) *gophercloud.ServiceClient {
36 var r = *c
37 r.ResourceBase = c.Endpoint + "v2.0/"
38 return &r
39}
40
Ash Wilson318666f2014-10-03 08:38:39 -040041// Get retrieves information for a specific extension using its alias.
42func Get(c *gophercloud.ServiceClient, alias string) GetResult {
Ash Wilsonf2f6c0a2014-10-06 14:27:20 -040043 return GetResult{common.Get(rebased(c), alias)}
Ash Wilson318666f2014-10-03 08:38:39 -040044}
45
46// List returns a Pager which allows you to iterate over the full collection of extensions.
47// It does not accept query parameters.
48func List(c *gophercloud.ServiceClient) pagination.Pager {
Ash Wilsonf2f6c0a2014-10-06 14:27:20 -040049 return common.List(rebased(c))
Ash Wilson318666f2014-10-03 08:38:39 -040050}