blob: d307fad411c3a88d68f7cdb2585020926e7f8051 [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 {
7 var res GetResult
Jon Perritta33da232016-03-02 04:43:08 -06008 _, res.Err = c.Request("GET", getURL(c, stackName, stackID), &gophercloud.RequestOpts{
Ash Wilsondecfed72015-02-13 09:14:55 -05009 JSONResponse: &res.Body,
Jon Perrittf799b942015-02-09 11:23:28 -070010 })
11 return res
12}
13
14// ValidateOptsBuilder describes struct types that can be accepted by the Validate call.
15// The ValidateOpts struct in this package does.
16type ValidateOptsBuilder interface {
17 ToStackTemplateValidateMap() (map[string]interface{}, error)
18}
19
20// ValidateOpts specifies the template validation parameters.
21type ValidateOpts struct {
Pratik Mallya827c03e2015-09-17 00:10:47 -050022 Template string
Jon Perrittf799b942015-02-09 11:23:28 -070023 TemplateURL string
24}
25
26// ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts.
27func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) {
28 vo := make(map[string]interface{})
Pratik Mallya827c03e2015-09-17 00:10:47 -050029 if opts.Template != "" {
Jon Perrittf799b942015-02-09 11:23:28 -070030 vo["template"] = opts.Template
31 return vo, nil
32 }
33 if opts.TemplateURL != "" {
34 vo["template_url"] = opts.TemplateURL
35 return vo, nil
36 }
Jon Perritt58611da2016-03-09 00:49:57 -060037 err := gophercloud.ErrMissingInput{}
38 err.Argument = "stacktemplates.ValidateOpts.Template/stacktemplates.ValidateOpts.TemplateURL"
39 err.Info = "One of Template or TemplateURL is required."
40 return nil, err
Jon Perrittf799b942015-02-09 11:23:28 -070041}
42
43// Validate validates the given stack template.
44func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) ValidateResult {
45 var res ValidateResult
46
47 reqBody, err := opts.ToStackTemplateValidateMap()
48 if err != nil {
49 res.Err = err
50 return res
51 }
52
Jamie Hannaford1d27afa2015-03-24 16:20:45 +010053 _, res.Err = c.Post(validateURL(c), reqBody, &res.Body, &gophercloud.RequestOpts{
54 OkCodes: []int{200},
Jon Perrittf799b942015-02-09 11:23:28 -070055 })
56 return res
57}