blob: 02c285134b8913b16b6743e14ba46d208c636a98 [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)
Jon Perritt31b66462016-02-25 22:25:30 -060037 return len(flavors) == 0, err
Jon Perritt23e89c32015-01-19 15:39:45 -070038}
39
40// ExtractFlavors extracts and returns Flavors. It is used while iterating over
41// a flavors.List call.
Jon Perritt31b66462016-02-25 22:25:30 -060042func ExtractFlavors(r pagination.Page) ([]Flavor, error) {
Jon Perritt12395212016-02-24 10:41:17 -060043 var s struct {
Jon Perritt23e89c32015-01-19 15:39:45 -070044 Flavors []Flavor `json:"flavors"`
45 }
Jon Perritt31b66462016-02-25 22:25:30 -060046 err := (r.(FlavorPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060047 return s.Flavors, err
Jon Perritt23e89c32015-01-19 15:39:45 -070048}
49
50// GetResult represents the result of a get operation.
51type GetResult struct {
52 gophercloud.Result
53}
54
55// Extract is a function that extracts a flavor from a GetResult.
56func (r GetResult) Extract() (*Flavor, error) {
Jon Perritt31b66462016-02-25 22:25:30 -060057 var s *Flavor
Jon Perritt12395212016-02-24 10:41:17 -060058 err := r.ExtractInto(&s)
Jon Perritt31b66462016-02-25 22:25:30 -060059 return s, err
Jon Perritt23e89c32015-01-19 15:39:45 -070060}