blob: e6e7f7914760fc2299b71253980b24319e769a08 [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 Perritt3860b512016-03-29 12:01:48 -05009func Find(c *gophercloud.ServiceClient, stackName string) (r FindResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050010 _, r.Err = c.Get(findURL(c, stackName), &r.Body, nil)
jrperritt29ae6b32016-04-13 12:59:37 -050011 return
Jon Perritt7cbb42c2015-02-08 21:13:08 -070012}
13
14// SortDir is a type for specifying in which direction to sort a list of events.
15type SortDir string
16
17// SortKey is a type for specifying by which key to sort a list of events.
18type SortKey string
19
20// ResourceStatus is a type for specifying by which resource status to filter a
21// list of events.
22type ResourceStatus string
23
24// ResourceAction is a type for specifying by which resource action to filter a
25// list of events.
26type ResourceAction string
27
28var (
Jon Perritt12c04a42015-02-12 11:45:10 -070029 // ResourceStatusInProgress is used to filter a List request by the 'IN_PROGRESS' status.
30 ResourceStatusInProgress ResourceStatus = "IN_PROGRESS"
31 // ResourceStatusComplete is used to filter a List request by the 'COMPLETE' status.
32 ResourceStatusComplete ResourceStatus = "COMPLETE"
33 // ResourceStatusFailed is used to filter a List request by the 'FAILED' status.
34 ResourceStatusFailed ResourceStatus = "FAILED"
35
36 // ResourceActionCreate is used to filter a List request by the 'CREATE' action.
37 ResourceActionCreate ResourceAction = "CREATE"
38 // ResourceActionDelete is used to filter a List request by the 'DELETE' action.
39 ResourceActionDelete ResourceAction = "DELETE"
40 // ResourceActionUpdate is used to filter a List request by the 'UPDATE' action.
41 ResourceActionUpdate ResourceAction = "UPDATE"
42 // ResourceActionRollback is used to filter a List request by the 'ROLLBACK' action.
43 ResourceActionRollback ResourceAction = "ROLLBACK"
44 // ResourceActionSuspend is used to filter a List request by the 'SUSPEND' action.
45 ResourceActionSuspend ResourceAction = "SUSPEND"
46 // ResourceActionResume is used to filter a List request by the 'RESUME' action.
47 ResourceActionResume ResourceAction = "RESUME"
48 // ResourceActionAbandon is used to filter a List request by the 'ABANDON' action.
49 ResourceActionAbandon ResourceAction = "ABANDON"
50
Jon Perritt7cbb42c2015-02-08 21:13:08 -070051 // SortAsc is used to sort a list of stacks in ascending order.
52 SortAsc SortDir = "asc"
53 // SortDesc is used to sort a list of stacks in descending order.
54 SortDesc SortDir = "desc"
55
56 // SortName is used to sort a list of stacks by name.
57 SortName SortKey = "name"
58 // SortResourceType is used to sort a list of stacks by resource type.
59 SortResourceType SortKey = "resource_type"
60 // SortCreatedAt is used to sort a list of stacks by date created.
61 SortCreatedAt SortKey = "created_at"
62)
63
64// ListOptsBuilder allows extensions to add additional parameters to the
65// List request.
66type ListOptsBuilder interface {
67 ToStackEventListQuery() (string, error)
68}
69
70// ListOpts allows the filtering and sorting of paginated collections through
71// the API. Marker and Limit are used for pagination.
72type ListOpts struct {
73 // The stack resource ID with which to start the listing.
74 Marker string `q:"marker"`
75 // Integer value for the limit of values to return.
76 Limit int `q:"limit"`
77 // Filters the event list by the specified ResourceAction. You can use this
78 // filter multiple times to filter by multiple resource actions: CREATE, DELETE,
79 // UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
Jon Perritt12c04a42015-02-12 11:45:10 -070080 ResourceActions []ResourceAction `q:"resource_action"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070081 // Filters the event list by the specified resource_status. You can use this
82 // filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
83 // COMPLETE or FAILED.
Jon Perritt12c04a42015-02-12 11:45:10 -070084 ResourceStatuses []ResourceStatus `q:"resource_status"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070085 // Filters the event list by the specified resource_name. You can use this
86 // filter multiple times to filter by multiple resource names.
87 ResourceNames []string `q:"resource_name"`
88 // Filters the event list by the specified resource_type. You can use this
89 // filter multiple times to filter by multiple resource types: OS::Nova::Server,
90 // OS::Cinder::Volume, and so on.
91 ResourceTypes []string `q:"resource_type"`
92 // Sorts the event list by: resource_type or created_at.
93 SortKey SortKey `q:"sort_keys"`
94 // The sort direction of the event list. Which is asc (ascending) or desc (descending).
95 SortDir SortDir `q:"sort_dir"`
96}
97
98// ToStackEventListQuery formats a ListOpts into a query string.
99func (opts ListOpts) ToStackEventListQuery() (string, error) {
100 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittfea90732016-03-15 02:57:05 -0500101 return q.String(), err
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700102}
103
104// List makes a request against the API to list resources for the given stack.
105func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
106 url := listURL(client, stackName, stackID)
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700107 if opts != nil {
108 query, err := opts.ToStackEventListQuery()
109 if err != nil {
110 return pagination.Pager{Err: err}
111 }
112 url += query
113 }
Jon Perrittfea90732016-03-15 02:57:05 -0500114 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700115 p := EventPage{pagination.MarkerPageBase{PageResult: r}}
116 p.MarkerPageBase.Owner = p
117 return p
Jon Perrittfea90732016-03-15 02:57:05 -0500118 })
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700119}
120
121// ListResourceEventsOptsBuilder allows extensions to add additional parameters to the
122// ListResourceEvents request.
123type ListResourceEventsOptsBuilder interface {
124 ToResourceEventListQuery() (string, error)
125}
126
127// ListResourceEventsOpts allows the filtering and sorting of paginated resource events through
128// the API. Marker and Limit are used for pagination.
129type ListResourceEventsOpts struct {
130 // The stack resource ID with which to start the listing.
131 Marker string `q:"marker"`
132 // Integer value for the limit of values to return.
133 Limit int `q:"limit"`
134 // Filters the event list by the specified ResourceAction. You can use this
135 // filter multiple times to filter by multiple resource actions: CREATE, DELETE,
136 // UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
137 ResourceActions []string `q:"resource_action"`
138 // Filters the event list by the specified resource_status. You can use this
139 // filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
140 // COMPLETE or FAILED.
141 ResourceStatuses []string `q:"resource_status"`
142 // Filters the event list by the specified resource_name. You can use this
143 // filter multiple times to filter by multiple resource names.
144 ResourceNames []string `q:"resource_name"`
145 // Filters the event list by the specified resource_type. You can use this
146 // filter multiple times to filter by multiple resource types: OS::Nova::Server,
147 // OS::Cinder::Volume, and so on.
148 ResourceTypes []string `q:"resource_type"`
149 // Sorts the event list by: resource_type or created_at.
150 SortKey SortKey `q:"sort_keys"`
151 // The sort direction of the event list. Which is asc (ascending) or desc (descending).
152 SortDir SortDir `q:"sort_dir"`
153}
154
Pratik Mallya7e6b7b92015-09-30 19:03:08 -0500155// ToResourceEventListQuery formats a ListResourceEventsOpts into a query string.
156func (opts ListResourceEventsOpts) ToResourceEventListQuery() (string, error) {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700157 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittfea90732016-03-15 02:57:05 -0500158 return q.String(), err
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700159}
160
161// ListResourceEvents makes a request against the API to list resources for the given stack.
162func ListResourceEvents(client *gophercloud.ServiceClient, stackName, stackID, resourceName string, opts ListResourceEventsOptsBuilder) pagination.Pager {
163 url := listResourceEventsURL(client, stackName, stackID, resourceName)
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700164 if opts != nil {
165 query, err := opts.ToResourceEventListQuery()
166 if err != nil {
167 return pagination.Pager{Err: err}
168 }
169 url += query
170 }
Jon Perrittfea90732016-03-15 02:57:05 -0500171 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700172 p := EventPage{pagination.MarkerPageBase{PageResult: r}}
173 p.MarkerPageBase.Owner = p
174 return p
Jon Perrittfea90732016-03-15 02:57:05 -0500175 })
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700176}
177
178// Get retreives data for the given stack resource.
Jon Perritt3860b512016-03-29 12:01:48 -0500179func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName, eventID string) (r GetResult) {
180 _, r.Err = c.Get(getURL(c, stackName, stackID, resourceName, eventID), &r.Body, nil)
jrperritt29ae6b32016-04-13 12:59:37 -0500181 return
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700182}