github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/compute/v2/instanceactions/request.go (about) 1 package instanceactions 2 3 import ( 4 "context" 5 "net/url" 6 "time" 7 8 "github.com/vnpaycloud-console/gophercloud/v2" 9 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 10 ) 11 12 // ListOptsBuilder allows extensions to add additional parameters to the 13 // List request. 14 type ListOptsBuilder interface { 15 ToInstanceActionsListQuery() (string, error) 16 } 17 18 // ListOpts represents options used to filter instance action results 19 // in a List request. 20 type ListOpts struct { 21 // Limit is an integer value to limit the results to return. 22 // This requires microversion 2.58 or later. 23 Limit int `q:"limit"` 24 25 // Marker is the request ID of the last-seen instance action. 26 // This requires microversion 2.58 or later. 27 Marker string `q:"marker"` 28 29 // ChangesSince filters the response by actions after the given time. 30 // This requires microversion 2.58 or later. 31 ChangesSince *time.Time `q:"changes-since"` 32 33 // ChangesBefore filters the response by actions before the given time. 34 // This requires microversion 2.66 or later. 35 ChangesBefore *time.Time `q:"changes-before"` 36 } 37 38 // ToInstanceActionsListQuery formats a ListOpts into a query string. 39 func (opts ListOpts) ToInstanceActionsListQuery() (string, error) { 40 q, err := gophercloud.BuildQueryString(opts) 41 if err != nil { 42 return "", err 43 } 44 45 params := q.Query() 46 47 if opts.ChangesSince != nil { 48 params.Add("changes-since", opts.ChangesSince.Format(time.RFC3339)) 49 } 50 51 if opts.ChangesBefore != nil { 52 params.Add("changes-before", opts.ChangesBefore.Format(time.RFC3339)) 53 } 54 55 q = &url.URL{RawQuery: params.Encode()} 56 return q.String(), nil 57 } 58 59 // List makes a request against the API to list the servers actions. 60 func List(client *gophercloud.ServiceClient, id string, opts ListOptsBuilder) pagination.Pager { 61 url := listURL(client, id) 62 if opts != nil { 63 query, err := opts.ToInstanceActionsListQuery() 64 if err != nil { 65 return pagination.Pager{Err: err} 66 } 67 url += query 68 } 69 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 70 return InstanceActionPage{pagination.SinglePageBase(r)} 71 }) 72 } 73 74 // Get makes a request against the API to get a server action. 75 func Get(ctx context.Context, client *gophercloud.ServiceClient, serverID, requestID string) (r InstanceActionResult) { 76 resp, err := client.Get(ctx, instanceActionsURL(client, serverID, requestID), &r.Body, &gophercloud.RequestOpts{ 77 OkCodes: []int{200}, 78 }) 79 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 80 return 81 }