blob: 9337cae639c19c239c515681ba87812e73089742 [file] [log] [blame]
Jon Perrittf799b942015-02-09 11:23:28 -07001package stacktemplates
2
Jon Perritt58611da2016-03-09 00:49:57 -06003import "github.com/gophercloud/gophercloud"
Jon Perrittf799b942015-02-09 11:23:28 -07004
5// Get retreives data for the given stack template.
6func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult {
Jon Perrittfea90732016-03-15 02:57:05 -05007 var r GetResult
8 _, r.Err = c.Get(getURL(c, stackName, stackID), &r.Body, nil)
9 return r
Jon Perrittf799b942015-02-09 11:23:28 -070010}
11
12// ValidateOptsBuilder describes struct types that can be accepted by the Validate call.
13// The ValidateOpts struct in this package does.
14type ValidateOptsBuilder interface {
15 ToStackTemplateValidateMap() (map[string]interface{}, error)
16}
17
18// ValidateOpts specifies the template validation parameters.
19type ValidateOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -050020 Template string `json:"template" or:"TemplateURL"`
21 TemplateURL string `json:"template_url" or:"Template"`
Jon Perrittf799b942015-02-09 11:23:28 -070022}
23
24// ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts.
25func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -050026 return gophercloud.BuildRequestBody(opts, "")
Jon Perrittf799b942015-02-09 11:23:28 -070027}
28
29// Validate validates the given stack template.
30func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) ValidateResult {
Jon Perrittfea90732016-03-15 02:57:05 -050031 var r ValidateResult
32 b, err := opts.ToStackTemplateValidateMap()
Jon Perrittf799b942015-02-09 11:23:28 -070033 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -050034 r.Err = err
35 return r
Jon Perrittf799b942015-02-09 11:23:28 -070036 }
Jon Perrittfea90732016-03-15 02:57:05 -050037 _, r.Err = c.Post(validateURL(c), b, &r.Body, &gophercloud.RequestOpts{
Jamie Hannaford1d27afa2015-03-24 16:20:45 +010038 OkCodes: []int{200},
Jon Perrittf799b942015-02-09 11:23:28 -070039 })
Jon Perrittfea90732016-03-15 02:57:05 -050040 return r
Jon Perrittf799b942015-02-09 11:23:28 -070041}