blob: 43a8afa3d795a2839e561d6f78dc6ba410f364ea [file] [log] [blame]
Jon Perrittdf38cca2014-12-04 10:59:04 -07001package apiversions
2
3import (
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02004 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02005 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
Jon Perrittdf38cca2014-12-04 10:59:04 -07006)
7
Jon Perrittdf38cca2014-12-04 10:59:04 -07008// APIVersion represents an API version for Neutron. It contains the status of
9// the API, and its unique ID.
10type APIVersion struct {
Jon Perritt3c166472016-02-25 03:07:41 -060011 Status string `json:"status"`
12 ID string `json:"id"`
13 Links []gophercloud.Link `json:"links"`
Jon Perrittdf38cca2014-12-04 10:59:04 -070014}
15
16// APIVersionPage is the page returned by a pager when traversing over a
17// collection of API versions.
18type APIVersionPage struct {
19 pagination.SinglePageBase
20}
21
22// IsEmpty checks whether an APIVersionPage struct is empty.
23func (r APIVersionPage) IsEmpty() (bool, error) {
24 is, err := ExtractAPIVersions(r)
Jon Perritt3c166472016-02-25 03:07:41 -060025 return len(is) == 0, err
Jon Perrittdf38cca2014-12-04 10:59:04 -070026}
27
28// ExtractAPIVersions takes a collection page, extracts all of the elements,
29// and returns them a slice of APIVersion structs. It is effectively a cast.
Jon Perritt3c166472016-02-25 03:07:41 -060030func ExtractAPIVersions(r pagination.Page) ([]APIVersion, error) {
31 var s struct {
32 APIVersions []APIVersion `json:"versions"`
Jon Perrittdf38cca2014-12-04 10:59:04 -070033 }
Jon Perritt3c166472016-02-25 03:07:41 -060034 err := (r.(APIVersionPage)).ExtractInto(&s)
35 return s.APIVersions, err
Jon Perrittdf38cca2014-12-04 10:59:04 -070036}