github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/baremetal/v1/drivers/requests.go (about)

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