Skip to content

Commit 3b18b37

Browse files
authored
Merge pull request #12 from ts170710/add_quota_list
Add loadbalance quota list
2 parents 444b43f + b5b8e92 commit 3b18b37

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

openstack/loadbalancer/v2/quotas/requests.go

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package quotas
22

33
import (
44
"github.com/gophercloud/gophercloud"
5+
"github.com/gophercloud/gophercloud/pagination"
56
)
67

78
// Get returns load balancer Quotas for a project.
@@ -11,6 +12,14 @@ func Get(client *gophercloud.ServiceClient, projectID string) (r GetResult) {
1112
return
1213
}
1314

15+
// List returns load balancer Quotas.
16+
func List(client *gophercloud.ServiceClient) pagination.Pager {
17+
url := getURL(client, "")
18+
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
19+
return QuotaPage{pagination.LinkedPageBase{PageResult: r}}
20+
})
21+
}
22+
1423
// UpdateOptsBuilder allows extensions to add additional parameters to the
1524
// Update request.
1625
type UpdateOptsBuilder interface {

openstack/loadbalancer/v2/quotas/results.go

+34
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55

66
"github.com/gophercloud/gophercloud"
7+
"github.com/gophercloud/gophercloud/pagination"
78
)
89

910
type commonResult struct {
@@ -19,6 +20,39 @@ func (r commonResult) Extract() (*Quota, error) {
1920
return s.Quota, err
2021
}
2122

23+
type QuotaPage struct {
24+
pagination.LinkedPageBase
25+
}
26+
27+
func (r QuotaPage) NextPageURL() (string, error) {
28+
var s struct {
29+
Links []gophercloud.Link `json:"quota_links"`
30+
}
31+
err := r.ExtractInto(&s)
32+
if err != nil {
33+
return "", err
34+
}
35+
return gophercloud.ExtractNextURL(s.Links)
36+
}
37+
38+
// IsEmpty checks whether a QuotaPage struct is empty.
39+
func (r QuotaPage) IsEmpty() (bool, error) {
40+
if r.StatusCode == 204 {
41+
return true, nil
42+
}
43+
44+
is, err := ExtractQuotas(r)
45+
return len(is) == 0, err
46+
}
47+
48+
func ExtractQuotas(r pagination.Page) ([]Quota, error) {
49+
var s struct {
50+
Quotas []Quota `json:"quotas"`
51+
}
52+
err := (r.(QuotaPage)).ExtractInto(&s)
53+
return s.Quotas, err
54+
}
55+
2256
// GetResult represents the result of a get operation. Call its Extract
2357
// method to interpret it as a Quota.
2458
type GetResult struct {

0 commit comments

Comments
 (0)