github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/conductors/requests.go (about) 1 package conductors 2 3 import ( 4 "fmt" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 // ListOptsBuilder allows extensions to add additional parameters to the 11 // List request. 12 type ListOptsBuilder interface { 13 ToConductorListQuery() (string, error) 14 } 15 16 // ListOpts allows the filtering and sorting of paginated collections through 17 // the API. Filtering is achieved by passing in struct field values that map to 18 // the conductor attributes you want to see returned. Marker and Limit are used 19 // for pagination. 20 type ListOpts struct { 21 // One or more fields to be returned in the response. 22 Fields []string `q:"fields"` 23 24 // Requests a page size of items. 25 Limit int `q:"limit"` 26 27 // The ID of the last-seen item. 28 Marker string `q:"marker"` 29 30 // Sorts the response by the requested sort direction. 31 SortDir string `q:"sort_dir"` 32 33 // Sorts the response by the this attribute value. 34 SortKey string `q:"sort_key"` 35 36 // Provide additional information for the BIOS Settings 37 Detail bool `q:"detail"` 38 } 39 40 // ToConductorListQuery formats a ListOpts into a query string. 41 func (opts ListOpts) ToConductorListQuery() (string, error) { 42 if opts.Detail == true && len(opts.Fields) > 0 { 43 return "", fmt.Errorf("cannot have both fields and detail options for conductors") 44 } 45 46 q, err := gophercloud.BuildQueryString(opts) 47 return q.String(), err 48 } 49 50 // List makes a request against the API to list conductors accessible to you. 51 func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 52 url := listURL(client) 53 if opts != nil { 54 query, err := opts.ToConductorListQuery() 55 if err != nil { 56 return pagination.Pager{Err: err} 57 } 58 url += query 59 } 60 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 61 return ConductorPage{pagination.LinkedPageBase{PageResult: r}} 62 }) 63 } 64 65 // Get requests details on a single conductor by hostname 66 func Get(client *gophercloud.ServiceClient, name string) (r GetResult) { 67 resp, err := client.Get(getURL(client, name), &r.Body, &gophercloud.RequestOpts{ 68 OkCodes: []int{200}, 69 }) 70 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 71 return 72 }