blob: 79a89de03a56ae1bfc25d3264da574a1ee9ef44d [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.
29func ExtractAPIVersions(page pagination.Page) ([]APIVersion, error) {
Jon Perritt12395212016-02-24 10:41:17 -060030 r := page.(APIVersionPage)
31 var s struct {
32 Versions []APIVersion `json:"versions"`
Jon Perrittfd53bba2014-10-03 00:41:22 -050033 }
Jon Perritt12395212016-02-24 10:41:17 -060034 err := r.ExtractInto(&s)
35 return s.Versions, err
Jon Perrittfd53bba2014-10-03 00:41:22 -050036}
37
Jamie Hannafordd8275bb2014-10-06 16:12:23 +020038// GetResult represents the result of a get operation.
Jon Perrittfd53bba2014-10-03 00:41:22 -050039type GetResult struct {
Ash Wilsonf548aad2014-10-20 08:35:34 -040040 gophercloud.Result
Jon Perrittfd53bba2014-10-03 00:41:22 -050041}
42
Jamie Hannafordd8275bb2014-10-06 16:12:23 +020043// Extract is a function that accepts a result and extracts an API version resource.
Jon Perrittfd53bba2014-10-03 00:41:22 -050044func (r GetResult) Extract() (*APIVersion, error) {
Jon Perritt12395212016-02-24 10:41:17 -060045 var s struct {
46 Version *APIVersion `json:"version"`
Jon Perrittfd53bba2014-10-03 00:41:22 -050047 }
Jon Perritt12395212016-02-24 10:41:17 -060048 err := r.ExtractInto(&s)
49 return s.Version, err
Jon Perrittfd53bba2014-10-03 00:41:22 -050050}