blob: ac2f24b80b4ad647ba20831b86fde6668df6feb1 [file] [log] [blame]
Jon Perrittf799b942015-02-09 11:23:28 -07001package stacktemplates
2
3import (
4 "github.com/mitchellh/mapstructure"
5 "github.com/rackspace/gophercloud"
6)
7
Jon Perritt8ade4322015-02-09 11:34:59 -07008// Template represents a stack template.
Jon Perrittf799b942015-02-09 11:23:28 -07009type Template struct {
10 Description string `mapstructure:"description"`
11 HeatTemplateVersion string `mapstructure:"heat_template_version"`
12 Parameters map[string]interface{} `mapstructure:"parameters"`
13 Resources map[string]interface{} `mapstructure:"resources"`
14}
15
Jon Perritt8ade4322015-02-09 11:34:59 -070016// GetResult represents the result of a Get operation.
Jon Perrittf799b942015-02-09 11:23:28 -070017type GetResult struct {
18 gophercloud.Result
19}
20
Jon Perritt8ade4322015-02-09 11:34:59 -070021// Extract returns a pointer to a Template object and is called after a
22// Get operation.
Jon Perrittf799b942015-02-09 11:23:28 -070023func (r GetResult) Extract() (*Template, error) {
24 if r.Err != nil {
25 return nil, r.Err
26 }
27
28 var res Template
29 if err := mapstructure.Decode(r.Body, &res); err != nil {
30 return nil, err
31 }
32
33 return &res, nil
34}
35
Jon Perritt8ade4322015-02-09 11:34:59 -070036// ValidatedTemplate represents the parsed object returned from a Validate request.
Jon Perrittf799b942015-02-09 11:23:28 -070037type ValidatedTemplate struct {
38 Description string
39 Parameters map[string]interface{}
40}
41
Jon Perritt8ade4322015-02-09 11:34:59 -070042// ValidateResult represents the result of a Validate operation.
Jon Perrittf799b942015-02-09 11:23:28 -070043type ValidateResult struct {
44 gophercloud.Result
45}
46
Jon Perritt8ade4322015-02-09 11:34:59 -070047// Extract returns a pointer to a ValidatedTemplate object and is called after a
48// Validate operation.
Jon Perrittf799b942015-02-09 11:23:28 -070049func (r ValidateResult) Extract() (*ValidatedTemplate, error) {
50 if r.Err != nil {
51 return nil, r.Err
52 }
53
54 var res ValidatedTemplate
55 if err := mapstructure.Decode(r.Body, &res); err != nil {
56 return nil, err
57 }
58
59 return &res, nil
60}