blob: d248c24ff64f013116ddff2468c4a423dd34f04f [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)
jrperritt29ae6b32016-04-13 12:59:37 -05008 return
Jon Perrittf799b942015-02-09 11:23:28 -07009}
10
11// ValidateOptsBuilder describes struct types that can be accepted by the Validate call.
12// The ValidateOpts struct in this package does.
13type ValidateOptsBuilder interface {
14 ToStackTemplateValidateMap() (map[string]interface{}, error)
15}
16
17// ValidateOpts specifies the template validation parameters.
18type ValidateOpts struct {
Jon Perrittfea90732016-03-15 02:57:05 -050019 Template string `json:"template" or:"TemplateURL"`
20 TemplateURL string `json:"template_url" or:"Template"`
Jon Perrittf799b942015-02-09 11:23:28 -070021}
22
23// ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts.
24func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) {
Jon Perrittfea90732016-03-15 02:57:05 -050025 return gophercloud.BuildRequestBody(opts, "")
Jon Perrittf799b942015-02-09 11:23:28 -070026}
27
28// Validate validates the given stack template.
Jon Perritt3860b512016-03-29 12:01:48 -050029func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) (r ValidateResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050030 b, err := opts.ToStackTemplateValidateMap()
Jon Perrittf799b942015-02-09 11:23:28 -070031 if err != nil {
Jon Perrittfea90732016-03-15 02:57:05 -050032 r.Err = err
Jon Perritt3860b512016-03-29 12:01:48 -050033 return
Jon Perrittf799b942015-02-09 11:23:28 -070034 }
Jon Perrittfea90732016-03-15 02:57:05 -050035 _, r.Err = c.Post(validateURL(c), b, &r.Body, &gophercloud.RequestOpts{
Jamie Hannaford1d27afa2015-03-24 16:20:45 +010036 OkCodes: []int{200},
Jon Perrittf799b942015-02-09 11:23:28 -070037 })
jrperritt29ae6b32016-04-13 12:59:37 -050038 return
Jon Perrittf799b942015-02-09 11:23:28 -070039}