github.com/gophercloud/gophercloud@v1.11.0/openstack/orchestration/v1/stackevents/requests.go (about) 1 package stackevents 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // Find retrieves stack events for the given stack name. 9 func Find(c *gophercloud.ServiceClient, stackName string) (r FindResult) { 10 resp, err := c.Get(findURL(c, stackName), &r.Body, nil) 11 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 12 return 13 } 14 15 // SortDir is a type for specifying in which direction to sort a list of events. 16 type SortDir string 17 18 // SortKey is a type for specifying by which key to sort a list of events. 19 type SortKey string 20 21 // ResourceStatus is a type for specifying by which resource status to filter a 22 // list of events. 23 type ResourceStatus string 24 25 // ResourceAction is a type for specifying by which resource action to filter a 26 // list of events. 27 type ResourceAction string 28 29 var ( 30 // 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 52 // 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. 67 type 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. 73 type 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. 81 ResourceActions []ResourceAction `q:"resource_action"` 82 // 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. 85 ResourceStatuses []ResourceStatus `q:"resource_status"` 86 // 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. 100 func (opts ListOpts) ToStackEventListQuery() (string, error) { 101 q, err := gophercloud.BuildQueryString(opts) 102 return q.String(), err 103 } 104 105 // List makes a request against the API to list resources for the given stack. 106 func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager { 107 url := listURL(client, stackName, stackID) 108 if opts != nil { 109 query, err := opts.ToStackEventListQuery() 110 if err != nil { 111 return pagination.Pager{Err: err} 112 } 113 url += query 114 } 115 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 116 p := EventPage{pagination.MarkerPageBase{PageResult: r}} 117 p.MarkerPageBase.Owner = p 118 return p 119 }) 120 } 121 122 // ListResourceEventsOptsBuilder allows extensions to add additional parameters to the 123 // ListResourceEvents request. 124 type 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. 130 type 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 156 // ToResourceEventListQuery formats a ListResourceEventsOpts into a query string. 157 func (opts ListResourceEventsOpts) ToResourceEventListQuery() (string, error) { 158 q, err := gophercloud.BuildQueryString(opts) 159 return q.String(), err 160 } 161 162 // ListResourceEvents makes a request against the API to list resources for the given stack. 163 func ListResourceEvents(client *gophercloud.ServiceClient, stackName, stackID, resourceName string, opts ListResourceEventsOptsBuilder) pagination.Pager { 164 url := listResourceEventsURL(client, stackName, stackID, resourceName) 165 if opts != nil { 166 query, err := opts.ToResourceEventListQuery() 167 if err != nil { 168 return pagination.Pager{Err: err} 169 } 170 url += query 171 } 172 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 173 p := EventPage{pagination.MarkerPageBase{PageResult: r}} 174 p.MarkerPageBase.Owner = p 175 return p 176 }) 177 } 178 179 // Get retreives data for the given stack resource. 180 func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName, eventID string) (r GetResult) { 181 resp, err := c.Get(getURL(c, stackName, stackID, resourceName, eventID), &r.Body, nil) 182 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 183 return 184 }