blob: f510c6d103abcba617d3ddbb182f88ccec49e706 [file] [log] [blame]
Jon Perrittfd53bba2014-10-03 00:41:22 -05001package apiversions
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Jon Perrittfd53bba2014-10-03 00:41:22 -05006)
7
8// APIVersion represents an API version for Cinder.
9type APIVersion struct {
Jon Perritt12395212016-02-24 10:41:17 -060010 ID string `json:"id"` // unique identifier
11 Status string `json:"status"` // current status
12 Updated string `json:"updated"` // date last updated
Jon Perrittfd53bba2014-10-03 00:41:22 -050013}
14
15// APIVersionPage is the page returned by a pager when traversing over a
16// collection of API versions.
17type APIVersionPage struct {
18 pagination.SinglePageBase
19}
20
21// IsEmpty checks whether an APIVersionPage struct is empty.
22func (r APIVersionPage) IsEmpty() (bool, error) {
23 is, err := ExtractAPIVersions(r)
Jon Perritt12395212016-02-24 10:41:17 -060024 return len(is) == 0, err
Jon Perrittfd53bba2014-10-03 00:41:22 -050025}
26
27// ExtractAPIVersions takes a collection page, extracts all of the elements,
28// and returns them a slice of APIVersion structs. It is effectively a cast.
Jon Perritt31b66462016-02-25 22:25:30 -060029func ExtractAPIVersions(r pagination.Page) ([]APIVersion, error) {
Jon Perritt12395212016-02-24 10:41:17 -060030 var s struct {
31 Versions []APIVersion `json:"versions"`
Jon Perrittfd53bba2014-10-03 00:41:22 -050032 }
Jon Perritt31b66462016-02-25 22:25:30 -060033 err := (r.(APIVersionPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060034 return s.Versions, err
Jon Perrittfd53bba2014-10-03 00:41:22 -050035}
36
Jamie Hannafordd8275bb2014-10-06 16:12:23 +020037// GetResult represents the result of a get operation.
Jon Perrittfd53bba2014-10-03 00:41:22 -050038type GetResult struct {
Ash Wilsonf548aad2014-10-20 08:35:34 -040039 gophercloud.Result
Jon Perrittfd53bba2014-10-03 00:41:22 -050040}
41
Jamie Hannafordd8275bb2014-10-06 16:12:23 +020042// Extract is a function that accepts a result and extracts an API version resource.
Jon Perrittfd53bba2014-10-03 00:41:22 -050043func (r GetResult) Extract() (*APIVersion, error) {
Jon Perritt12395212016-02-24 10:41:17 -060044 var s struct {
45 Version *APIVersion `json:"version"`
Jon Perrittfd53bba2014-10-03 00:41:22 -050046 }
Jon Perritt12395212016-02-24 10:41:17 -060047 err := r.ExtractInto(&s)
48 return s.Version, err
Jon Perrittfd53bba2014-10-03 00:41:22 -050049}