blob: 57f990f2e6bf4990a7c6660cd2a4bc2086eae697 [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.
Jon Perritt3860b512016-03-29 12:01:48 -05006func Get(c *gophercloud.ServiceClient, stackName, stackID string) (r GetResult) {
Jon Perrittfea90732016-03-15 02:57:05 -05007 _, r.Err = c.Get(getURL(c, stackName, stackID), &r.Body, nil)
Jon Perrittf799b942015-02-09 11:23:28 -07008}
9
10// ValidateOptsBuilder describes struct types that can be accepted by the Validate call.
11// The ValidateOpts struct in this package does.
12type ValidateOptsBuilder interface {
13 ToStackTemplateValidateMap() (map[string]interface{}, error)
14}
15
16// ValidateOpts specifies the template validation parameters.
17type ValidateOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -050018 Template string `json:"template" or:"TemplateURL"`
19 TemplateURL string `json:"template_url" or:"Template"`
Jon Perrittf799b942015-02-09 11:23:28 -070020}
21
22// ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts.
23func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -050024 return gophercloud.BuildRequestBody(opts, "")
Jon Perrittf799b942015-02-09 11:23:28 -070025}
26
27// Validate validates the given stack template.
Jon Perritt3860b512016-03-29 12:01:48 -050028func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) (r ValidateResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050029 b, err := opts.ToStackTemplateValidateMap()
Jon Perrittf799b942015-02-09 11:23:28 -070030 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -050031 r.Err = err
Jon Perritt3860b512016-03-29 12:01:48 -050032 return
Jon Perrittf799b942015-02-09 11:23:28 -070033 }
Jon Perrittfea90732016-03-15 02:57:05 -050034 _, r.Err = c.Post(validateURL(c), b, &r.Body, &gophercloud.RequestOpts{
Jamie Hannaford1d27afa2015-03-24 16:20:45 +010035 OkCodes: []int{200},
Jon Perrittf799b942015-02-09 11:23:28 -070036 })
Jon Perrittf799b942015-02-09 11:23:28 -070037}