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