github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/amphorae/requests.go (about)

     1  package amphorae
     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
     9  // List request.
    10  type ListOptsBuilder interface {
    11  	ToAmphoraListQuery() (string, error)
    12  }
    13  
    14  // ListOpts allows the filtering and sorting of paginated collections through
    15  // the API. Filtering is achieved by passing in struct field values that map to
    16  // the Amphorae attributes you want to see returned. SortKey allows you to
    17  // sort by a particular attribute. SortDir sets the direction, and is
    18  // either `asc' or `desc'. Marker and Limit are used for pagination.
    19  type ListOpts struct {
    20  	LoadbalancerID string `q:"loadbalancer_id"`
    21  	ImageID        string `q:"image_id"`
    22  	Role           string `q:"role"`
    23  	Status         string `q:"status"`
    24  	HAPortID       string `q:"ha_port_id"`
    25  	VRRPPortID     string `q:"vrrp_port_id"`
    26  	Limit          int    `q:"limit"`
    27  	Marker         string `q:"marker"`
    28  	SortKey        string `q:"sort_key"`
    29  	SortDir        string `q:"sort_dir"`
    30  }
    31  
    32  // ToAmphoraListQuery formats a ListOpts into a query string.
    33  func (opts ListOpts) ToAmphoraListQuery() (string, error) {
    34  	q, err := gophercloud.BuildQueryString(opts)
    35  	return q.String(), err
    36  }
    37  
    38  // List returns a Pager which allows you to iterate over a collection of
    39  // amphorae. It accepts a ListOpts struct, which allows you to filter
    40  // and sort the returned collection for greater efficiency.
    41  func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    42  	url := rootURL(c)
    43  	if opts != nil {
    44  		query, err := opts.ToAmphoraListQuery()
    45  		if err != nil {
    46  			return pagination.Pager{Err: err}
    47  		}
    48  		url += query
    49  	}
    50  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    51  		return AmphoraPage{pagination.LinkedPageBase{PageResult: r}}
    52  	})
    53  }
    54  
    55  // Get retrieves a particular amphora based on its unique ID.
    56  func Get(c *gophercloud.ServiceClient, id string) (r GetResult) {
    57  	resp, err := c.Get(resourceURL(c, id), &r.Body, nil)
    58  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    59  	return
    60  }
    61  
    62  // Failover performs a failover of an amphora.
    63  func Failover(c *gophercloud.ServiceClient, id string) (r FailoverResult) {
    64  	resp, err := c.Put(failoverRootURL(c, id), nil, nil, &gophercloud.RequestOpts{
    65  		OkCodes: []int{202},
    66  	})
    67  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    68  	return
    69  }