-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadbalancers.go
59 lines (49 loc) · 1.33 KB
/
loadbalancers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"time"
"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/loadbalancers"
"github.com/gophercloud/gophercloud/v2/pagination"
)
type LoadBalancer struct {
resource *loadbalancers.LoadBalancer
client *gophercloud.ServiceClient
}
func (s LoadBalancer) CreatedAt() time.Time {
return s.resource.CreatedAt
}
func (s LoadBalancer) Delete(ctx context.Context) error {
return loadbalancers.Delete(ctx, s.client, s.resource.ID, loadbalancers.DeleteOpts{Cascade: true}).ExtractErr()
}
func (s LoadBalancer) Type() string {
return "load balancer"
}
func (s LoadBalancer) ID() string {
return s.resource.ID
}
func (s LoadBalancer) Name() string {
return s.resource.Name
}
func (s LoadBalancer) Tags() []string {
return s.resource.Tags
}
func ListLoadBalancers(ctx context.Context, client *gophercloud.ServiceClient) <-chan Resource {
ch := make(chan Resource)
go func() {
defer close(ch)
if err := loadbalancers.List(client, nil).EachPage(ctx, func(_ context.Context, page pagination.Page) (bool, error) {
resources, err := loadbalancers.ExtractLoadBalancers(page)
for i := range resources {
ch <- LoadBalancer{
resource: &resources[i],
client: client,
}
}
return true, err
}); err != nil {
panic(err)
}
}()
return ch
}