This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
requests.go
113 lines (100 loc) · 4.69 KB
/
requests.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package stackevents
import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)
// SortDir is a type for specifying in which direction to sort a list of events.
type SortDir string
// SortKey is a type for specifying by which key to sort a list of events.
type SortKey string
// ResourceStatus is a type for specifying by which resource status to filter a
// list of events.
type ResourceStatus string
// ResourceAction is a type for specifying by which resource action to filter a
// list of events.
type ResourceAction string
var (
// ResourceStatusInProgress is used to filter a List request by the 'IN_PROGRESS' status.
ResourceStatusInProgress ResourceStatus = "IN_PROGRESS"
// ResourceStatusComplete is used to filter a List request by the 'COMPLETE' status.
ResourceStatusComplete ResourceStatus = "COMPLETE"
// ResourceStatusFailed is used to filter a List request by the 'FAILED' status.
ResourceStatusFailed ResourceStatus = "FAILED"
// ResourceActionCreate is used to filter a List request by the 'CREATE' action.
ResourceActionCreate ResourceAction = "CREATE"
// ResourceActionDelete is used to filter a List request by the 'DELETE' action.
ResourceActionDelete ResourceAction = "DELETE"
// ResourceActionUpdate is used to filter a List request by the 'UPDATE' action.
ResourceActionUpdate ResourceAction = "UPDATE"
// ResourceActionRollback is used to filter a List request by the 'ROLLBACK' action.
ResourceActionRollback ResourceAction = "ROLLBACK"
// ResourceActionSuspend is used to filter a List request by the 'SUSPEND' action.
ResourceActionSuspend ResourceAction = "SUSPEND"
// ResourceActionResume is used to filter a List request by the 'RESUME' action.
ResourceActionResume ResourceAction = "RESUME"
// ResourceActionAbandon is used to filter a List request by the 'ABANDON' action.
ResourceActionAbandon ResourceAction = "ABANDON"
// SortAsc is used to sort a list of stacks in ascending order.
SortAsc SortDir = "asc"
// SortDesc is used to sort a list of stacks in descending order.
SortDesc SortDir = "desc"
// SortName is used to sort a list of stacks by name.
SortName SortKey = "name"
// SortResourceType is used to sort a list of stacks by resource type.
SortResourceType SortKey = "resource_type"
// SortCreatedAt is used to sort a list of stacks by date created.
SortCreatedAt SortKey = "created_at"
)
// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToStackEventListQuery() (string, error)
}
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Marker and Limit are used for pagination.
type ListOpts struct {
// The stack resource ID with which to start the listing.
Marker string `q:"marker"`
// Integer value for the limit of values to return.
Limit int `q:"limit"`
// Filters the event list by the specified ResourceAction. You can use this
// filter multiple times to filter by multiple resource actions: CREATE, DELETE,
// UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
ResourceActions []ResourceAction `q:"resource_action"`
// Filters the event list by the specified resource_status. You can use this
// filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
// COMPLETE or FAILED.
ResourceStatuses []ResourceStatus `q:"resource_status"`
// Filters the event list by the specified resource_name. You can use this
// filter multiple times to filter by multiple resource names.
ResourceNames []string `q:"resource_name"`
// Filters the event list by the specified resource_type. You can use this
// filter multiple times to filter by multiple resource types: OS::Nova::Server,
// OS::Cinder::Volume, and so on.
ResourceTypes []string `q:"resource_type"`
// Sorts the event list by: resource_type or created_at.
SortKey SortKey `q:"sort_keys"`
// The sort direction of the event list. Which is asc (ascending) or desc (descending).
SortDir SortDir `q:"sort_dir"`
}
// ToStackEventListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToStackEventListQuery() (string, error) {
q, err := golangsdk.BuildQueryString(opts)
return q.String(), err
}
// List makes a request against the API to list resources for the given stack.
func List(client *golangsdk.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
url := listURL(client, stackName, stackID)
if opts != nil {
query, err := opts.ToStackEventListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
p := EventPage{pagination.MarkerPageBase{PageResult: r}}
p.MarkerPageBase.Owner = p
return p
})
}