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