Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame^] | 1 | package drivers |
| 2 | |
| 3 | import ( |
| 4 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
| 5 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
| 6 | ) |
| 7 | |
| 8 | type commonResult struct { |
| 9 | gophercloud.Result |
| 10 | } |
| 11 | |
| 12 | func (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 | |
| 20 | type GetResult struct { |
| 21 | commonResult |
| 22 | } |
| 23 | |
| 24 | type Link struct { |
| 25 | Href string `json:"href"` |
| 26 | Rel string `json:"rel"` |
| 27 | } |
| 28 | |
| 29 | type 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 | |
| 37 | type DriverPage struct { |
| 38 | pagination.SinglePageBase |
| 39 | } |
| 40 | |
| 41 | func (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 | |
| 52 | func (r DriverPage) IsEmpty() (bool, error) { |
| 53 | is, err := ExtractDrivers(r) |
| 54 | return len(is) == 0, err |
| 55 | } |
| 56 | |
| 57 | func 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 | } |