blob: 6b6f3a34b3eb12e3caf31b291f4ee190051b5c0f [file] [log] [blame]
Jon Perritt35e27e42014-12-05 11:10:46 -07001package stacks
2
3import (
Jon Perritt3d381d52015-02-09 13:04:48 -07004 "encoding/json"
Jon Perritt35e27e42014-12-05 11:10:46 -07005
Jon Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud"
7 "github.com/gophercloud/gophercloud/pagination"
Jon Perritt35e27e42014-12-05 11:10:46 -07008)
9
Jon Perritt7726e492015-02-04 17:54:28 -070010// CreatedStack represents the object extracted from a Create operation.
Jon Perritt01972e22015-01-28 10:30:45 -070011type CreatedStack struct {
Jon Perritt3c166472016-02-25 03:07:41 -060012 ID string `json:"id"`
13 Links []gophercloud.Link `json:"links"`
Jon Perritt35e27e42014-12-05 11:10:46 -070014}
15
Jon Perritt7726e492015-02-04 17:54:28 -070016// CreateResult represents the result of a Create operation.
Jon Perritt35e27e42014-12-05 11:10:46 -070017type CreateResult struct {
18 gophercloud.Result
19}
20
Jon Perritt7726e492015-02-04 17:54:28 -070021// Extract returns a pointer to a CreatedStack object and is called after a
22// Create operation.
Jon Perritt22325f42015-01-29 14:48:18 -070023func (r CreateResult) Extract() (*CreatedStack, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060024 var s struct {
25 CreatedStack *CreatedStack `json:"stack"`
Jon Perritt35e27e42014-12-05 11:10:46 -070026 }
Jon Perritt3c166472016-02-25 03:07:41 -060027 err := r.ExtractInto(&s)
28 return s.CreatedStack, err
Jon Perritt35e27e42014-12-05 11:10:46 -070029}
30
Jon Perritt7726e492015-02-04 17:54:28 -070031// AdoptResult represents the result of an Adopt operation. AdoptResult has the
32// same form as CreateResult.
Jon Perritt35e27e42014-12-05 11:10:46 -070033type AdoptResult struct {
Jon Perritt9741dd92015-02-04 12:05:47 -070034 CreateResult
Jon Perritt35e27e42014-12-05 11:10:46 -070035}
36
37// StackPage is a pagination.Pager that is returned from a call to the List function.
38type StackPage struct {
39 pagination.SinglePageBase
40}
41
42// IsEmpty returns true if a ListResult contains no Stacks.
43func (r StackPage) IsEmpty() (bool, error) {
44 stacks, err := ExtractStacks(r)
Jon Perritt3c166472016-02-25 03:07:41 -060045 return len(stacks) == 0, err
Jon Perritt35e27e42014-12-05 11:10:46 -070046}
47
Jon Perritt7726e492015-02-04 17:54:28 -070048// ListedStack represents an element in the slice extracted from a List operation.
Jon Perritt01972e22015-01-28 10:30:45 -070049type ListedStack struct {
Jon Perritt3c166472016-02-25 03:07:41 -060050 CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
51 Description string `json:"description"`
52 ID string `json:"id"`
53 Links []gophercloud.Link `json:"links"`
54 Name string `json:"stack_name"`
55 Status string `json:"stack_status"`
56 StatusReason string `json:"stack_status_reason"`
57 Tags []string `json:"tags"`
58 UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
Jon Perritt35e27e42014-12-05 11:10:46 -070059}
60
Jon Perritt7726e492015-02-04 17:54:28 -070061// ExtractStacks extracts and returns a slice of ListedStack. It is used while iterating
Jon Perritt35e27e42014-12-05 11:10:46 -070062// over a stacks.List call.
Jon Perritt3c166472016-02-25 03:07:41 -060063func ExtractStacks(r pagination.Page) ([]ListedStack, error) {
64 var s struct {
65 ListedStacks []ListedStack `json:"stacks"`
Jon Perritt35e27e42014-12-05 11:10:46 -070066 }
Jon Perritt3c166472016-02-25 03:07:41 -060067 err := (r.(StackPage)).ExtractInto(&s)
68 return s.ListedStacks, err
Jon Perritt35e27e42014-12-05 11:10:46 -070069}
70
Jon Perritt7726e492015-02-04 17:54:28 -070071// RetrievedStack represents the object extracted from a Get operation.
Jon Perritt01972e22015-01-28 10:30:45 -070072type RetrievedStack struct {
Jon Perritt3c166472016-02-25 03:07:41 -060073 Capabilities []interface{} `json:"capabilities"`
74 CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
75 Description string `json:"description"`
76 DisableRollback bool `json:"disable_rollback"`
77 ID string `json:"id"`
78 Links []gophercloud.Link `json:"links"`
79 NotificationTopics []interface{} `json:"notification_topics"`
80 Outputs []map[string]interface{} `json:"outputs"`
81 Parameters map[string]string `json:"parameters"`
82 Name string `json:"stack_name"`
83 Status string `json:"stack_status"`
84 StatusReason string `json:"stack_status_reason"`
85 Tags []string `json:"tags"`
86 TemplateDescription string `json:"template_description"`
87 Timeout int `json:"timeout_mins"`
88 UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
Jon Perritt35e27e42014-12-05 11:10:46 -070089}
90
Jon Perritt7726e492015-02-04 17:54:28 -070091// GetResult represents the result of a Get operation.
Jon Perritt35e27e42014-12-05 11:10:46 -070092type GetResult struct {
93 gophercloud.Result
94}
95
Jon Perritt7726e492015-02-04 17:54:28 -070096// Extract returns a pointer to a RetrievedStack object and is called after a
97// Get operation.
Jon Perritt22325f42015-01-29 14:48:18 -070098func (r GetResult) Extract() (*RetrievedStack, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060099 var s struct {
100 Stack *RetrievedStack `json:"stack"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700101 }
Jon Perritt3c166472016-02-25 03:07:41 -0600102 err := r.ExtractInto(&s)
103 return s.Stack, err
Jon Perritt35e27e42014-12-05 11:10:46 -0700104}
105
Jon Perritt7726e492015-02-04 17:54:28 -0700106// UpdateResult represents the result of a Update operation.
Jon Perritt35e27e42014-12-05 11:10:46 -0700107type UpdateResult struct {
108 gophercloud.ErrResult
109}
110
Jon Perritt7726e492015-02-04 17:54:28 -0700111// DeleteResult represents the result of a Delete operation.
Jon Perritt35e27e42014-12-05 11:10:46 -0700112type DeleteResult struct {
113 gophercloud.ErrResult
114}
115
Jon Perritt37f97742015-02-04 18:55:05 -0700116// PreviewedStack represents the result of a Preview operation.
Jon Perritt01972e22015-01-28 10:30:45 -0700117type PreviewedStack struct {
Jon Perritt3c166472016-02-25 03:07:41 -0600118 Capabilities []interface{} `json:"capabilities"`
119 CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
120 Description string `json:"description"`
121 DisableRollback bool `json:"disable_rollback"`
122 ID string `json:"id"`
123 Links []gophercloud.Link `json:"links"`
124 Name string `json:"stack_name"`
125 NotificationTopics []interface{} `json:"notification_topics"`
126 Parameters map[string]string `json:"parameters"`
127 Resources []interface{} `json:"resources"`
128 TemplateDescription string `json:"template_description"`
129 Timeout int `json:"timeout_mins"`
130 UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700131}
132
Jon Perritt37f97742015-02-04 18:55:05 -0700133// PreviewResult represents the result of a Preview operation.
Jon Perritt35e27e42014-12-05 11:10:46 -0700134type PreviewResult struct {
135 gophercloud.Result
136}
137
Jon Perritt37f97742015-02-04 18:55:05 -0700138// Extract returns a pointer to a PreviewedStack object and is called after a
139// Preview operation.
Jon Perritt22325f42015-01-29 14:48:18 -0700140func (r PreviewResult) Extract() (*PreviewedStack, error) {
Jon Perritt3c166472016-02-25 03:07:41 -0600141 var s struct {
142 PreviewedStack *PreviewedStack `json:"stack"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700143 }
Jon Perritt3c166472016-02-25 03:07:41 -0600144 err := r.ExtractInto(&s)
145 return s.PreviewedStack, err
Jon Perritt35e27e42014-12-05 11:10:46 -0700146}
147
Jon Perritt9209df42015-02-05 12:55:33 -0700148// AbandonedStack represents the result of an Abandon operation.
Jon Perritt01972e22015-01-28 10:30:45 -0700149type AbandonedStack struct {
Jon Perritt3c166472016-02-25 03:07:41 -0600150 Status string `json:"status"`
151 Name string `json:"name"`
152 Template map[string]interface{} `json:"template"`
153 Action string `json:"action"`
154 ID string `json:"id"`
155 Resources map[string]interface{} `json:"resources"`
156 Files map[string]string `json:"files"`
157 StackUserProjectID string `json:"stack_user_project_id"`
158 ProjectID string `json:"project_id"`
159 Environment map[string]interface{} `json:"environment"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700160}
161
Jon Perritt9209df42015-02-05 12:55:33 -0700162// AbandonResult represents the result of an Abandon operation.
Jon Perritt35e27e42014-12-05 11:10:46 -0700163type AbandonResult struct {
164 gophercloud.Result
165}
Jon Perritt9209df42015-02-05 12:55:33 -0700166
167// Extract returns a pointer to an AbandonedStack object and is called after an
168// Abandon operation.
169func (r AbandonResult) Extract() (*AbandonedStack, error) {
Jon Perritt3c166472016-02-25 03:07:41 -0600170 var s *AbandonedStack
171 err := r.ExtractInto(&s)
172 return s, err
Jon Perritt9209df42015-02-05 12:55:33 -0700173}
Jon Perritt3d381d52015-02-09 13:04:48 -0700174
Jon Perrittdb0d26a2015-02-09 13:06:16 -0700175// String converts an AbandonResult to a string. This is useful to when passing
176// the result of an Abandon operation to an AdoptOpts AdoptStackData field.
Jon Perritt3d381d52015-02-09 13:04:48 -0700177func (r AbandonResult) String() (string, error) {
178 out, err := json.Marshal(r)
Jon Perritt31b66462016-02-25 22:25:30 -0600179 return string(out), err
Jon Perritt3d381d52015-02-09 13:04:48 -0700180}