blob: a7c22a2739b5c68b20d53148f5dd6437d58fb962 [file] [log] [blame]
Jon Perrittdf38cca2014-12-04 10:59:04 -07001package apiversions
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/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}