Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 1 | package stacktemplates |
| 2 | |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame] | 3 | import "github.com/gophercloud/gophercloud" |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 4 | |
| 5 | // Get retreives data for the given stack template. |
| 6 | func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 7 | var r GetResult |
| 8 | _, r.Err = c.Get(getURL(c, stackName, stackID), &r.Body, nil) |
| 9 | return r |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | // ValidateOptsBuilder describes struct types that can be accepted by the Validate call. |
| 13 | // The ValidateOpts struct in this package does. |
| 14 | type ValidateOptsBuilder interface { |
| 15 | ToStackTemplateValidateMap() (map[string]interface{}, error) |
| 16 | } |
| 17 | |
| 18 | // ValidateOpts specifies the template validation parameters. |
| 19 | type ValidateOpts struct { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 20 | Template string `json:"template" or:"TemplateURL"` |
| 21 | TemplateURL string `json:"template_url" or:"Template"` |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | // ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts. |
| 25 | func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 26 | return gophercloud.BuildRequestBody(opts, "") |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | // Validate validates the given stack template. |
| 30 | func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) ValidateResult { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 31 | var r ValidateResult |
| 32 | b, err := opts.ToStackTemplateValidateMap() |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 33 | if err != nil { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 34 | r.Err = err |
| 35 | return r |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 36 | } |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 37 | _, r.Err = c.Post(validateURL(c), b, &r.Body, &gophercloud.RequestOpts{ |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 38 | OkCodes: []int{200}, |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 39 | }) |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 40 | return r |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 41 | } |