blob: 04c5150b32801c00d743afa51925541b4f4284fd [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.
89func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
Jon Perrittfea90732016-03-15 02:57:05 -050090 var r CreateResult
91 b, err := opts.ToStackCreateMap()
Jon Perritt35e27e42014-12-05 11:10:46 -070092 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -050093 r.Err = err
94 return r
Jon Perritt35e27e42014-12-05 11:10:46 -070095 }
Jon Perrittfea90732016-03-15 02:57:05 -050096 _, r.Err = c.Post(createURL(c), b, &r.Body, nil)
97 return r
Jon Perritt35e27e42014-12-05 11:10:46 -070098}
99
100// AdoptOptsBuilder is the interface options structs have to satisfy in order
101// to be used in the Adopt function in this package. Since many
102// extensions decorate or modify the common logic, it is useful for them to
103// satisfy a basic interface in order for them to be used.
104type AdoptOptsBuilder interface {
105 ToStackAdoptMap() (map[string]interface{}, error)
106}
107
108// AdoptOpts is the common options struct used in this package's Adopt
109// operation.
110type AdoptOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -0500111 // Existing resources data represented as a string to add to the
Jon Perritt9741dd92015-02-04 12:05:47 -0700112 // new stack. Data returned by Abandon could be provided as AdoptsStackData.
Jon Perrittfea90732016-03-15 02:57:05 -0500113 AdoptStackData string `json:"adopt_stack_data" required:"true"`
114 // The name of the stack. It must start with an alphabetic character.
115 Name string `json:"stack_name" required:"true"`
Jon Perritt397ade62016-03-15 06:55:02 -0500116 // A structure that contains either the template file or url. Call the
117 // associated methods to extract the information relevant to send in a create request.
118 TemplateOpts *Template `json:"-" required:"true"`
Jon Perrittfea90732016-03-15 02:57:05 -0500119 // The timeout for stack creation in minutes.
120 Timeout int `json:"timeout_mins,omitempty"`
121 // A structure that contains either the template file or url. Call the
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500122 // associated methods to extract the information relevant to send in a create request.
Jon Perrittfea90732016-03-15 02:57:05 -0500123 //TemplateOpts *Template `json:"-" required:"true"`
124 // Enables or disables deletion of all stack resources when a stack
Jon Perritt9741dd92015-02-04 12:05:47 -0700125 // creation fails. Default is true, meaning all resources are not deleted when
126 // stack creation fails.
Jon Perrittfea90732016-03-15 02:57:05 -0500127 DisableRollback *bool `json:"disable_rollback,omitempty"`
128 // A structure that contains details for the environment of the stack.
129 EnvironmentOpts *Environment `json:"-"`
130 // User-defined parameters to pass to the template.
131 Parameters map[string]string `json:"parameters,omitempty"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700132}
133
134// ToStackAdoptMap casts a CreateOpts struct to a map.
135func (opts AdoptOpts) ToStackAdoptMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -0500136 b, err := gophercloud.BuildRequestBody(opts, "")
137 if err != nil {
Jon Perritt58611da2016-03-09 00:49:57 -0600138 return nil, err
Jon Perritt35e27e42014-12-05 11:10:46 -0700139 }
Jon Perrittfea90732016-03-15 02:57:05 -0500140
Jon Perritt397ade62016-03-15 06:55:02 -0500141 if err := opts.TemplateOpts.Parse(); err != nil {
142 return nil, err
143 }
144
145 if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
146 return nil, err
147 }
148 opts.TemplateOpts.fixFileRefs()
149 b["template"] = string(opts.TemplateOpts.Bin)
150
Jon Perrittfea90732016-03-15 02:57:05 -0500151 files := make(map[string]string)
Jon Perritt397ade62016-03-15 06:55:02 -0500152 for k, v := range opts.TemplateOpts.Files {
153 files[k] = v
154 }
Jon Perritt35e27e42014-12-05 11:10:46 -0700155
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500156 if opts.EnvironmentOpts != nil {
157 if err := opts.EnvironmentOpts.Parse(); err != nil {
158 return nil, err
159 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500160 if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500161 return nil, err
162 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500163 opts.EnvironmentOpts.fixFileRefs()
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500164 for k, v := range opts.EnvironmentOpts.Files {
Jon Perrittfea90732016-03-15 02:57:05 -0500165 files[k] = v
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500166 }
Jon Perrittfea90732016-03-15 02:57:05 -0500167 b["environment"] = string(opts.EnvironmentOpts.Bin)
Jon Perritt35e27e42014-12-05 11:10:46 -0700168 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500169
Jon Perrittfea90732016-03-15 02:57:05 -0500170 if len(files) > 0 {
171 b["files"] = files
Jon Perritt35e27e42014-12-05 11:10:46 -0700172 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500173
Jon Perrittfea90732016-03-15 02:57:05 -0500174 return b, nil
Jon Perritt35e27e42014-12-05 11:10:46 -0700175}
176
177// Adopt accepts an AdoptOpts struct and creates a new stack using the resources
178// from another stack.
Jon Perritt9741dd92015-02-04 12:05:47 -0700179func Adopt(c *gophercloud.ServiceClient, opts AdoptOptsBuilder) AdoptResult {
Jon Perrittfea90732016-03-15 02:57:05 -0500180 var r AdoptResult
181 b, err := opts.ToStackAdoptMap()
Jon Perritt35e27e42014-12-05 11:10:46 -0700182 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -0500183 r.Err = err
184 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700185 }
Jon Perrittfea90732016-03-15 02:57:05 -0500186 _, r.Err = c.Post(adoptURL(c), b, &r.Body, nil)
187 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700188}
189
190// SortDir is a type for specifying in which direction to sort a list of stacks.
191type SortDir string
192
193// SortKey is a type for specifying by which key to sort a list of stacks.
194type SortKey string
195
196var (
197 // SortAsc is used to sort a list of stacks in ascending order.
198 SortAsc SortDir = "asc"
199 // SortDesc is used to sort a list of stacks in descending order.
200 SortDesc SortDir = "desc"
201 // SortName is used to sort a list of stacks by name.
202 SortName SortKey = "name"
203 // SortStatus is used to sort a list of stacks by status.
204 SortStatus SortKey = "status"
205 // SortCreatedAt is used to sort a list of stacks by date created.
206 SortCreatedAt SortKey = "created_at"
207 // SortUpdatedAt is used to sort a list of stacks by date updated.
208 SortUpdatedAt SortKey = "updated_at"
209)
210
211// ListOptsBuilder allows extensions to add additional parameters to the
212// List request.
213type ListOptsBuilder interface {
214 ToStackListQuery() (string, error)
215}
216
217// ListOpts allows the filtering and sorting of paginated collections through
218// the API. Filtering is achieved by passing in struct field values that map to
219// the network attributes you want to see returned. SortKey allows you to sort
220// by a particular network attribute. SortDir sets the direction, and is either
221// `asc' or `desc'. Marker and Limit are used for pagination.
222type ListOpts struct {
223 Status string `q:"status"`
224 Name string `q:"name"`
225 Marker string `q:"marker"`
226 Limit int `q:"limit"`
227 SortKey SortKey `q:"sort_keys"`
228 SortDir SortDir `q:"sort_dir"`
229}
230
231// ToStackListQuery formats a ListOpts into a query string.
232func (opts ListOpts) ToStackListQuery() (string, error) {
233 q, err := gophercloud.BuildQueryString(opts)
234 if err != nil {
235 return "", err
236 }
237 return q.String(), nil
238}
239
240// List returns a Pager which allows you to iterate over a collection of
241// stacks. It accepts a ListOpts struct, which allows you to filter and sort
242// the returned collection for greater efficiency.
243func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
244 url := listURL(c)
245 if opts != nil {
246 query, err := opts.ToStackListQuery()
247 if err != nil {
248 return pagination.Pager{Err: err}
249 }
250 url += query
251 }
Jon Perritt35e27e42014-12-05 11:10:46 -0700252 createPage := func(r pagination.PageResult) pagination.Page {
253 return StackPage{pagination.SinglePageBase(r)}
254 }
255 return pagination.NewPager(c, url, createPage)
256}
257
258// Get retreives a stack based on the stack name and stack ID.
259func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult {
Jon Perrittfea90732016-03-15 02:57:05 -0500260 var r GetResult
261 _, r.Err = c.Get(getURL(c, stackName, stackID), &r.Body, nil)
262 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700263}
264
265// UpdateOptsBuilder is the interface options structs have to satisfy in order
266// to be used in the Update operation in this package.
267type UpdateOptsBuilder interface {
268 ToStackUpdateMap() (map[string]interface{}, error)
269}
270
271// UpdateOpts contains the common options struct used in this package's Update
272// operation.
273type UpdateOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -0500274 // A structure that contains either the template file or url. Call the
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500275 // associated methods to extract the information relevant to send in a create request.
Jon Perrittfea90732016-03-15 02:57:05 -0500276 TemplateOpts *Template `json:"-" required:"true"`
277 // A structure that contains details for the environment of the stack.
278 EnvironmentOpts *Environment `json:"-"`
279 // User-defined parameters to pass to the template.
280 Parameters map[string]string `json:"parameters,omitempty"`
281 // The timeout for stack creation in minutes.
282 Timeout int `json:"timeout_mins,omitempty"`
283 // A list of tags to assosciate with the Stack
284 Tags []string `json:"-"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700285}
286
287// ToStackUpdateMap casts a CreateOpts struct to a map.
288func (opts UpdateOpts) ToStackUpdateMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -0500289 b, err := gophercloud.BuildRequestBody(opts, "")
290 if 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.Parse(); err != nil {
295 return nil, err
296 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500297
Jon Perrittfea90732016-03-15 02:57:05 -0500298 if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
299 return nil, err
300 }
301 opts.TemplateOpts.fixFileRefs()
302 b["template"] = string(opts.TemplateOpts.Bin)
303
304 files := make(map[string]string)
305 for k, v := range opts.TemplateOpts.Files {
306 files[k] = v
Jon Perritt35e27e42014-12-05 11:10:46 -0700307 }
308
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500309 if opts.EnvironmentOpts != nil {
310 if err := opts.EnvironmentOpts.Parse(); err != nil {
311 return nil, err
312 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500313 if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500314 return nil, err
315 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500316 opts.EnvironmentOpts.fixFileRefs()
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500317 for k, v := range opts.EnvironmentOpts.Files {
Jon Perrittfea90732016-03-15 02:57:05 -0500318 files[k] = v
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500319 }
Jon Perrittfea90732016-03-15 02:57:05 -0500320 b["environment"] = string(opts.EnvironmentOpts.Bin)
Jon Perritt35e27e42014-12-05 11:10:46 -0700321 }
322
Jon Perrittfea90732016-03-15 02:57:05 -0500323 if len(files) > 0 {
324 b["files"] = files
Jon Perritt35e27e42014-12-05 11:10:46 -0700325 }
326
Pratik Mallya827c03e2015-09-17 00:10:47 -0500327 if opts.Tags != nil {
Jon Perrittfea90732016-03-15 02:57:05 -0500328 b["tags"] = strings.Join(opts.Tags, ",")
Pratik Mallya827c03e2015-09-17 00:10:47 -0500329 }
330
Jon Perrittfea90732016-03-15 02:57:05 -0500331 return b, nil
Jon Perritt35e27e42014-12-05 11:10:46 -0700332}
333
334// Update accepts an UpdateOpts struct and updates an existing stack using the values
335// provided.
336func Update(c *gophercloud.ServiceClient, stackName, stackID string, opts UpdateOptsBuilder) UpdateResult {
Jon Perrittfea90732016-03-15 02:57:05 -0500337 var r UpdateResult
338 b, err := opts.ToStackUpdateMap()
Jon Perritt35e27e42014-12-05 11:10:46 -0700339 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -0500340 r.Err = err
341 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700342 }
Jon Perrittfea90732016-03-15 02:57:05 -0500343 _, r.Err = c.Put(updateURL(c, stackName, stackID), b, nil, nil)
344 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700345}
346
347// Delete deletes a stack based on the stack name and stack ID.
348func Delete(c *gophercloud.ServiceClient, stackName, stackID string) DeleteResult {
Jon Perrittfea90732016-03-15 02:57:05 -0500349 var r DeleteResult
350 _, r.Err = c.Delete(deleteURL(c, stackName, stackID), nil)
351 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700352}
353
354// PreviewOptsBuilder is the interface options structs have to satisfy in order
355// to be used in the Preview operation in this package.
356type PreviewOptsBuilder interface {
357 ToStackPreviewMap() (map[string]interface{}, error)
358}
359
360// PreviewOpts contains the common options struct used in this package's Preview
361// operation.
362type PreviewOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -0500363 // The name of the stack. It must start with an alphabetic character.
364 Name string `json:"stack_name" required:"true"`
365 // The timeout for stack creation in minutes.
366 Timeout int `json:"timeout_mins" required:"true"`
367 // A structure that contains either the template file or url. Call the
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500368 // associated methods to extract the information relevant to send in a create request.
Jon Perrittfea90732016-03-15 02:57:05 -0500369 TemplateOpts *Template `json:"-" required:"true"`
370 // Enables or disables deletion of all stack resources when a stack
Jon Perritt37f97742015-02-04 18:55:05 -0700371 // creation fails. Default is true, meaning all resources are not deleted when
372 // stack creation fails.
Jon Perrittfea90732016-03-15 02:57:05 -0500373 DisableRollback *bool `json:"disable_rollback,omitempty"`
374 // A structure that contains details for the environment of the stack.
375 EnvironmentOpts *Environment `json:"-"`
376 // User-defined parameters to pass to the template.
377 Parameters map[string]string `json:"parameters,omitempty"`
Jon Perritt35e27e42014-12-05 11:10:46 -0700378}
379
380// ToStackPreviewMap casts a PreviewOpts struct to a map.
381func (opts PreviewOpts) ToStackPreviewMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -0500382 b, err := gophercloud.BuildRequestBody(opts, "")
383 if err != nil {
Jon Perritt58611da2016-03-09 00:49:57 -0600384 return nil, err
Jon Perritt35e27e42014-12-05 11:10:46 -0700385 }
Jon Perritt35e27e42014-12-05 11:10:46 -0700386
Jon Perrittfea90732016-03-15 02:57:05 -0500387 if err := opts.TemplateOpts.Parse(); err != nil {
388 return nil, err
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500389 }
Jon Perrittfea90732016-03-15 02:57:05 -0500390
391 if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
392 return nil, err
393 }
394 opts.TemplateOpts.fixFileRefs()
395 b["template"] = string(opts.TemplateOpts.Bin)
396
397 files := make(map[string]string)
398 for k, v := range opts.TemplateOpts.Files {
399 files[k] = v
Jon Perritt35e27e42014-12-05 11:10:46 -0700400 }
401
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500402 if opts.EnvironmentOpts != nil {
403 if err := opts.EnvironmentOpts.Parse(); err != nil {
404 return nil, err
405 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500406 if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500407 return nil, err
408 }
Pratik Mallyaa979f5b2015-09-22 03:10:55 -0500409 opts.EnvironmentOpts.fixFileRefs()
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500410 for k, v := range opts.EnvironmentOpts.Files {
Jon Perrittfea90732016-03-15 02:57:05 -0500411 files[k] = v
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500412 }
Jon Perrittfea90732016-03-15 02:57:05 -0500413 b["environment"] = string(opts.EnvironmentOpts.Bin)
Jon Perritt35e27e42014-12-05 11:10:46 -0700414 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500415
Jon Perrittfea90732016-03-15 02:57:05 -0500416 if len(files) > 0 {
417 b["files"] = files
Jon Perritt35e27e42014-12-05 11:10:46 -0700418 }
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500419
Jon Perrittfea90732016-03-15 02:57:05 -0500420 return b, nil
Jon Perritt35e27e42014-12-05 11:10:46 -0700421}
422
423// Preview accepts a PreviewOptsBuilder interface and creates a preview of a stack using the values
424// provided.
425func Preview(c *gophercloud.ServiceClient, opts PreviewOptsBuilder) PreviewResult {
Jon Perrittfea90732016-03-15 02:57:05 -0500426 var r PreviewResult
427 b, err := opts.ToStackPreviewMap()
Jon Perritt35e27e42014-12-05 11:10:46 -0700428 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -0500429 r.Err = err
430 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700431 }
Jon Perrittfea90732016-03-15 02:57:05 -0500432 _, r.Err = c.Post(previewURL(c), b, &r.Body, &gophercloud.RequestOpts{
Jamie Hannaford1d27afa2015-03-24 16:20:45 +0100433 OkCodes: []int{200},
Jon Perritt35e27e42014-12-05 11:10:46 -0700434 })
Jon Perrittfea90732016-03-15 02:57:05 -0500435 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700436}
437
438// Abandon deletes the stack with the provided stackName and stackID, but leaves its
439// resources intact, and returns data describing the stack and its resources.
440func Abandon(c *gophercloud.ServiceClient, stackName, stackID string) AbandonResult {
Jon Perrittfea90732016-03-15 02:57:05 -0500441 var r AbandonResult
442 _, r.Err = c.Delete(abandonURL(c, stackName, stackID), &gophercloud.RequestOpts{
443 JSONResponse: &r.Body,
Ash Wilsondecfed72015-02-13 09:14:55 -0500444 OkCodes: []int{200},
Jon Perritt35e27e42014-12-05 11:10:46 -0700445 })
Jon Perrittfea90732016-03-15 02:57:05 -0500446 return r
Jon Perritt35e27e42014-12-05 11:10:46 -0700447}