Skip to content

Commit 6cdce06

Browse files
committed
Compute v2: Add Pagination Support to Usage
This commit adds pagination support to the compute v2 usage extension.
1 parent 4f96abf commit 6cdce06

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

openstack/compute/v2/extensions/usage/requests.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ type SingleTenantOpts struct {
1515

1616
// The beginning time to calculate usage statistics on compute and storage resources.
1717
Start *time.Time `q:"start"`
18+
19+
// Limit limits the amount of results returned by the API.
20+
// This requires the client to be set to microversion 2.40 or later.
21+
Limit int `q:"limit"`
22+
23+
// Marker instructs the API call where to start listing from.
24+
// This requires the client to be set to microversion 2.40 or later.
25+
Marker string `q:"marker"`
1826
}
1927

2028
// SingleTenantOptsBuilder allows extensions to add additional parameters to the
@@ -25,7 +33,13 @@ type SingleTenantOptsBuilder interface {
2533

2634
// ToUsageSingleTenantQuery formats a SingleTenantOpts into a query string.
2735
func (opts SingleTenantOpts) ToUsageSingleTenantQuery() (string, error) {
28-
params := make(url.Values)
36+
q, err := gophercloud.BuildQueryString(opts)
37+
if err != nil {
38+
return "", err
39+
}
40+
41+
params := q.Query()
42+
2943
if opts.Start != nil {
3044
params.Add("start", opts.Start.Format(gophercloud.RFC3339MilliNoZ))
3145
}
@@ -34,7 +48,7 @@ func (opts SingleTenantOpts) ToUsageSingleTenantQuery() (string, error) {
3448
params.Add("end", opts.End.Format(gophercloud.RFC3339MilliNoZ))
3549
}
3650

37-
q := &url.URL{RawQuery: params.Encode()}
51+
q = &url.URL{RawQuery: params.Encode()}
3852
return q.String(), nil
3953
}
4054

@@ -63,6 +77,14 @@ type AllTenantsOpts struct {
6377

6478
// The beginning time to calculate usage statistics on compute and storage resources.
6579
Start *time.Time `q:"start"`
80+
81+
// Limit limits the amount of results returned by the API.
82+
// This requires the client to be set to microversion 2.40 or later.
83+
Limit int `q:"limit"`
84+
85+
// Marker instructs the API call where to start listing from.
86+
// This requires the client to be set to microversion 2.40 or later.
87+
Marker string `q:"marker"`
6688
}
6789

6890
// AllTenantsOptsBuilder allows extensions to add additional parameters to the
@@ -73,7 +95,13 @@ type AllTenantsOptsBuilder interface {
7395

7496
// ToUsageAllTenantsQuery formats a AllTenantsOpts into a query string.
7597
func (opts AllTenantsOpts) ToUsageAllTenantsQuery() (string, error) {
76-
params := make(url.Values)
98+
q, err := gophercloud.BuildQueryString(opts)
99+
if err != nil {
100+
return "", err
101+
}
102+
103+
params := q.Query()
104+
77105
if opts.Start != nil {
78106
params.Add("start", opts.Start.Format(gophercloud.RFC3339MilliNoZ))
79107
}
@@ -86,7 +114,7 @@ func (opts AllTenantsOpts) ToUsageAllTenantsQuery() (string, error) {
86114
params.Add("detailed", "1")
87115
}
88116

89-
q := &url.URL{RawQuery: params.Encode()}
117+
q = &url.URL{RawQuery: params.Encode()}
90118
return q.String(), nil
91119
}
92120

0 commit comments

Comments
 (0)