github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/drivers/requests.go (about)

     1  package drivers
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // ListDriversOptsBuilder allows extensions to add additional parameters to the
     9  // ListDrivers request.
    10  type ListDriversOptsBuilder interface {
    11  	ToListDriversOptsQuery() (string, error)
    12  }
    13  
    14  // ListDriversOpts defines query options that can be passed to ListDrivers
    15  type ListDriversOpts struct {
    16  	// Provide detailed information about the drivers
    17  	Detail bool `q:"detail"`
    18  
    19  	// Filter the list by the type of the driver
    20  	Type string `q:"type"`
    21  }
    22  
    23  // ToListDriversOptsQuery formats a ListOpts into a query string
    24  func (opts ListDriversOpts) ToListDriversOptsQuery() (string, error) {
    25  	q, err := gophercloud.BuildQueryString(opts)
    26  	return q.String(), err
    27  }
    28  
    29  // ListDrivers makes a request against the API to list all drivers
    30  func ListDrivers(client *gophercloud.ServiceClient, opts ListDriversOptsBuilder) pagination.Pager {
    31  	url := driversURL(client)
    32  	if opts != nil {
    33  		query, err := opts.ToListDriversOptsQuery()
    34  		if err != nil {
    35  			return pagination.Pager{Err: err}
    36  		}
    37  		url += query
    38  	}
    39  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    40  		return DriverPage{pagination.LinkedPageBase{PageResult: r}}
    41  	})
    42  }
    43  
    44  // GetDriverDetails Shows details for a driver
    45  func GetDriverDetails(client *gophercloud.ServiceClient, driverName string) (r GetDriverResult) {
    46  	resp, err := client.Get(driverDetailsURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
    47  		OkCodes: []int{200},
    48  	})
    49  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    50  	return
    51  }
    52  
    53  // GetDriverProperties Shows the required and optional parameters that
    54  // driverName expects to be supplied in the driver_info field for every
    55  // Node it manages
    56  func GetDriverProperties(client *gophercloud.ServiceClient, driverName string) (r GetPropertiesResult) {
    57  	resp, err := client.Get(driverPropertiesURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
    58  		OkCodes: []int{200},
    59  	})
    60  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    61  	return
    62  }
    63  
    64  // GetDriverDiskProperties Show the required and optional parameters that
    65  // driverName expects to be supplied in the node’s raid_config field, if a
    66  // RAID configuration change is requested.
    67  func GetDriverDiskProperties(client *gophercloud.ServiceClient, driverName string) (r GetDiskPropertiesResult) {
    68  	resp, err := client.Get(driverDiskPropertiesURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
    69  		OkCodes: []int{200},
    70  	})
    71  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    72  	return
    73  }