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 | |
| 8 | // Event represents a stack event. |
| 9 | type Event struct { |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 10 | // The name of the resource for which the event occurred. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 11 | ResourceName string `json:"resource_name"` |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 12 | // The time the event occurred. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 13 | Time gophercloud.JSONRFC3339NoZ `json:"event_time"` |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 14 | // The URLs to the event. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 15 | Links []gophercloud.Link `json:"links"` |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 16 | // The logical ID of the stack resource. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 17 | LogicalResourceID string `json:"logical_resource_id"` |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 18 | // The reason of the status of the event. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 19 | ResourceStatusReason string `json:"resource_status_reason"` |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 20 | // The status of the event. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 21 | ResourceStatus string `json:"resource_status"` |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 22 | // The physical ID of the stack resource. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 23 | PhysicalResourceID string `json:"physical_resource_id"` |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 24 | // The event ID. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 25 | ID string `json:"id"` |
Jon Perritt | 9dce415 | 2015-02-11 13:05:54 -0700 | [diff] [blame] | 26 | // Properties of the stack resource. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 27 | ResourceProperties map[string]interface{} `json:"resource_properties"` |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | // FindResult represents the result of a Find operation. |
| 31 | type FindResult struct { |
| 32 | gophercloud.Result |
| 33 | } |
| 34 | |
| 35 | // Extract returns a slice of Event objects and is called after a |
| 36 | // Find operation. |
| 37 | func (r FindResult) Extract() ([]Event, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 38 | var s struct { |
| 39 | Events []Event `json:"events"` |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 40 | } |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 41 | err := r.ExtractInto(&s) |
| 42 | return s.Events, err |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // EventPage abstracts the raw results of making a List() request against the API. |
| 46 | // As OpenStack extensions may freely alter the response bodies of structures returned to the client, you may only safely access the |
| 47 | // data provided through the ExtractResources call. |
| 48 | type EventPage struct { |
| 49 | pagination.MarkerPageBase |
| 50 | } |
| 51 | |
| 52 | // IsEmpty returns true if a page contains no Server results. |
| 53 | func (r EventPage) IsEmpty() (bool, error) { |
| 54 | events, err := ExtractEvents(r) |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 55 | return len(events) == 0, err |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | // LastMarker returns the last stack ID in a ListResult. |
| 59 | func (r EventPage) LastMarker() (string, error) { |
| 60 | events, err := ExtractEvents(r) |
| 61 | if err != nil { |
| 62 | return "", err |
| 63 | } |
| 64 | if len(events) == 0 { |
| 65 | return "", nil |
| 66 | } |
| 67 | return events[len(events)-1].ID, nil |
| 68 | } |
| 69 | |
| 70 | // ExtractEvents interprets the results of a single page from a List() call, producing a slice of Event entities. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 71 | func ExtractEvents(r pagination.Page) ([]Event, error) { |
| 72 | var s struct { |
| 73 | Events []Event `json:"events"` |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 74 | } |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 75 | err := (r.(EventPage)).ExtractInto(&s) |
| 76 | return s.Events, err |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Jon Perritt | 64c053f | 2015-02-09 15:42:18 -0700 | [diff] [blame] | 79 | // ExtractResourceEvents interprets the results of a single page from a |
| 80 | // ListResourceEvents() call, producing a slice of Event entities. |
| 81 | func ExtractResourceEvents(page pagination.Page) ([]Event, error) { |
| 82 | return ExtractEvents(page) |
| 83 | } |
| 84 | |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 85 | // GetResult represents the result of a Get operation. |
| 86 | type GetResult struct { |
| 87 | gophercloud.Result |
| 88 | } |
| 89 | |
| 90 | // Extract returns a pointer to an Event object and is called after a |
| 91 | // Get operation. |
| 92 | func (r GetResult) Extract() (*Event, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 93 | var s struct { |
| 94 | Event *Event `json:"event"` |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 95 | } |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 96 | err := r.ExtractInto(&s) |
| 97 | return s.Event, err |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 98 | } |