blob: 6c7f1835b4dab190e508b1e070607f21817a071d [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
8// Event represents a stack event.
9type Event struct {
Jon Perritt9dce4152015-02-11 13:05:54 -070010 // The name of the resource for which the event occurred.
Jon Perritt3c166472016-02-25 03:07:41 -060011 ResourceName string `json:"resource_name"`
Jon Perritt9dce4152015-02-11 13:05:54 -070012 // The time the event occurred.
Jon Perritt3c166472016-02-25 03:07:41 -060013 Time gophercloud.JSONRFC3339NoZ `json:"event_time"`
Jon Perritt9dce4152015-02-11 13:05:54 -070014 // The URLs to the event.
Jon Perritt3c166472016-02-25 03:07:41 -060015 Links []gophercloud.Link `json:"links"`
Jon Perritt9dce4152015-02-11 13:05:54 -070016 // The logical ID of the stack resource.
Jon Perritt3c166472016-02-25 03:07:41 -060017 LogicalResourceID string `json:"logical_resource_id"`
Jon Perritt9dce4152015-02-11 13:05:54 -070018 // The reason of the status of the event.
Jon Perritt3c166472016-02-25 03:07:41 -060019 ResourceStatusReason string `json:"resource_status_reason"`
Jon Perritt9dce4152015-02-11 13:05:54 -070020 // The status of the event.
Jon Perritt3c166472016-02-25 03:07:41 -060021 ResourceStatus string `json:"resource_status"`
Jon Perritt9dce4152015-02-11 13:05:54 -070022 // The physical ID of the stack resource.
Jon Perritt3c166472016-02-25 03:07:41 -060023 PhysicalResourceID string `json:"physical_resource_id"`
Jon Perritt9dce4152015-02-11 13:05:54 -070024 // The event ID.
Jon Perritt3c166472016-02-25 03:07:41 -060025 ID string `json:"id"`
Jon Perritt9dce4152015-02-11 13:05:54 -070026 // Properties of the stack resource.
Jon Perritt3c166472016-02-25 03:07:41 -060027 ResourceProperties map[string]interface{} `json:"resource_properties"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070028}
29
30// FindResult represents the result of a Find operation.
31type FindResult struct {
32 gophercloud.Result
33}
34
35// Extract returns a slice of Event objects and is called after a
36// Find operation.
37func (r FindResult) Extract() ([]Event, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060038 var s struct {
39 Events []Event `json:"events"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070040 }
Jon Perritt3c166472016-02-25 03:07:41 -060041 err := r.ExtractInto(&s)
42 return s.Events, err
Jon Perritt7cbb42c2015-02-08 21:13:08 -070043}
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.
48type EventPage struct {
49 pagination.MarkerPageBase
50}
51
52// IsEmpty returns true if a page contains no Server results.
53func (r EventPage) IsEmpty() (bool, error) {
54 events, err := ExtractEvents(r)
Jon Perritt3c166472016-02-25 03:07:41 -060055 return len(events) == 0, err
Jon Perritt7cbb42c2015-02-08 21:13:08 -070056}
57
58// LastMarker returns the last stack ID in a ListResult.
59func (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 Perritt3c166472016-02-25 03:07:41 -060071func ExtractEvents(r pagination.Page) ([]Event, error) {
72 var s struct {
73 Events []Event `json:"events"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070074 }
Jon Perritt3c166472016-02-25 03:07:41 -060075 err := (r.(EventPage)).ExtractInto(&s)
76 return s.Events, err
Jon Perritt7cbb42c2015-02-08 21:13:08 -070077}
78
Jon Perritt64c053f2015-02-09 15:42:18 -070079// ExtractResourceEvents interprets the results of a single page from a
80// ListResourceEvents() call, producing a slice of Event entities.
81func ExtractResourceEvents(page pagination.Page) ([]Event, error) {
82 return ExtractEvents(page)
83}
84
Jon Perritt7cbb42c2015-02-08 21:13:08 -070085// GetResult represents the result of a Get operation.
86type GetResult struct {
87 gophercloud.Result
88}
89
90// Extract returns a pointer to an Event object and is called after a
91// Get operation.
92func (r GetResult) Extract() (*Event, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060093 var s struct {
94 Event *Event `json:"event"`
Jon Perritt7cbb42c2015-02-08 21:13:08 -070095 }
Jon Perritt3c166472016-02-25 03:07:41 -060096 err := r.ExtractInto(&s)
97 return s.Event, err
Jon Perritt7cbb42c2015-02-08 21:13:08 -070098}