blob: 46d0f465f3a4782f9725856ca75d7a8854dd114f [file] [log] [blame]
Jon Perritt35e27e42014-12-05 11:10:46 -07001package stacks
2
3import (
Pratik Mallya827c03e2015-09-17 00:10:47 -05004 "strings"
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
10// CreateOptsBuilder is the interface options structs have to satisfy in order
11// to be used in the main Create operation in this package. Since many
12// extensions decorate or modify the common logic, it is useful for them to
13// satisfy a basic interface in order for them to be used.
14type CreateOptsBuilder interface {
15 ToStackCreateMap() (map[string]interface{}, error)
16}
17
18// CreateOpts is the common options struct used in this package's Create
19// operation.
20type CreateOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -050021 // The name of the stack. It must start with an alphabetic character.
22 Name string `json:"stack_name" required:"true"`
23 // A structure that contains either the template file or url. Call the
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050024 // associated methods to extract the information relevant to send in a create request.
Jon Perrittfea90732016-03-15 02:57:05 -050025 TemplateOpts *Template `json:"-" required:"true"`
26 // Enables or disables deletion of all stack resources when a stack
Jon Perritt952f3e12015-02-03 12:13:24 -070027 // creation fails. Default is true, meaning all resources are not deleted when
28 // stack creation fails.
Jon Perrittfea90732016-03-15 02:57:05 -050029 DisableRollback *bool `json:"disable_rollback,omitempty"`
30 // A structure that contains details for the environment of the stack.
31 EnvironmentOpts *Environment `json:"-"`
32 // User-defined parameters to pass to the template.
33 Parameters map[string]string `json:"parameters,omitempty"`
34 // The timeout for stack creation in minutes.
35 Timeout int `json:"timeout_mins,omitempty"`
36 // A list of tags to assosciate with the Stack
37 Tags []string `json:"-"`
Jon Perritt35e27e42014-12-05 11:10:46 -070038}
39
40// ToStackCreateMap casts a CreateOpts struct to a map.
41func (opts CreateOpts) ToStackCreateMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -050042 b, err := gophercloud.BuildRequestBody(opts, "")
43 if err != nil {
Jon Perritt58611da2016-03-09 00:49:57 -060044 return nil, err
Jon Perritt35e27e42014-12-05 11:10:46 -070045 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050046
Jon Perrittfea90732016-03-15 02:57:05 -050047 if err := opts.TemplateOpts.Parse(); err != nil {
48 return nil, err
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050049 }
Jon Perrittfea90732016-03-15 02:57:05 -050050
51 if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
52 return nil, err
53 }
54 opts.TemplateOpts.fixFileRefs()
55 b["template"] = string(opts.TemplateOpts.Bin)
56
57 files := make(map[string]string)
58 for k, v := range opts.TemplateOpts.Files {
59 files[k] = v
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050060 }
61
62 if opts.EnvironmentOpts != nil {
63 if err := opts.EnvironmentOpts.Parse(); err != nil {
64 return nil, err
65 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -050066 if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050067 return nil, err
68 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -050069 opts.EnvironmentOpts.fixFileRefs()
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050070 for k, v := range opts.EnvironmentOpts.Files {
Jon Perrittfea90732016-03-15 02:57:05 -050071 files[k] = v
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050072 }
Jon Perrittfea90732016-03-15 02:57:05 -050073 b["environment"] = string(opts.EnvironmentOpts.Bin)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050074 }
75
Jon Perrittfea90732016-03-15 02:57:05 -050076 if len(files) > 0 {
77 b["files"] = files
Jon Perritt35e27e42014-12-05 11:10:46 -070078 }
79
Pratik Mallya827c03e2015-09-17 00:10:47 -050080 if opts.Tags != nil {
Jon Perrittfea90732016-03-15 02:57:05 -050081 b["tags"] = strings.Join(opts.Tags, ",")
Pratik Mallya827c03e2015-09-17 00:10:47 -050082 }
Jon Perrittfea90732016-03-15 02:57:05 -050083
84 return b, nil
Jon Perritt35e27e42014-12-05 11:10:46 -070085}
86
87// Create accepts a CreateOpts struct and creates a new stack using the values
88// provided.
Jon Perritt3860b512016-03-29 12:01:48 -050089func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050090 b, err := opts.ToStackCreateMap()
Jon Perritt35e27e42014-12-05 11:10:46 -070091 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -050092 r.Err = err
Jon Perritt3860b512016-03-29 12:01:48 -050093 return
Jon Perritt35e27e42014-12-05 11:10:46 -070094 }
Jon Perrittfea90732016-03-15 02:57:05 -050095 _, r.Err = c.Post(createURL(c), b, &r.Body, nil)
Jon Perritt35e27e42014-12-05 11:10:46 -070096}
97
98// AdoptOptsBuilder is the interface options structs have to satisfy in order
99// to be used in the Adopt function in this package. Since many
100// extensions decorate or modify the common logic, it is useful for them to
101// satisfy a basic interface in order for them to be used.
102type AdoptOptsBuilder interface {
103 ToStackAdoptMap() (map[string]interface{}, error)
104}
105
106// AdoptOpts is the common options struct used in this package's Adopt
107// operation.
108type AdoptOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -0500109 // Existing resources data represented as a string to add to the
Jon Perritt9741dd92015-02-04 12:05:47 -0700110 // new stack. Data returned by Abandon could be provided as AdoptsStackData.
Jon Perrittfea90732016-03-15 02:57:05 -0500111 AdoptStackData string `json:"adopt_stack_data" required:"true"`
112 // The name of the stack. It must start with an alphabetic character.
113 Name string `json:"stack_name" required:"true"`
Jon Perritt397ade62016-03-15 06:55:02 -0500114 // A structure that contains either the template file or url. Call the
115 // associated methods to extract the information relevant to send in a create request.
116 TemplateOpts *Template `json:"-" required:"true"`
Jon Perrittfea90732016-03-15 02:57:05 -0500117 // The timeout for stack creation in minutes.
118 Timeout int `json:"timeout_mins,omitempty"`
119 // A structure that contains either the template file or url. Call the
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500120 // associated methods to extract the information relevant to send in a create request.
Jon Perrittfea90732016-03-15 02:57:05 -0500121 //TemplateOpts *Template `json:"-" required:"true"`
122 // Enables or disables deletion of all stack resources when a stack
Jon Perritt9741dd92015-02-04 12:05:47 -0700123 // creation fails. Default is true, meaning all resources are not deleted when
124 // stack creation fails.
Jon Perrittfea90732016-03-15 02:57:05 -0500125 DisableRollback *bool `json:"disable_rollback,omitempty"`
126 // A structure that contains details for the environment of the stack.
127 EnvironmentOpts *Environment `json:"-"`
128 // User-defined parameters to pass to the template.
129 Parameters map[string]string `json:"parameters,omitempty"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700130}
131
132// ToStackAdoptMap casts a CreateOpts struct to a map.
133func (opts AdoptOpts) ToStackAdoptMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -0500134 b, err := gophercloud.BuildRequestBody(opts, "")
135 if err != nil {
Jon Perritt58611da2016-03-09 00:49:57 -0600136 return nil, err
Jon Perritt35e27e42014-12-05 11:10:46 -0700137 }
Jon Perrittfea90732016-03-15 02:57:05 -0500138
Jon Perritt397ade62016-03-15 06:55:02 -0500139 if err := opts.TemplateOpts.Parse(); err != nil {
140 return nil, err
141 }
142
143 if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
144 return nil, err
145 }
146 opts.TemplateOpts.fixFileRefs()
147 b["template"] = string(opts.TemplateOpts.Bin)
148
Jon Perrittfea90732016-03-15 02:57:05 -0500149 files := make(map[string]string)
Jon Perritt397ade62016-03-15 06:55:02 -0500150 for k, v := range opts.TemplateOpts.Files {
151 files[k] = v
152 }
Jon Perritt35e27e42014-12-05 11:10:46 -0700153
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500154 if opts.EnvironmentOpts != nil {
155 if err := opts.EnvironmentOpts.Parse(); err != nil {
156 return nil, err
157 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500158 if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500159 return nil, err
160 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500161 opts.EnvironmentOpts.fixFileRefs()
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500162 for k, v := range opts.EnvironmentOpts.Files {
Jon Perrittfea90732016-03-15 02:57:05 -0500163 files[k] = v
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500164 }
Jon Perrittfea90732016-03-15 02:57:05 -0500165 b["environment"] = string(opts.EnvironmentOpts.Bin)
Jon Perritt35e27e42014-12-05 11:10:46 -0700166 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500167
Jon Perrittfea90732016-03-15 02:57:05 -0500168 if len(files) > 0 {
169 b["files"] = files
Jon Perritt35e27e42014-12-05 11:10:46 -0700170 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500171
Jon Perrittfea90732016-03-15 02:57:05 -0500172 return b, nil
Jon Perritt35e27e42014-12-05 11:10:46 -0700173}
174
175// Adopt accepts an AdoptOpts struct and creates a new stack using the resources
176// from another stack.
Jon Perritt3860b512016-03-29 12:01:48 -0500177func Adopt(c *gophercloud.ServiceClient, opts AdoptOptsBuilder) (r AdoptResult) {
Jon Perrittfea90732016-03-15 02:57:05 -0500178 b, err := opts.ToStackAdoptMap()
Jon Perritt35e27e42014-12-05 11:10:46 -0700179 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -0500180 r.Err = err
Jon Perritt3860b512016-03-29 12:01:48 -0500181 return
Jon Perritt35e27e42014-12-05 11:10:46 -0700182 }
Jon Perrittfea90732016-03-15 02:57:05 -0500183 _, r.Err = c.Post(adoptURL(c), b, &r.Body, nil)
Jon Perritt35e27e42014-12-05 11:10:46 -0700184}
185
186// SortDir is a type for specifying in which direction to sort a list of stacks.
187type SortDir string
188
189// SortKey is a type for specifying by which key to sort a list of stacks.
190type SortKey string
191
192var (
193 // SortAsc is used to sort a list of stacks in ascending order.
194 SortAsc SortDir = "asc"
195 // SortDesc is used to sort a list of stacks in descending order.
196 SortDesc SortDir = "desc"
197 // SortName is used to sort a list of stacks by name.
198 SortName SortKey = "name"
199 // SortStatus is used to sort a list of stacks by status.
200 SortStatus SortKey = "status"
201 // SortCreatedAt is used to sort a list of stacks by date created.
202 SortCreatedAt SortKey = "created_at"
203 // SortUpdatedAt is used to sort a list of stacks by date updated.
204 SortUpdatedAt SortKey = "updated_at"
205)
206
207// ListOptsBuilder allows extensions to add additional parameters to the
208// List request.
209type ListOptsBuilder interface {
210 ToStackListQuery() (string, error)
211}
212
213// ListOpts allows the filtering and sorting of paginated collections through
214// the API. Filtering is achieved by passing in struct field values that map to
215// the network attributes you want to see returned. SortKey allows you to sort
216// by a particular network attribute. SortDir sets the direction, and is either
217// `asc' or `desc'. Marker and Limit are used for pagination.
218type ListOpts struct {
219 Status string `q:"status"`
220 Name string `q:"name"`
221 Marker string `q:"marker"`
222 Limit int `q:"limit"`
223 SortKey SortKey `q:"sort_keys"`
224 SortDir SortDir `q:"sort_dir"`
225}
226
227// ToStackListQuery formats a ListOpts into a query string.
228func (opts ListOpts) ToStackListQuery() (string, error) {
229 q, err := gophercloud.BuildQueryString(opts)
230 if err != nil {
231 return "", err
232 }
233 return q.String(), nil
234}
235
236// List returns a Pager which allows you to iterate over a collection of
237// stacks. It accepts a ListOpts struct, which allows you to filter and sort
238// the returned collection for greater efficiency.
239func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
240 url := listURL(c)
241 if opts != nil {
242 query, err := opts.ToStackListQuery()
243 if err != nil {
244 return pagination.Pager{Err: err}
245 }
246 url += query
247 }
Jon Perritt35e27e42014-12-05 11:10:46 -0700248 createPage := func(r pagination.PageResult) pagination.Page {
249 return StackPage{pagination.SinglePageBase(r)}
250 }
251 return pagination.NewPager(c, url, createPage)
252}
253
254// Get retreives a stack based on the stack name and stack ID.
255func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult {
Jon Perrittfea90732016-03-15 02:57:05 -0500256 var r GetResult
257 _, r.Err = c.Get(getURL(c, stackName, stackID), &r.Body, nil)
258 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700259}
260
261// UpdateOptsBuilder is the interface options structs have to satisfy in order
262// to be used in the Update operation in this package.
263type UpdateOptsBuilder interface {
264 ToStackUpdateMap() (map[string]interface{}, error)
265}
266
267// UpdateOpts contains the common options struct used in this package's Update
268// operation.
269type UpdateOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -0500270 // A structure that contains either the template file or url. Call the
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500271 // associated methods to extract the information relevant to send in a create request.
Jon Perrittfea90732016-03-15 02:57:05 -0500272 TemplateOpts *Template `json:"-" required:"true"`
273 // A structure that contains details for the environment of the stack.
274 EnvironmentOpts *Environment `json:"-"`
275 // User-defined parameters to pass to the template.
276 Parameters map[string]string `json:"parameters,omitempty"`
277 // The timeout for stack creation in minutes.
278 Timeout int `json:"timeout_mins,omitempty"`
279 // A list of tags to assosciate with the Stack
280 Tags []string `json:"-"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700281}
282
283// ToStackUpdateMap casts a CreateOpts struct to a map.
284func (opts UpdateOpts) ToStackUpdateMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -0500285 b, err := gophercloud.BuildRequestBody(opts, "")
286 if err != nil {
287 return nil, err
288 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500289
Jon Perrittfea90732016-03-15 02:57:05 -0500290 if err := opts.TemplateOpts.Parse(); err != nil {
291 return nil, err
292 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500293
Jon Perrittfea90732016-03-15 02:57:05 -0500294 if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
295 return nil, err
296 }
297 opts.TemplateOpts.fixFileRefs()
298 b["template"] = string(opts.TemplateOpts.Bin)
299
300 files := make(map[string]string)
301 for k, v := range opts.TemplateOpts.Files {
302 files[k] = v
Jon Perritt35e27e42014-12-05 11:10:46 -0700303 }
304
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500305 if opts.EnvironmentOpts != nil {
306 if err := opts.EnvironmentOpts.Parse(); err != nil {
307 return nil, err
308 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500309 if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500310 return nil, err
311 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500312 opts.EnvironmentOpts.fixFileRefs()
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500313 for k, v := range opts.EnvironmentOpts.Files {
Jon Perrittfea90732016-03-15 02:57:05 -0500314 files[k] = v
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500315 }
Jon Perrittfea90732016-03-15 02:57:05 -0500316 b["environment"] = string(opts.EnvironmentOpts.Bin)
Jon Perritt35e27e42014-12-05 11:10:46 -0700317 }
318
Jon Perrittfea90732016-03-15 02:57:05 -0500319 if len(files) > 0 {
320 b["files"] = files
Jon Perritt35e27e42014-12-05 11:10:46 -0700321 }
322
Pratik Mallya827c03e2015-09-17 00:10:47 -0500323 if opts.Tags != nil {
Jon Perrittfea90732016-03-15 02:57:05 -0500324 b["tags"] = strings.Join(opts.Tags, ",")
Pratik Mallya827c03e2015-09-17 00:10:47 -0500325 }
326
Jon Perrittfea90732016-03-15 02:57:05 -0500327 return b, nil
Jon Perritt35e27e42014-12-05 11:10:46 -0700328}
329
330// Update accepts an UpdateOpts struct and updates an existing stack using the values
331// provided.
Jon Perritt3860b512016-03-29 12:01:48 -0500332func Update(c *gophercloud.ServiceClient, stackName, stackID string, opts UpdateOptsBuilder) (r UpdateResult) {
Jon Perrittfea90732016-03-15 02:57:05 -0500333 b, err := opts.ToStackUpdateMap()
Jon Perritt35e27e42014-12-05 11:10:46 -0700334 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -0500335 r.Err = err
Jon Perritt3860b512016-03-29 12:01:48 -0500336 return
Jon Perritt35e27e42014-12-05 11:10:46 -0700337 }
Jon Perrittfea90732016-03-15 02:57:05 -0500338 _, r.Err = c.Put(updateURL(c, stackName, stackID), b, nil, nil)
Jon Perritt35e27e42014-12-05 11:10:46 -0700339}
340
341// Delete deletes a stack based on the stack name and stack ID.
Jon Perritt3860b512016-03-29 12:01:48 -0500342func Delete(c *gophercloud.ServiceClient, stackName, stackID string) (r DeleteResult) {
Jon Perrittfea90732016-03-15 02:57:05 -0500343 _, r.Err = c.Delete(deleteURL(c, stackName, stackID), nil)
Jon Perritt35e27e42014-12-05 11:10:46 -0700344}
345
346// PreviewOptsBuilder is the interface options structs have to satisfy in order
347// to be used in the Preview operation in this package.
348type PreviewOptsBuilder interface {
349 ToStackPreviewMap() (map[string]interface{}, error)
350}
351
352// PreviewOpts contains the common options struct used in this package's Preview
353// operation.
354type PreviewOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -0500355 // The name of the stack. It must start with an alphabetic character.
356 Name string `json:"stack_name" required:"true"`
357 // The timeout for stack creation in minutes.
358 Timeout int `json:"timeout_mins" required:"true"`
359 // A structure that contains either the template file or url. Call the
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500360 // associated methods to extract the information relevant to send in a create request.
Jon Perrittfea90732016-03-15 02:57:05 -0500361 TemplateOpts *Template `json:"-" required:"true"`
362 // Enables or disables deletion of all stack resources when a stack
Jon Perritt37f97742015-02-04 18:55:05 -0700363 // creation fails. Default is true, meaning all resources are not deleted when
364 // stack creation fails.
Jon Perrittfea90732016-03-15 02:57:05 -0500365 DisableRollback *bool `json:"disable_rollback,omitempty"`
366 // A structure that contains details for the environment of the stack.
367 EnvironmentOpts *Environment `json:"-"`
368 // User-defined parameters to pass to the template.
369 Parameters map[string]string `json:"parameters,omitempty"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700370}
371
372// ToStackPreviewMap casts a PreviewOpts struct to a map.
373func (opts PreviewOpts) ToStackPreviewMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -0500374 b, err := gophercloud.BuildRequestBody(opts, "")
375 if err != nil {
Jon Perritt58611da2016-03-09 00:49:57 -0600376 return nil, err
Jon Perritt35e27e42014-12-05 11:10:46 -0700377 }
Jon Perritt35e27e42014-12-05 11:10:46 -0700378
Jon Perrittfea90732016-03-15 02:57:05 -0500379 if err := opts.TemplateOpts.Parse(); err != nil {
380 return nil, err
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500381 }
Jon Perrittfea90732016-03-15 02:57:05 -0500382
383 if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
384 return nil, err
385 }
386 opts.TemplateOpts.fixFileRefs()
387 b["template"] = string(opts.TemplateOpts.Bin)
388
389 files := make(map[string]string)
390 for k, v := range opts.TemplateOpts.Files {
391 files[k] = v
Jon Perritt35e27e42014-12-05 11:10:46 -0700392 }
393
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500394 if opts.EnvironmentOpts != nil {
395 if err := opts.EnvironmentOpts.Parse(); err != nil {
396 return nil, err
397 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500398 if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500399 return nil, err
400 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500401 opts.EnvironmentOpts.fixFileRefs()
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500402 for k, v := range opts.EnvironmentOpts.Files {
Jon Perrittfea90732016-03-15 02:57:05 -0500403 files[k] = v
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500404 }
Jon Perrittfea90732016-03-15 02:57:05 -0500405 b["environment"] = string(opts.EnvironmentOpts.Bin)
Jon Perritt35e27e42014-12-05 11:10:46 -0700406 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500407
Jon Perrittfea90732016-03-15 02:57:05 -0500408 if len(files) > 0 {
409 b["files"] = files
Jon Perritt35e27e42014-12-05 11:10:46 -0700410 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500411
Jon Perrittfea90732016-03-15 02:57:05 -0500412 return b, nil
Jon Perritt35e27e42014-12-05 11:10:46 -0700413}
414
415// Preview accepts a PreviewOptsBuilder interface and creates a preview of a stack using the values
416// provided.
Jon Perritt3860b512016-03-29 12:01:48 -0500417func Preview(c *gophercloud.ServiceClient, opts PreviewOptsBuilder) (r PreviewResult) {
Jon Perrittfea90732016-03-15 02:57:05 -0500418 b, err := opts.ToStackPreviewMap()
Jon Perritt35e27e42014-12-05 11:10:46 -0700419 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -0500420 r.Err = err
Jon Perritt3860b512016-03-29 12:01:48 -0500421 return
Jon Perritt35e27e42014-12-05 11:10:46 -0700422 }
Jon Perrittfea90732016-03-15 02:57:05 -0500423 _, r.Err = c.Post(previewURL(c), b, &r.Body, &gophercloud.RequestOpts{
Jamie Hannaford1d27afa2015-03-24 16:20:45 +0100424 OkCodes: []int{200},
Jon Perritt35e27e42014-12-05 11:10:46 -0700425 })
Jon Perritt35e27e42014-12-05 11:10:46 -0700426}
427
428// Abandon deletes the stack with the provided stackName and stackID, but leaves its
429// resources intact, and returns data describing the stack and its resources.
Jon Perritt3860b512016-03-29 12:01:48 -0500430func Abandon(c *gophercloud.ServiceClient, stackName, stackID string) (r AbandonResult) {
Jon Perrittfea90732016-03-15 02:57:05 -0500431 _, r.Err = c.Delete(abandonURL(c, stackName, stackID), &gophercloud.RequestOpts{
432 JSONResponse: &r.Body,
Ash Wilsondecfed72015-02-13 09:14:55 -0500433 OkCodes: []int{200},
Jon Perritt35e27e42014-12-05 11:10:46 -0700434 })
Jon Perritt35e27e42014-12-05 11:10:46 -0700435}