github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/services/requests.go (about)

     1  package services
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // ListOptsBuilder allows extensions to add additional parameters to the List
     9  // request.
    10  type ListOptsBuilder interface {
    11  	ToServiceListQuery() (string, error)
    12  }
    13  
    14  // ListOpts holds options for listing Services.
    15  type ListOpts struct {
    16  	// The pool name for the back end.
    17  	ProjectID string `json:"project_id,omitempty"`
    18  	// The service host name.
    19  	Host string `json:"host"`
    20  	// The service binary name. Default is the base name of the executable.
    21  	Binary string `json:"binary"`
    22  	// The availability zone.
    23  	Zone string `json:"zone"`
    24  	// The current state of the service. A valid value is up or down.
    25  	State string `json:"state"`
    26  	// The service status, which is enabled or disabled.
    27  	Status string `json:"status"`
    28  }
    29  
    30  // ToServiceListQuery formats a ListOpts into a query string.
    31  func (opts ListOpts) ToServiceListQuery() (string, error) {
    32  	q, err := gophercloud.BuildQueryString(opts)
    33  	return q.String(), err
    34  }
    35  
    36  // List makes a request against the API to list services.
    37  func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    38  	url := listURL(client)
    39  	if opts != nil {
    40  		query, err := opts.ToServiceListQuery()
    41  		if err != nil {
    42  			return pagination.Pager{Err: err}
    43  		}
    44  		url += query
    45  	}
    46  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    47  		return ServicePage{pagination.SinglePageBase(r)}
    48  	})
    49  }