blob: 37eab1e763e8f354a726d72e1581e76befd6f0cf [file] [log] [blame]
Jon Perritt7cbb42c2015-02-08 21:13:08 -07001package stackevents
2
3import (
Jon Perritt7cbb42c2015-02-08 21:13:08 -07004 "github.com/rackspace/gophercloud"
5 "github.com/rackspace/gophercloud/pagination"
6)
7
Jon Perritta37ecf42015-02-11 12:51:40 -07008// Find retrieves stack events for the given stack name.
Jon Perritt7cbb42c2015-02-08 21:13:08 -07009func Find(c *gophercloud.ServiceClient, stackName string) FindResult {
10 var res FindResult
11
Ash Wilsondecfed72015-02-13 09:14:55 -050012 _, res.Err = c.Request("GET", findURL(c, stackName), gophercloud.RequestOpts{
13 JSONResponse: &res.Body,
14 OkCodes: []int{200},
Jon Perritt7cbb42c2015-02-08 21:13:08 -070015 })
16 return res
17}
18
19// SortDir is a type for specifying in which direction to sort a list of events.
20type SortDir string
21
22// SortKey is a type for specifying by which key to sort a list of events.
23type SortKey string
24
25// ResourceStatus is a type for specifying by which resource status to filter a
26// list of events.
27type ResourceStatus string
28
29// ResourceAction is a type for specifying by which resource action to filter a
30// list of events.
31type ResourceAction string
32
33var (
Jon Perritt12c04a42015-02-12 11:45:10 -070034 // ResourceStatusInProgress is used to filter a List request by the 'IN_PROGRESS' status.
35 ResourceStatusInProgress ResourceStatus = "IN_PROGRESS"
36 // ResourceStatusComplete is used to filter a List request by the 'COMPLETE' status.
37 ResourceStatusComplete ResourceStatus = "COMPLETE"
38 // ResourceStatusFailed is used to filter a List request by the 'FAILED' status.
39 ResourceStatusFailed ResourceStatus = "FAILED"
40
41 // ResourceActionCreate is used to filter a List request by the 'CREATE' action.
42 ResourceActionCreate ResourceAction = "CREATE"
43 // ResourceActionDelete is used to filter a List request by the 'DELETE' action.
44 ResourceActionDelete ResourceAction = "DELETE"
45 // ResourceActionUpdate is used to filter a List request by the 'UPDATE' action.
46 ResourceActionUpdate ResourceAction = "UPDATE"
47 // ResourceActionRollback is used to filter a List request by the 'ROLLBACK' action.
48 ResourceActionRollback ResourceAction = "ROLLBACK"
49 // ResourceActionSuspend is used to filter a List request by the 'SUSPEND' action.
50 ResourceActionSuspend ResourceAction = "SUSPEND"
51 // ResourceActionResume is used to filter a List request by the 'RESUME' action.
52 ResourceActionResume ResourceAction = "RESUME"
53 // ResourceActionAbandon is used to filter a List request by the 'ABANDON' action.
54 ResourceActionAbandon ResourceAction = "ABANDON"
55
Jon Perritt7cbb42c2015-02-08 21:13:08 -070056 // SortAsc is used to sort a list of stacks in ascending order.
57 SortAsc SortDir = "asc"
58 // SortDesc is used to sort a list of stacks in descending order.
59 SortDesc SortDir = "desc"
60
61 // SortName is used to sort a list of stacks by name.
62 SortName SortKey = "name"
63 // SortResourceType is used to sort a list of stacks by resource type.
64 SortResourceType SortKey = "resource_type"
65 // SortCreatedAt is used to sort a list of stacks by date created.
66 SortCreatedAt SortKey = "created_at"
67)
68
69// ListOptsBuilder allows extensions to add additional parameters to the
70// List request.
71type ListOptsBuilder interface {
72 ToStackEventListQuery() (string, error)
73}
74
75// ListOpts allows the filtering and sorting of paginated collections through
76// the API. Marker and Limit are used for pagination.
77type ListOpts struct {
78 // The stack resource ID with which to start the listing.
79 Marker string `q:"marker"`
80 // Integer value for the limit of values to return.
81 Limit int `q:"limit"`
82 // Filters the event list by the specified ResourceAction. You can use this
83 // filter multiple times to filter by multiple resource actions: CREATE, DELETE,
84 // UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
Jon Perritt12c04a42015-02-12 11:45:10 -070085 ResourceActions []ResourceAction `q:"resource_action"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070086 // Filters the event list by the specified resource_status. You can use this
87 // filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
88 // COMPLETE or FAILED.
Jon Perritt12c04a42015-02-12 11:45:10 -070089 ResourceStatuses []ResourceStatus `q:"resource_status"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070090 // Filters the event list by the specified resource_name. You can use this
91 // filter multiple times to filter by multiple resource names.
92 ResourceNames []string `q:"resource_name"`
93 // Filters the event list by the specified resource_type. You can use this
94 // filter multiple times to filter by multiple resource types: OS::Nova::Server,
95 // OS::Cinder::Volume, and so on.
96 ResourceTypes []string `q:"resource_type"`
97 // Sorts the event list by: resource_type or created_at.
98 SortKey SortKey `q:"sort_keys"`
99 // The sort direction of the event list. Which is asc (ascending) or desc (descending).
100 SortDir SortDir `q:"sort_dir"`
101}
102
103// ToStackEventListQuery formats a ListOpts into a query string.
104func (opts ListOpts) ToStackEventListQuery() (string, error) {
105 q, err := gophercloud.BuildQueryString(opts)
106 if err != nil {
107 return "", err
108 }
109 return q.String(), nil
110}
111
112// List makes a request against the API to list resources for the given stack.
113func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
114 url := listURL(client, stackName, stackID)
115
116 if opts != nil {
117 query, err := opts.ToStackEventListQuery()
118 if err != nil {
119 return pagination.Pager{Err: err}
120 }
121 url += query
122 }
123
124 createPageFn := func(r pagination.PageResult) pagination.Page {
125 p := EventPage{pagination.MarkerPageBase{PageResult: r}}
126 p.MarkerPageBase.Owner = p
127 return p
128 }
129
130 return pagination.NewPager(client, url, createPageFn)
131}
132
133// ListResourceEventsOptsBuilder allows extensions to add additional parameters to the
134// ListResourceEvents request.
135type ListResourceEventsOptsBuilder interface {
136 ToResourceEventListQuery() (string, error)
137}
138
139// ListResourceEventsOpts allows the filtering and sorting of paginated resource events through
140// the API. Marker and Limit are used for pagination.
141type ListResourceEventsOpts struct {
142 // The stack resource ID with which to start the listing.
143 Marker string `q:"marker"`
144 // Integer value for the limit of values to return.
145 Limit int `q:"limit"`
146 // Filters the event list by the specified ResourceAction. You can use this
147 // filter multiple times to filter by multiple resource actions: CREATE, DELETE,
148 // UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
149 ResourceActions []string `q:"resource_action"`
150 // Filters the event list by the specified resource_status. You can use this
151 // filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
152 // COMPLETE or FAILED.
153 ResourceStatuses []string `q:"resource_status"`
154 // Filters the event list by the specified resource_name. You can use this
155 // filter multiple times to filter by multiple resource names.
156 ResourceNames []string `q:"resource_name"`
157 // Filters the event list by the specified resource_type. You can use this
158 // filter multiple times to filter by multiple resource types: OS::Nova::Server,
159 // OS::Cinder::Volume, and so on.
160 ResourceTypes []string `q:"resource_type"`
161 // Sorts the event list by: resource_type or created_at.
162 SortKey SortKey `q:"sort_keys"`
163 // The sort direction of the event list. Which is asc (ascending) or desc (descending).
164 SortDir SortDir `q:"sort_dir"`
165}
166
167// ToResourceEventsListQuery formats a ListOpts into a query string.
168func (opts ListOpts) ToResourceEventsListQuery() (string, error) {
169 q, err := gophercloud.BuildQueryString(opts)
170 if err != nil {
171 return "", err
172 }
173 return q.String(), nil
174}
175
176// ListResourceEvents makes a request against the API to list resources for the given stack.
177func ListResourceEvents(client *gophercloud.ServiceClient, stackName, stackID, resourceName string, opts ListResourceEventsOptsBuilder) pagination.Pager {
178 url := listResourceEventsURL(client, stackName, stackID, resourceName)
179
180 if opts != nil {
181 query, err := opts.ToResourceEventListQuery()
182 if err != nil {
183 return pagination.Pager{Err: err}
184 }
185 url += query
186 }
187
188 createPageFn := func(r pagination.PageResult) pagination.Page {
189 p := EventPage{pagination.MarkerPageBase{PageResult: r}}
190 p.MarkerPageBase.Owner = p
191 return p
192 }
193
194 return pagination.NewPager(client, url, createPageFn)
195}
196
197// Get retreives data for the given stack resource.
198func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName, eventID string) GetResult {
199 var res GetResult
Ash Wilsondecfed72015-02-13 09:14:55 -0500200 _, res.Err = c.Request("GET", getURL(c, stackName, stackID, resourceName, eventID), gophercloud.RequestOpts{
201 JSONResponse: &res.Body,
202 OkCodes: []int{200},
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700203 })
204 return res
205}