blob: b3efacd64a88b4426499a1abc02dd53ff1a13a15 [file] [log] [blame]
Michal Kobusa1c3ca92019-08-21 14:29:23 +02001package drivers
2
3import (
4 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
5 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
6)
7
8type commonResult struct {
9 gophercloud.Result
10}
11
12func (r commonResult) Extract() (*Driver, error) {
13 var d struct {
14 Driver *Driver `json:"driver"`
15 }
16 err := r.ExtractInto(&d)
17 return d.Driver, err
18}
19
20type GetResult struct {
21 commonResult
22}
23
24type Link struct {
25 Href string `json:"href"`
26 Rel string `json:"rel"`
27}
28
29type Driver struct {
30 Name string `json:"name"`
31 Type string `json:"type"`
32 Hosts []string `json:"hosts"`
33 Links []Link `json:"links"`
34 Properties []Link `json:"properties"`
35}
36
37type DriverPage struct {
38 pagination.SinglePageBase
39}
40
41func (r DriverPage) NextPageURL() (string, error) {
42 var d struct {
43 Links []gophercloud.Link `json:"drivers_links"`
44 }
45 err := r.ExtractInto(&d)
46 if err != nil {
47 return "", err
48 }
49 return gophercloud.ExtractNextURL(d.Links)
50}
51
52func (r DriverPage) IsEmpty() (bool, error) {
53 is, err := ExtractDrivers(r)
54 return len(is) == 0, err
55}
56
57func ExtractDrivers(r pagination.Page) ([]Driver, error) {
58 var d struct {
59 Drivers []Driver `json:"drivers"`
60 }
61 err := (r.(DriverPage)).ExtractInto(&d)
62 return d.Drivers, err
63}