github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/conductors/results.go (about) 1 package conductors 2 3 import ( 4 "time" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 type conductorResult struct { 11 gophercloud.Result 12 } 13 14 // Extract interprets any conductorResult as a Conductor, if possible. 15 func (r conductorResult) Extract() (*Conductor, error) { 16 var s Conductor 17 err := r.ExtractInto(&s) 18 return &s, err 19 } 20 21 func (r conductorResult) ExtractInto(v interface{}) error { 22 return r.Result.ExtractIntoStructPtr(v, "") 23 } 24 25 func ExtractConductorInto(r pagination.Page, v interface{}) error { 26 return r.(ConductorPage).Result.ExtractIntoSlicePtr(v, "conductors") 27 } 28 29 // Conductor represents a conductor in the OpenStack Bare Metal API. 30 type Conductor struct { 31 // Whether or not this Conductor is alive or not 32 Alive bool `json:"alive"` 33 34 // Hostname of this conductor 35 Hostname string `json:"hostname"` 36 37 // Array of drivers for this conductor. 38 Drivers []string `json:"drivers"` 39 40 // Conductor group for a conductor. Case-insensitive string up to 255 characters, containing a-z, 0-9, _, -, and .. 41 ConductorGroup string `json:"conductor_group"` 42 43 // The UTC date and time when the resource was created, ISO 8601 format. 44 CreatedAt time.Time `json:"created_at"` 45 46 // The UTC date and time when the resource was updated, ISO 8601 format. May be “null”. 47 UpdatedAt time.Time `json:"updated_at"` 48 } 49 50 // ConductorPage abstracts the raw results of making a List() request against 51 // the API. As OpenStack extensions may freely alter the response bodies of 52 // structures returned to the client, you may only safely access the data 53 // provided through the ExtractConductor call. 54 type ConductorPage struct { 55 pagination.LinkedPageBase 56 } 57 58 // IsEmpty returns true if a page contains no conductor results. 59 func (r ConductorPage) IsEmpty() (bool, error) { 60 if r.StatusCode == 204 { 61 return true, nil 62 } 63 64 s, err := ExtractConductors(r) 65 return len(s) == 0, err 66 } 67 68 // NextPageURL uses the response's embedded link reference to navigate to the 69 // next page of results. 70 func (r ConductorPage) NextPageURL() (string, error) { 71 var s struct { 72 Links []gophercloud.Link `json:"conductor_links"` 73 } 74 err := r.ExtractInto(&s) 75 if err != nil { 76 return "", err 77 } 78 return gophercloud.ExtractNextURL(s.Links) 79 } 80 81 // ExtractConductors interprets the results of a single page from a List() call, 82 // producing a slice of Conductor entities. 83 func ExtractConductors(r pagination.Page) ([]Conductor, error) { 84 var s []Conductor 85 err := ExtractConductorInto(r, &s) 86 return s, err 87 } 88 89 // GetResult is the response from a Get operation. Call its Extract 90 // method to interpret it as a Conductor. 91 type GetResult struct { 92 conductorResult 93 }