blob: 1b15dbc3384feb398f72cf4bb953e990378bea30 [file] [log] [blame]
Jon Perritt23e89c32015-01-19 15:39:45 -07001package flavors
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Jon Perritt23e89c32015-01-19 15:39:45 -07006)
7
8// Provider represents a provider for a particular flavor.
9type Provider struct {
10 // Specifies the name of the provider. The name must not exceed 64 bytes in
11 // length and is limited to unicode, digits, underscores, and hyphens.
Jon Perritt12395212016-02-24 10:41:17 -060012 Provider string `json:"provider"`
Jon Perritt23e89c32015-01-19 15:39:45 -070013 // Specifies a list with an href where rel is provider_url.
Jon Perritt12395212016-02-24 10:41:17 -060014 Links []gophercloud.Link `json:"links"`
Jon Perritt23e89c32015-01-19 15:39:45 -070015}
16
17// Flavor represents a mapping configuration to a CDN provider.
18type Flavor struct {
19 // Specifies the name of the flavor. The name must not exceed 64 bytes in
20 // length and is limited to unicode, digits, underscores, and hyphens.
Jon Perritt12395212016-02-24 10:41:17 -060021 ID string `json:"id"`
Jon Perritt23e89c32015-01-19 15:39:45 -070022 // Specifies the list of providers mapped to this flavor.
Jon Perritt12395212016-02-24 10:41:17 -060023 Providers []Provider `json:"providers"`
Jon Perritt23e89c32015-01-19 15:39:45 -070024 // Specifies the self-navigating JSON document paths.
Jon Perritt12395212016-02-24 10:41:17 -060025 Links []gophercloud.Link `json:"links"`
Jon Perritt23e89c32015-01-19 15:39:45 -070026}
27
28// FlavorPage is the page returned by a pager when traversing over a
29// collection of CDN flavors.
30type FlavorPage struct {
31 pagination.SinglePageBase
32}
33
34// IsEmpty returns true if a FlavorPage contains no Flavors.
35func (r FlavorPage) IsEmpty() (bool, error) {
36 flavors, err := ExtractFlavors(r)
37 if err != nil {
38 return true, err
39 }
40 return len(flavors) == 0, nil
41}
42
43// ExtractFlavors extracts and returns Flavors. It is used while iterating over
44// a flavors.List call.
45func ExtractFlavors(page pagination.Page) ([]Flavor, error) {
Jon Perritt12395212016-02-24 10:41:17 -060046 r := page.(FlavorPage)
47 var s struct {
Jon Perritt23e89c32015-01-19 15:39:45 -070048 Flavors []Flavor `json:"flavors"`
49 }
Jon Perritt12395212016-02-24 10:41:17 -060050 err := r.ExtractInto(&s)
51 return s.Flavors, err
Jon Perritt23e89c32015-01-19 15:39:45 -070052}
53
54// GetResult represents the result of a get operation.
55type GetResult struct {
56 gophercloud.Result
57}
58
59// Extract is a function that extracts a flavor from a GetResult.
60func (r GetResult) Extract() (*Flavor, error) {
Jon Perritt12395212016-02-24 10:41:17 -060061 var s Flavor
62 err := r.ExtractInto(&s)
63 return &s, err
Jon Perritt23e89c32015-01-19 15:39:45 -070064}