Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 1 | package stackevents |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 6 | ) |
| 7 | |
Jon Perritt | a37ecf4 | 2015-02-11 12:51:40 -0700 | [diff] [blame] | 8 | // Find retrieves stack events for the given stack name. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 9 | func Find(c *gophercloud.ServiceClient, stackName string) (r FindResult) { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 10 | _, r.Err = c.Get(findURL(c, stackName), &r.Body, nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 11 | return |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 12 | } |
| 13 | |
| 14 | // SortDir is a type for specifying in which direction to sort a list of events. |
| 15 | type SortDir string |
| 16 | |
| 17 | // SortKey is a type for specifying by which key to sort a list of events. |
| 18 | type SortKey string |
| 19 | |
| 20 | // ResourceStatus is a type for specifying by which resource status to filter a |
| 21 | // list of events. |
| 22 | type ResourceStatus string |
| 23 | |
| 24 | // ResourceAction is a type for specifying by which resource action to filter a |
| 25 | // list of events. |
| 26 | type ResourceAction string |
| 27 | |
| 28 | var ( |
Jon Perritt | 12c04a4 | 2015-02-12 11:45:10 -0700 | [diff] [blame] | 29 | // 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 Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 51 | // 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. |
| 66 | type 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. |
| 72 | type 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 Perritt | 12c04a4 | 2015-02-12 11:45:10 -0700 | [diff] [blame] | 80 | ResourceActions []ResourceAction `q:"resource_action"` |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 81 | // 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 Perritt | 12c04a4 | 2015-02-12 11:45:10 -0700 | [diff] [blame] | 84 | ResourceStatuses []ResourceStatus `q:"resource_status"` |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 85 | // 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. |
| 99 | func (opts ListOpts) ToStackEventListQuery() (string, error) { |
| 100 | q, err := gophercloud.BuildQueryString(opts) |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 101 | return q.String(), err |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | // List makes a request against the API to list resources for the given stack. |
| 105 | func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager { |
| 106 | url := listURL(client, stackName, stackID) |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 107 | if opts != nil { |
| 108 | query, err := opts.ToStackEventListQuery() |
| 109 | if err != nil { |
| 110 | return pagination.Pager{Err: err} |
| 111 | } |
| 112 | url += query |
| 113 | } |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 114 | return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 115 | p := EventPage{pagination.MarkerPageBase{PageResult: r}} |
| 116 | p.MarkerPageBase.Owner = p |
| 117 | return p |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 118 | }) |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // ListResourceEventsOptsBuilder allows extensions to add additional parameters to the |
| 122 | // ListResourceEvents request. |
| 123 | type 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. |
| 129 | type 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 Mallya | 7e6b7b9 | 2015-09-30 19:03:08 -0500 | [diff] [blame] | 155 | // ToResourceEventListQuery formats a ListResourceEventsOpts into a query string. |
| 156 | func (opts ListResourceEventsOpts) ToResourceEventListQuery() (string, error) { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 157 | q, err := gophercloud.BuildQueryString(opts) |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 158 | return q.String(), err |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // ListResourceEvents makes a request against the API to list resources for the given stack. |
| 162 | func ListResourceEvents(client *gophercloud.ServiceClient, stackName, stackID, resourceName string, opts ListResourceEventsOptsBuilder) pagination.Pager { |
| 163 | url := listResourceEventsURL(client, stackName, stackID, resourceName) |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 164 | if opts != nil { |
| 165 | query, err := opts.ToResourceEventListQuery() |
| 166 | if err != nil { |
| 167 | return pagination.Pager{Err: err} |
| 168 | } |
| 169 | url += query |
| 170 | } |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 171 | return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 172 | p := EventPage{pagination.MarkerPageBase{PageResult: r}} |
| 173 | p.MarkerPageBase.Owner = p |
| 174 | return p |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 175 | }) |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | // Get retreives data for the given stack resource. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 179 | func 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) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 181 | return |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 182 | } |