blob: 794d4c8e550b7bdd6064f7dc233a075264bcefdf [file] [log] [blame]
Jon Perritt7cbb42c2015-02-08 21:13:08 -07001package stackevents
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Jon Perritt7cbb42c2015-02-08 21:13:08 -07006)
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 {
Jon Perrittfea90732016-03-15 02:57:05 -050010 var r FindResult
11 _, r.Err = c.Get(findURL(c, stackName), &r.Body, nil)
12 return r
Jon Perritt7cbb42c2015-02-08 21:13:08 -070013}
14
15// SortDir is a type for specifying in which direction to sort a list of events.
16type SortDir string
17
18// SortKey is a type for specifying by which key to sort a list of events.
19type SortKey string
20
21// ResourceStatus is a type for specifying by which resource status to filter a
22// list of events.
23type ResourceStatus string
24
25// ResourceAction is a type for specifying by which resource action to filter a
26// list of events.
27type ResourceAction string
28
29var (
Jon Perritt12c04a42015-02-12 11:45:10 -070030 // ResourceStatusInProgress is used to filter a List request by the 'IN_PROGRESS' status.
31 ResourceStatusInProgress ResourceStatus = "IN_PROGRESS"
32 // ResourceStatusComplete is used to filter a List request by the 'COMPLETE' status.
33 ResourceStatusComplete ResourceStatus = "COMPLETE"
34 // ResourceStatusFailed is used to filter a List request by the 'FAILED' status.
35 ResourceStatusFailed ResourceStatus = "FAILED"
36
37 // ResourceActionCreate is used to filter a List request by the 'CREATE' action.
38 ResourceActionCreate ResourceAction = "CREATE"
39 // ResourceActionDelete is used to filter a List request by the 'DELETE' action.
40 ResourceActionDelete ResourceAction = "DELETE"
41 // ResourceActionUpdate is used to filter a List request by the 'UPDATE' action.
42 ResourceActionUpdate ResourceAction = "UPDATE"
43 // ResourceActionRollback is used to filter a List request by the 'ROLLBACK' action.
44 ResourceActionRollback ResourceAction = "ROLLBACK"
45 // ResourceActionSuspend is used to filter a List request by the 'SUSPEND' action.
46 ResourceActionSuspend ResourceAction = "SUSPEND"
47 // ResourceActionResume is used to filter a List request by the 'RESUME' action.
48 ResourceActionResume ResourceAction = "RESUME"
49 // ResourceActionAbandon is used to filter a List request by the 'ABANDON' action.
50 ResourceActionAbandon ResourceAction = "ABANDON"
51
Jon Perritt7cbb42c2015-02-08 21:13:08 -070052 // SortAsc is used to sort a list of stacks in ascending order.
53 SortAsc SortDir = "asc"
54 // SortDesc is used to sort a list of stacks in descending order.
55 SortDesc SortDir = "desc"
56
57 // SortName is used to sort a list of stacks by name.
58 SortName SortKey = "name"
59 // SortResourceType is used to sort a list of stacks by resource type.
60 SortResourceType SortKey = "resource_type"
61 // SortCreatedAt is used to sort a list of stacks by date created.
62 SortCreatedAt SortKey = "created_at"
63)
64
65// ListOptsBuilder allows extensions to add additional parameters to the
66// List request.
67type ListOptsBuilder interface {
68 ToStackEventListQuery() (string, error)
69}
70
71// ListOpts allows the filtering and sorting of paginated collections through
72// the API. Marker and Limit are used for pagination.
73type ListOpts struct {
74 // The stack resource ID with which to start the listing.
75 Marker string `q:"marker"`
76 // Integer value for the limit of values to return.
77 Limit int `q:"limit"`
78 // Filters the event list by the specified ResourceAction. You can use this
79 // filter multiple times to filter by multiple resource actions: CREATE, DELETE,
80 // UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
Jon Perritt12c04a42015-02-12 11:45:10 -070081 ResourceActions []ResourceAction `q:"resource_action"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070082 // Filters the event list by the specified resource_status. You can use this
83 // filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
84 // COMPLETE or FAILED.
Jon Perritt12c04a42015-02-12 11:45:10 -070085 ResourceStatuses []ResourceStatus `q:"resource_status"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070086 // Filters the event list by the specified resource_name. You can use this
87 // filter multiple times to filter by multiple resource names.
88 ResourceNames []string `q:"resource_name"`
89 // Filters the event list by the specified resource_type. You can use this
90 // filter multiple times to filter by multiple resource types: OS::Nova::Server,
91 // OS::Cinder::Volume, and so on.
92 ResourceTypes []string `q:"resource_type"`
93 // Sorts the event list by: resource_type or created_at.
94 SortKey SortKey `q:"sort_keys"`
95 // The sort direction of the event list. Which is asc (ascending) or desc (descending).
96 SortDir SortDir `q:"sort_dir"`
97}
98
99// ToStackEventListQuery formats a ListOpts into a query string.
100func (opts ListOpts) ToStackEventListQuery() (string, error) {
101 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittfea90732016-03-15 02:57:05 -0500102 return q.String(), err
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700103}
104
105// List makes a request against the API to list resources for the given stack.
106func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
107 url := listURL(client, stackName, stackID)
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700108 if opts != nil {
109 query, err := opts.ToStackEventListQuery()
110 if err != nil {
111 return pagination.Pager{Err: err}
112 }
113 url += query
114 }
Jon Perrittfea90732016-03-15 02:57:05 -0500115 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700116 p := EventPage{pagination.MarkerPageBase{PageResult: r}}
117 p.MarkerPageBase.Owner = p
118 return p
Jon Perrittfea90732016-03-15 02:57:05 -0500119 })
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700120}
121
122// ListResourceEventsOptsBuilder allows extensions to add additional parameters to the
123// ListResourceEvents request.
124type ListResourceEventsOptsBuilder interface {
125 ToResourceEventListQuery() (string, error)
126}
127
128// ListResourceEventsOpts allows the filtering and sorting of paginated resource events through
129// the API. Marker and Limit are used for pagination.
130type ListResourceEventsOpts struct {
131 // The stack resource ID with which to start the listing.
132 Marker string `q:"marker"`
133 // Integer value for the limit of values to return.
134 Limit int `q:"limit"`
135 // Filters the event list by the specified ResourceAction. You can use this
136 // filter multiple times to filter by multiple resource actions: CREATE, DELETE,
137 // UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
138 ResourceActions []string `q:"resource_action"`
139 // Filters the event list by the specified resource_status. You can use this
140 // filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
141 // COMPLETE or FAILED.
142 ResourceStatuses []string `q:"resource_status"`
143 // Filters the event list by the specified resource_name. You can use this
144 // filter multiple times to filter by multiple resource names.
145 ResourceNames []string `q:"resource_name"`
146 // Filters the event list by the specified resource_type. You can use this
147 // filter multiple times to filter by multiple resource types: OS::Nova::Server,
148 // OS::Cinder::Volume, and so on.
149 ResourceTypes []string `q:"resource_type"`
150 // Sorts the event list by: resource_type or created_at.
151 SortKey SortKey `q:"sort_keys"`
152 // The sort direction of the event list. Which is asc (ascending) or desc (descending).
153 SortDir SortDir `q:"sort_dir"`
154}
155
Pratik Mallya7e6b7b92015-09-30 19:03:08 -0500156// ToResourceEventListQuery formats a ListResourceEventsOpts into a query string.
157func (opts ListResourceEventsOpts) ToResourceEventListQuery() (string, error) {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700158 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittfea90732016-03-15 02:57:05 -0500159 return q.String(), err
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700160}
161
162// ListResourceEvents makes a request against the API to list resources for the given stack.
163func ListResourceEvents(client *gophercloud.ServiceClient, stackName, stackID, resourceName string, opts ListResourceEventsOptsBuilder) pagination.Pager {
164 url := listResourceEventsURL(client, stackName, stackID, resourceName)
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700165 if opts != nil {
166 query, err := opts.ToResourceEventListQuery()
167 if err != nil {
168 return pagination.Pager{Err: err}
169 }
170 url += query
171 }
Jon Perrittfea90732016-03-15 02:57:05 -0500172 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700173 p := EventPage{pagination.MarkerPageBase{PageResult: r}}
174 p.MarkerPageBase.Owner = p
175 return p
Jon Perrittfea90732016-03-15 02:57:05 -0500176 })
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700177}
178
179// Get retreives data for the given stack resource.
180func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName, eventID string) GetResult {
Jon Perrittfea90732016-03-15 02:57:05 -0500181 var r GetResult
182 _, r.Err = c.Get(getURL(c, stackName, stackID, resourceName, eventID), &r.Body, &gophercloud.RequestOpts{
Jamie Hannaford1d27afa2015-03-24 16:20:45 +0100183 OkCodes: []int{200},
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700184 })
Jon Perrittfea90732016-03-15 02:57:05 -0500185 return r
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700186}