Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 1 | package stacks |
| 2 | |
| 3 | import ( |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 4 | "strings" |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 5 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud" |
| 7 | "github.com/gophercloud/gophercloud/pagination" |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 8 | ) |
| 9 | |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 10 | // Rollback is used to specify whether or not a stack can be rolled back. |
Jon Perritt | b20ba0b | 2015-02-03 13:13:42 -0700 | [diff] [blame] | 11 | type Rollback *bool |
| 12 | |
| 13 | var ( |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 14 | disable = true |
| 15 | // Disable is used to specify that a stack cannot be rolled back. |
Jon Perritt | b20ba0b | 2015-02-03 13:13:42 -0700 | [diff] [blame] | 16 | Disable Rollback = &disable |
| 17 | enable = false |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 18 | // Enable is used to specify that a stack can be rolled back. |
| 19 | Enable Rollback = &enable |
Jon Perritt | b20ba0b | 2015-02-03 13:13:42 -0700 | [diff] [blame] | 20 | ) |
| 21 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 22 | // CreateOptsBuilder is the interface options structs have to satisfy in order |
| 23 | // to be used in the main Create operation in this package. Since many |
| 24 | // extensions decorate or modify the common logic, it is useful for them to |
| 25 | // satisfy a basic interface in order for them to be used. |
| 26 | type CreateOptsBuilder interface { |
| 27 | ToStackCreateMap() (map[string]interface{}, error) |
| 28 | } |
| 29 | |
| 30 | // CreateOpts is the common options struct used in this package's Create |
| 31 | // operation. |
| 32 | type CreateOpts struct { |
Jon Perritt | 952f3e1 | 2015-02-03 12:13:24 -0700 | [diff] [blame] | 33 | // (REQUIRED) The name of the stack. It must start with an alphabetic character. |
| 34 | Name string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 35 | // (REQUIRED) A structure that contains either the template file or url. Call the |
| 36 | // associated methods to extract the information relevant to send in a create request. |
| 37 | TemplateOpts *Template |
| 38 | // (DEPRECATED): Please use TemplateOpts for providing the template. If |
| 39 | // TemplateOpts is provided, TemplateURL will be ignored |
Jon Perritt | 952f3e1 | 2015-02-03 12:13:24 -0700 | [diff] [blame] | 40 | // (OPTIONAL; REQUIRED IF Template IS EMPTY) The URL of the template to instantiate. |
| 41 | // This value is ignored if Template is supplied inline. |
| 42 | TemplateURL string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 43 | // (DEPRECATED): Please use TemplateOpts for providing the template. If |
| 44 | // TemplateOpts is provided, Template will be ignored |
Jon Perritt | 952f3e1 | 2015-02-03 12:13:24 -0700 | [diff] [blame] | 45 | // (OPTIONAL; REQUIRED IF TemplateURL IS EMPTY) A template to instantiate. The value |
| 46 | // is a stringified version of the JSON/YAML template. Since the template will likely |
| 47 | // be located in a file, one way to set this variable is by using ioutil.ReadFile: |
| 48 | // import "io/ioutil" |
| 49 | // var opts stacks.CreateOpts |
| 50 | // b, err := ioutil.ReadFile("path/to/you/template/file.json") |
| 51 | // if err != nil { |
| 52 | // // handle error... |
| 53 | // } |
| 54 | // opts.Template = string(b) |
| 55 | Template string |
| 56 | // (OPTIONAL) Enables or disables deletion of all stack resources when a stack |
| 57 | // creation fails. Default is true, meaning all resources are not deleted when |
| 58 | // stack creation fails. |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 59 | DisableRollback Rollback |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 60 | // (OPTIONAL) A structure that contains details for the environment of the stack. |
| 61 | EnvironmentOpts *Environment |
| 62 | // (DEPRECATED): Please use EnvironmentOpts to provide Environment data |
Jon Perritt | 952f3e1 | 2015-02-03 12:13:24 -0700 | [diff] [blame] | 63 | // (OPTIONAL) A stringified JSON environment for the stack. |
| 64 | Environment string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 65 | // (DEPRECATED): Files is automatically determined |
| 66 | // by parsing the template and environment passed as TemplateOpts and |
| 67 | // EnvironmentOpts respectively. |
Jon Perritt | 952f3e1 | 2015-02-03 12:13:24 -0700 | [diff] [blame] | 68 | // (OPTIONAL) A map that maps file names to file contents. It can also be used |
| 69 | // to pass provider template contents. Example: |
| 70 | // Files: `{"myfile": "#!/bin/bash\necho 'Hello world' > /root/testfile.txt"}` |
| 71 | Files map[string]interface{} |
| 72 | // (OPTIONAL) User-defined parameters to pass to the template. |
| 73 | Parameters map[string]string |
Jon Perritt | 9170989 | 2015-02-11 17:53:43 -0700 | [diff] [blame] | 74 | // (OPTIONAL) The timeout for stack creation in minutes. |
| 75 | Timeout int |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 76 | // (OPTIONAL) A list of tags to assosciate with the Stack |
| 77 | Tags []string |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // ToStackCreateMap casts a CreateOpts struct to a map. |
| 81 | func (opts CreateOpts) ToStackCreateMap() (map[string]interface{}, error) { |
| 82 | s := make(map[string]interface{}) |
| 83 | |
| 84 | if opts.Name == "" { |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame] | 85 | err := gophercloud.ErrMissingInput{} |
| 86 | err.Argument = "stacks.CreateOpts.Name" |
| 87 | return nil, err |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 88 | } |
| 89 | s["stack_name"] = opts.Name |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 90 | Files := make(map[string]string) |
| 91 | if opts.TemplateOpts == nil { |
| 92 | if opts.Template != "" { |
| 93 | s["template"] = opts.Template |
| 94 | } else if opts.TemplateURL != "" { |
| 95 | s["template_url"] = opts.TemplateURL |
| 96 | } else { |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame] | 97 | err := gophercloud.ErrMissingInput{} |
| 98 | err.Argument = "stacks.CreateOpts.Template/stacks.CreateOpts.TemplateURL" |
| 99 | err.Info = "Either Template or TemplateURL must be provided" |
| 100 | return nil, err |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 101 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 102 | } else { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 103 | if err := opts.TemplateOpts.Parse(); err != nil { |
| 104 | return nil, err |
| 105 | } |
| 106 | |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 107 | if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 108 | return nil, err |
| 109 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 110 | opts.TemplateOpts.fixFileRefs() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 111 | s["template"] = string(opts.TemplateOpts.Bin) |
| 112 | |
| 113 | for k, v := range opts.TemplateOpts.Files { |
| 114 | Files[k] = v |
| 115 | } |
| 116 | } |
| 117 | if opts.DisableRollback != nil { |
| 118 | s["disable_rollback"] = &opts.DisableRollback |
| 119 | } |
| 120 | |
| 121 | if opts.EnvironmentOpts != nil { |
| 122 | if err := opts.EnvironmentOpts.Parse(); err != nil { |
| 123 | return nil, err |
| 124 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 125 | if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 126 | return nil, err |
| 127 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 128 | opts.EnvironmentOpts.fixFileRefs() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 129 | for k, v := range opts.EnvironmentOpts.Files { |
| 130 | Files[k] = v |
| 131 | } |
| 132 | s["environment"] = string(opts.EnvironmentOpts.Bin) |
| 133 | } else if opts.Environment != "" { |
| 134 | s["environment"] = opts.Environment |
| 135 | } |
| 136 | |
| 137 | if opts.Files != nil { |
| 138 | s["files"] = opts.Files |
| 139 | } else { |
| 140 | s["files"] = Files |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | if opts.DisableRollback != nil { |
| 144 | s["disable_rollback"] = &opts.DisableRollback |
| 145 | } |
| 146 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 147 | if opts.Parameters != nil { |
| 148 | s["parameters"] = opts.Parameters |
| 149 | } |
| 150 | |
Jon Perritt | 9170989 | 2015-02-11 17:53:43 -0700 | [diff] [blame] | 151 | if opts.Timeout != 0 { |
| 152 | s["timeout_mins"] = opts.Timeout |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 155 | if opts.Tags != nil { |
| 156 | s["tags"] = strings.Join(opts.Tags, ",") |
| 157 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 158 | return s, nil |
| 159 | } |
| 160 | |
| 161 | // Create accepts a CreateOpts struct and creates a new stack using the values |
| 162 | // provided. |
| 163 | func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult { |
| 164 | var res CreateResult |
| 165 | |
| 166 | reqBody, err := opts.ToStackCreateMap() |
| 167 | if err != nil { |
| 168 | res.Err = err |
| 169 | return res |
| 170 | } |
| 171 | |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 172 | _, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil) |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 173 | return res |
| 174 | } |
| 175 | |
| 176 | // AdoptOptsBuilder is the interface options structs have to satisfy in order |
| 177 | // to be used in the Adopt function in this package. Since many |
| 178 | // extensions decorate or modify the common logic, it is useful for them to |
| 179 | // satisfy a basic interface in order for them to be used. |
| 180 | type AdoptOptsBuilder interface { |
| 181 | ToStackAdoptMap() (map[string]interface{}, error) |
| 182 | } |
| 183 | |
| 184 | // AdoptOpts is the common options struct used in this package's Adopt |
| 185 | // operation. |
| 186 | type AdoptOpts struct { |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 187 | // (REQUIRED) Existing resources data represented as a string to add to the |
| 188 | // new stack. Data returned by Abandon could be provided as AdoptsStackData. |
| 189 | AdoptStackData string |
| 190 | // (REQUIRED) The name of the stack. It must start with an alphabetic character. |
| 191 | Name string |
| 192 | // (REQUIRED) The timeout for stack creation in minutes. |
| 193 | Timeout int |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 194 | // (REQUIRED) A structure that contains either the template file or url. Call the |
| 195 | // associated methods to extract the information relevant to send in a create request. |
| 196 | TemplateOpts *Template |
| 197 | // (DEPRECATED): Please use TemplateOpts for providing the template. If |
| 198 | // TemplateOpts is provided, TemplateURL will be ignored |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 199 | // (OPTIONAL; REQUIRED IF Template IS EMPTY) The URL of the template to instantiate. |
| 200 | // This value is ignored if Template is supplied inline. |
| 201 | TemplateURL string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 202 | // (DEPRECATED): Please use TemplateOpts for providing the template. If |
| 203 | // TemplateOpts is provided, Template will be ignored |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 204 | // (OPTIONAL; REQUIRED IF TemplateURL IS EMPTY) A template to instantiate. The value |
| 205 | // is a stringified version of the JSON/YAML template. Since the template will likely |
| 206 | // be located in a file, one way to set this variable is by using ioutil.ReadFile: |
| 207 | // import "io/ioutil" |
| 208 | // var opts stacks.CreateOpts |
| 209 | // b, err := ioutil.ReadFile("path/to/you/template/file.json") |
| 210 | // if err != nil { |
| 211 | // // handle error... |
| 212 | // } |
| 213 | // opts.Template = string(b) |
| 214 | Template string |
| 215 | // (OPTIONAL) Enables or disables deletion of all stack resources when a stack |
| 216 | // creation fails. Default is true, meaning all resources are not deleted when |
| 217 | // stack creation fails. |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 218 | DisableRollback Rollback |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 219 | // (OPTIONAL) A structure that contains details for the environment of the stack. |
| 220 | EnvironmentOpts *Environment |
| 221 | // (DEPRECATED): Please use EnvironmentOpts to provide Environment data |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 222 | // (OPTIONAL) A stringified JSON environment for the stack. |
| 223 | Environment string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 224 | // (DEPRECATED): Files is automatically determined |
| 225 | // by parsing the template and environment passed as TemplateOpts and |
| 226 | // EnvironmentOpts respectively. |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 227 | // (OPTIONAL) A map that maps file names to file contents. It can also be used |
| 228 | // to pass provider template contents. Example: |
| 229 | // Files: `{"myfile": "#!/bin/bash\necho 'Hello world' > /root/testfile.txt"}` |
| 230 | Files map[string]interface{} |
| 231 | // (OPTIONAL) User-defined parameters to pass to the template. |
| 232 | Parameters map[string]string |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | // ToStackAdoptMap casts a CreateOpts struct to a map. |
| 236 | func (opts AdoptOpts) ToStackAdoptMap() (map[string]interface{}, error) { |
| 237 | s := make(map[string]interface{}) |
| 238 | |
| 239 | if opts.Name == "" { |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame] | 240 | err := gophercloud.ErrMissingInput{} |
| 241 | err.Argument = "stacks.AdoptOpts.Name" |
| 242 | return nil, err |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 243 | } |
| 244 | s["stack_name"] = opts.Name |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 245 | Files := make(map[string]string) |
Pratik Mallya | 7e6b7b9 | 2015-09-30 19:03:08 -0500 | [diff] [blame] | 246 | if opts.AdoptStackData != "" { |
| 247 | s["adopt_stack_data"] = opts.AdoptStackData |
| 248 | } else if opts.TemplateOpts == nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 249 | if opts.Template != "" { |
| 250 | s["template"] = opts.Template |
| 251 | } else if opts.TemplateURL != "" { |
| 252 | s["template_url"] = opts.TemplateURL |
| 253 | } else { |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame] | 254 | err := gophercloud.ErrMissingInput{} |
| 255 | err.Argument = "stacks.AdoptOpts" |
| 256 | err.Info = "One of AdoptStackData, Template, TemplateURL or TemplateOpts must be provided" |
| 257 | return nil, err |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 258 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 259 | } else { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 260 | if err := opts.TemplateOpts.Parse(); err != nil { |
| 261 | return nil, err |
| 262 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 263 | |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 264 | if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 265 | return nil, err |
| 266 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 267 | opts.TemplateOpts.fixFileRefs() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 268 | s["template"] = string(opts.TemplateOpts.Bin) |
| 269 | |
| 270 | for k, v := range opts.TemplateOpts.Files { |
| 271 | Files[k] = v |
| 272 | } |
| 273 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 274 | |
| 275 | if opts.DisableRollback != nil { |
| 276 | s["disable_rollback"] = &opts.DisableRollback |
| 277 | } |
| 278 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 279 | if opts.EnvironmentOpts != nil { |
| 280 | if err := opts.EnvironmentOpts.Parse(); err != nil { |
| 281 | return nil, err |
| 282 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 283 | if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 284 | return nil, err |
| 285 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 286 | opts.EnvironmentOpts.fixFileRefs() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 287 | for k, v := range opts.EnvironmentOpts.Files { |
| 288 | Files[k] = v |
| 289 | } |
| 290 | s["environment"] = string(opts.EnvironmentOpts.Bin) |
| 291 | } else if opts.Environment != "" { |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 292 | s["environment"] = opts.Environment |
| 293 | } |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 294 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 295 | if opts.Files != nil { |
| 296 | s["files"] = opts.Files |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 297 | } else { |
| 298 | s["files"] = Files |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 299 | } |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 300 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 301 | if opts.Parameters != nil { |
| 302 | s["parameters"] = opts.Parameters |
| 303 | } |
| 304 | |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 305 | if opts.Timeout != 0 { |
| 306 | s["timeout"] = opts.Timeout |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 307 | } |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 308 | s["timeout_mins"] = opts.Timeout |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 309 | |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 310 | return s, nil |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | // Adopt accepts an AdoptOpts struct and creates a new stack using the resources |
| 314 | // from another stack. |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 315 | func Adopt(c *gophercloud.ServiceClient, opts AdoptOptsBuilder) AdoptResult { |
| 316 | var res AdoptResult |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 317 | |
| 318 | reqBody, err := opts.ToStackAdoptMap() |
| 319 | if err != nil { |
| 320 | res.Err = err |
| 321 | return res |
| 322 | } |
| 323 | |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 324 | _, res.Err = c.Post(adoptURL(c), reqBody, &res.Body, nil) |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 325 | return res |
| 326 | } |
| 327 | |
| 328 | // SortDir is a type for specifying in which direction to sort a list of stacks. |
| 329 | type SortDir string |
| 330 | |
| 331 | // SortKey is a type for specifying by which key to sort a list of stacks. |
| 332 | type SortKey string |
| 333 | |
| 334 | var ( |
| 335 | // SortAsc is used to sort a list of stacks in ascending order. |
| 336 | SortAsc SortDir = "asc" |
| 337 | // SortDesc is used to sort a list of stacks in descending order. |
| 338 | SortDesc SortDir = "desc" |
| 339 | // SortName is used to sort a list of stacks by name. |
| 340 | SortName SortKey = "name" |
| 341 | // SortStatus is used to sort a list of stacks by status. |
| 342 | SortStatus SortKey = "status" |
| 343 | // SortCreatedAt is used to sort a list of stacks by date created. |
| 344 | SortCreatedAt SortKey = "created_at" |
| 345 | // SortUpdatedAt is used to sort a list of stacks by date updated. |
| 346 | SortUpdatedAt SortKey = "updated_at" |
| 347 | ) |
| 348 | |
| 349 | // ListOptsBuilder allows extensions to add additional parameters to the |
| 350 | // List request. |
| 351 | type ListOptsBuilder interface { |
| 352 | ToStackListQuery() (string, error) |
| 353 | } |
| 354 | |
| 355 | // ListOpts allows the filtering and sorting of paginated collections through |
| 356 | // the API. Filtering is achieved by passing in struct field values that map to |
| 357 | // the network attributes you want to see returned. SortKey allows you to sort |
| 358 | // by a particular network attribute. SortDir sets the direction, and is either |
| 359 | // `asc' or `desc'. Marker and Limit are used for pagination. |
| 360 | type ListOpts struct { |
| 361 | Status string `q:"status"` |
| 362 | Name string `q:"name"` |
| 363 | Marker string `q:"marker"` |
| 364 | Limit int `q:"limit"` |
| 365 | SortKey SortKey `q:"sort_keys"` |
| 366 | SortDir SortDir `q:"sort_dir"` |
| 367 | } |
| 368 | |
| 369 | // ToStackListQuery formats a ListOpts into a query string. |
| 370 | func (opts ListOpts) ToStackListQuery() (string, error) { |
| 371 | q, err := gophercloud.BuildQueryString(opts) |
| 372 | if err != nil { |
| 373 | return "", err |
| 374 | } |
| 375 | return q.String(), nil |
| 376 | } |
| 377 | |
| 378 | // List returns a Pager which allows you to iterate over a collection of |
| 379 | // stacks. It accepts a ListOpts struct, which allows you to filter and sort |
| 380 | // the returned collection for greater efficiency. |
| 381 | func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { |
| 382 | url := listURL(c) |
| 383 | if opts != nil { |
| 384 | query, err := opts.ToStackListQuery() |
| 385 | if err != nil { |
| 386 | return pagination.Pager{Err: err} |
| 387 | } |
| 388 | url += query |
| 389 | } |
| 390 | |
| 391 | createPage := func(r pagination.PageResult) pagination.Page { |
| 392 | return StackPage{pagination.SinglePageBase(r)} |
| 393 | } |
| 394 | return pagination.NewPager(c, url, createPage) |
| 395 | } |
| 396 | |
| 397 | // Get retreives a stack based on the stack name and stack ID. |
| 398 | func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult { |
| 399 | var res GetResult |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 400 | _, res.Err = c.Get(getURL(c, stackName, stackID), &res.Body, nil) |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 401 | return res |
| 402 | } |
| 403 | |
| 404 | // UpdateOptsBuilder is the interface options structs have to satisfy in order |
| 405 | // to be used in the Update operation in this package. |
| 406 | type UpdateOptsBuilder interface { |
| 407 | ToStackUpdateMap() (map[string]interface{}, error) |
| 408 | } |
| 409 | |
| 410 | // UpdateOpts contains the common options struct used in this package's Update |
| 411 | // operation. |
| 412 | type UpdateOpts struct { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 413 | // (REQUIRED) A structure that contains either the template file or url. Call the |
| 414 | // associated methods to extract the information relevant to send in a create request. |
| 415 | TemplateOpts *Template |
| 416 | // (DEPRECATED): Please use TemplateOpts for providing the template. If |
| 417 | // TemplateOpts is provided, TemplateURL will be ignored |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 418 | // (OPTIONAL; REQUIRED IF Template IS EMPTY) The URL of the template to instantiate. |
| 419 | // This value is ignored if Template is supplied inline. |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 420 | TemplateURL string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 421 | // (DEPRECATED): Please use TemplateOpts for providing the template. If |
| 422 | // TemplateOpts is provided, Template will be ignored |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 423 | // (OPTIONAL; REQUIRED IF TemplateURL IS EMPTY) A template to instantiate. The value |
| 424 | // is a stringified version of the JSON/YAML template. Since the template will likely |
| 425 | // be located in a file, one way to set this variable is by using ioutil.ReadFile: |
| 426 | // import "io/ioutil" |
| 427 | // var opts stacks.CreateOpts |
| 428 | // b, err := ioutil.ReadFile("path/to/you/template/file.json") |
| 429 | // if err != nil { |
| 430 | // // handle error... |
| 431 | // } |
| 432 | // opts.Template = string(b) |
| 433 | Template string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 434 | // (OPTIONAL) A structure that contains details for the environment of the stack. |
| 435 | EnvironmentOpts *Environment |
| 436 | // (DEPRECATED): Please use EnvironmentOpts to provide Environment data |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 437 | // (OPTIONAL) A stringified JSON environment for the stack. |
| 438 | Environment string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 439 | // (DEPRECATED): Files is automatically determined |
| 440 | // by parsing the template and environment passed as TemplateOpts and |
| 441 | // EnvironmentOpts respectively. |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 442 | // (OPTIONAL) A map that maps file names to file contents. It can also be used |
| 443 | // to pass provider template contents. Example: |
| 444 | // Files: `{"myfile": "#!/bin/bash\necho 'Hello world' > /root/testfile.txt"}` |
| 445 | Files map[string]interface{} |
| 446 | // (OPTIONAL) User-defined parameters to pass to the template. |
| 447 | Parameters map[string]string |
Jon Perritt | 5110718 | 2015-02-11 18:18:19 -0700 | [diff] [blame] | 448 | // (OPTIONAL) The timeout for stack creation in minutes. |
| 449 | Timeout int |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 450 | // (OPTIONAL) A list of tags to assosciate with the Stack |
| 451 | Tags []string |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | // ToStackUpdateMap casts a CreateOpts struct to a map. |
| 455 | func (opts UpdateOpts) ToStackUpdateMap() (map[string]interface{}, error) { |
| 456 | s := make(map[string]interface{}) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 457 | Files := make(map[string]string) |
| 458 | if opts.TemplateOpts == nil { |
| 459 | if opts.Template != "" { |
| 460 | s["template"] = opts.Template |
| 461 | } else if opts.TemplateURL != "" { |
| 462 | s["template_url"] = opts.TemplateURL |
| 463 | } else { |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame] | 464 | err := gophercloud.ErrMissingInput{} |
| 465 | err.Argument = "stacks.UpdateOpts" |
| 466 | err.Info = "Either Template or TemplateURL must be provided" |
| 467 | return nil, err |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 468 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 469 | } else { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 470 | if err := opts.TemplateOpts.Parse(); err != nil { |
| 471 | return nil, err |
| 472 | } |
| 473 | |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 474 | if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 475 | return nil, err |
| 476 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 477 | opts.TemplateOpts.fixFileRefs() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 478 | s["template"] = string(opts.TemplateOpts.Bin) |
| 479 | |
| 480 | for k, v := range opts.TemplateOpts.Files { |
| 481 | Files[k] = v |
| 482 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 485 | if opts.EnvironmentOpts != nil { |
| 486 | if err := opts.EnvironmentOpts.Parse(); err != nil { |
| 487 | return nil, err |
| 488 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 489 | if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 490 | return nil, err |
| 491 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 492 | opts.EnvironmentOpts.fixFileRefs() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 493 | for k, v := range opts.EnvironmentOpts.Files { |
| 494 | Files[k] = v |
| 495 | } |
| 496 | s["environment"] = string(opts.EnvironmentOpts.Bin) |
| 497 | } else if opts.Environment != "" { |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 498 | s["environment"] = opts.Environment |
| 499 | } |
| 500 | |
| 501 | if opts.Files != nil { |
| 502 | s["files"] = opts.Files |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 503 | } else { |
| 504 | s["files"] = Files |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | if opts.Parameters != nil { |
| 508 | s["parameters"] = opts.Parameters |
| 509 | } |
| 510 | |
| 511 | if opts.Timeout != 0 { |
| 512 | s["timeout_mins"] = opts.Timeout |
| 513 | } |
| 514 | |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 515 | if opts.Tags != nil { |
| 516 | s["tags"] = strings.Join(opts.Tags, ",") |
| 517 | } |
| 518 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 519 | return s, nil |
| 520 | } |
| 521 | |
| 522 | // Update accepts an UpdateOpts struct and updates an existing stack using the values |
| 523 | // provided. |
| 524 | func Update(c *gophercloud.ServiceClient, stackName, stackID string, opts UpdateOptsBuilder) UpdateResult { |
| 525 | var res UpdateResult |
| 526 | |
| 527 | reqBody, err := opts.ToStackUpdateMap() |
| 528 | if err != nil { |
| 529 | res.Err = err |
| 530 | return res |
| 531 | } |
| 532 | |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 533 | _, res.Err = c.Put(updateURL(c, stackName, stackID), reqBody, nil, nil) |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 534 | return res |
| 535 | } |
| 536 | |
| 537 | // Delete deletes a stack based on the stack name and stack ID. |
| 538 | func Delete(c *gophercloud.ServiceClient, stackName, stackID string) DeleteResult { |
| 539 | var res DeleteResult |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 540 | _, res.Err = c.Delete(deleteURL(c, stackName, stackID), nil) |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 541 | return res |
| 542 | } |
| 543 | |
| 544 | // PreviewOptsBuilder is the interface options structs have to satisfy in order |
| 545 | // to be used in the Preview operation in this package. |
| 546 | type PreviewOptsBuilder interface { |
| 547 | ToStackPreviewMap() (map[string]interface{}, error) |
| 548 | } |
| 549 | |
| 550 | // PreviewOpts contains the common options struct used in this package's Preview |
| 551 | // operation. |
| 552 | type PreviewOpts struct { |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 553 | // (REQUIRED) The name of the stack. It must start with an alphabetic character. |
| 554 | Name string |
| 555 | // (REQUIRED) The timeout for stack creation in minutes. |
| 556 | Timeout int |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 557 | // (REQUIRED) A structure that contains either the template file or url. Call the |
| 558 | // associated methods to extract the information relevant to send in a create request. |
| 559 | TemplateOpts *Template |
| 560 | // (DEPRECATED): Please use TemplateOpts for providing the template. If |
| 561 | // TemplateOpts is provided, TemplateURL will be ignored |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 562 | // (OPTIONAL; REQUIRED IF Template IS EMPTY) The URL of the template to instantiate. |
| 563 | // This value is ignored if Template is supplied inline. |
| 564 | TemplateURL string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 565 | // (DEPRECATED): Please use TemplateOpts for providing the template. If |
| 566 | // TemplateOpts is provided, Template will be ignored |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 567 | // (OPTIONAL; REQUIRED IF TemplateURL IS EMPTY) A template to instantiate. The value |
| 568 | // is a stringified version of the JSON/YAML template. Since the template will likely |
| 569 | // be located in a file, one way to set this variable is by using ioutil.ReadFile: |
| 570 | // import "io/ioutil" |
| 571 | // var opts stacks.CreateOpts |
| 572 | // b, err := ioutil.ReadFile("path/to/you/template/file.json") |
| 573 | // if err != nil { |
| 574 | // // handle error... |
| 575 | // } |
| 576 | // opts.Template = string(b) |
| 577 | Template string |
| 578 | // (OPTIONAL) Enables or disables deletion of all stack resources when a stack |
| 579 | // creation fails. Default is true, meaning all resources are not deleted when |
| 580 | // stack creation fails. |
| 581 | DisableRollback Rollback |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 582 | // (OPTIONAL) A structure that contains details for the environment of the stack. |
| 583 | EnvironmentOpts *Environment |
| 584 | // (DEPRECATED): Please use EnvironmentOpts to provide Environment data |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 585 | // (OPTIONAL) A stringified JSON environment for the stack. |
| 586 | Environment string |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 587 | // (DEPRECATED): Files is automatically determined |
| 588 | // by parsing the template and environment passed as TemplateOpts and |
| 589 | // EnvironmentOpts respectively. |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 590 | // (OPTIONAL) A map that maps file names to file contents. It can also be used |
| 591 | // to pass provider template contents. Example: |
| 592 | // Files: `{"myfile": "#!/bin/bash\necho 'Hello world' > /root/testfile.txt"}` |
| 593 | Files map[string]interface{} |
| 594 | // (OPTIONAL) User-defined parameters to pass to the template. |
| 595 | Parameters map[string]string |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | // ToStackPreviewMap casts a PreviewOpts struct to a map. |
| 599 | func (opts PreviewOpts) ToStackPreviewMap() (map[string]interface{}, error) { |
| 600 | s := make(map[string]interface{}) |
| 601 | |
| 602 | if opts.Name == "" { |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame] | 603 | err := gophercloud.ErrMissingInput{} |
| 604 | err.Argument = "stacks.PreviewOpts.Name" |
| 605 | return nil, err |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 606 | } |
| 607 | s["stack_name"] = opts.Name |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 608 | Files := make(map[string]string) |
| 609 | if opts.TemplateOpts == nil { |
| 610 | if opts.Template != "" { |
| 611 | s["template"] = opts.Template |
| 612 | } else if opts.TemplateURL != "" { |
| 613 | s["template_url"] = opts.TemplateURL |
| 614 | } else { |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame] | 615 | err := gophercloud.ErrMissingInput{} |
| 616 | err.Argument = "stacks.PreviewOpts" |
| 617 | err.Info = "Either Template or TemplateURL must be provided" |
| 618 | return nil, err |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 619 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 620 | } else { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 621 | if err := opts.TemplateOpts.Parse(); err != nil { |
| 622 | return nil, err |
| 623 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 624 | |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 625 | if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 626 | return nil, err |
| 627 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 628 | opts.TemplateOpts.fixFileRefs() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 629 | s["template"] = string(opts.TemplateOpts.Bin) |
| 630 | |
| 631 | for k, v := range opts.TemplateOpts.Files { |
| 632 | Files[k] = v |
| 633 | } |
| 634 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 635 | if opts.DisableRollback != nil { |
| 636 | s["disable_rollback"] = &opts.DisableRollback |
| 637 | } |
| 638 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 639 | if opts.EnvironmentOpts != nil { |
| 640 | if err := opts.EnvironmentOpts.Parse(); err != nil { |
| 641 | return nil, err |
| 642 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 643 | if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil { |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 644 | return nil, err |
| 645 | } |
Pratik Mallya | a979f5b | 2015-09-22 03:10:55 -0500 | [diff] [blame] | 646 | opts.EnvironmentOpts.fixFileRefs() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 647 | for k, v := range opts.EnvironmentOpts.Files { |
| 648 | Files[k] = v |
| 649 | } |
| 650 | s["environment"] = string(opts.EnvironmentOpts.Bin) |
| 651 | } else if opts.Environment != "" { |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 652 | s["environment"] = opts.Environment |
| 653 | } |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 654 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 655 | if opts.Files != nil { |
| 656 | s["files"] = opts.Files |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 657 | } else { |
| 658 | s["files"] = Files |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 659 | } |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 660 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 661 | if opts.Parameters != nil { |
| 662 | s["parameters"] = opts.Parameters |
| 663 | } |
| 664 | |
| 665 | if opts.Timeout != 0 { |
| 666 | s["timeout_mins"] = opts.Timeout |
| 667 | } |
| 668 | |
| 669 | return s, nil |
| 670 | } |
| 671 | |
| 672 | // Preview accepts a PreviewOptsBuilder interface and creates a preview of a stack using the values |
| 673 | // provided. |
| 674 | func Preview(c *gophercloud.ServiceClient, opts PreviewOptsBuilder) PreviewResult { |
| 675 | var res PreviewResult |
| 676 | |
| 677 | reqBody, err := opts.ToStackPreviewMap() |
| 678 | if err != nil { |
| 679 | res.Err = err |
| 680 | return res |
| 681 | } |
| 682 | |
| 683 | // Send request to API |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 684 | _, res.Err = c.Post(previewURL(c), reqBody, &res.Body, &gophercloud.RequestOpts{ |
| 685 | OkCodes: []int{200}, |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 686 | }) |
| 687 | return res |
| 688 | } |
| 689 | |
| 690 | // Abandon deletes the stack with the provided stackName and stackID, but leaves its |
| 691 | // resources intact, and returns data describing the stack and its resources. |
| 692 | func Abandon(c *gophercloud.ServiceClient, stackName, stackID string) AbandonResult { |
| 693 | var res AbandonResult |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 694 | _, res.Err = c.Delete(abandonURL(c, stackName, stackID), &gophercloud.RequestOpts{ |
Ash Wilson | decfed7 | 2015-02-13 09:14:55 -0500 | [diff] [blame] | 695 | JSONResponse: &res.Body, |
| 696 | OkCodes: []int{200}, |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 697 | }) |
| 698 | return res |
| 699 | } |