Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 1 | package stacktemplates |
| 2 | |
| 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | "github.com/rackspace/gophercloud" |
| 6 | ) |
| 7 | |
| 8 | type Template struct { |
| 9 | Description string `mapstructure:"description"` |
| 10 | HeatTemplateVersion string `mapstructure:"heat_template_version"` |
| 11 | Parameters map[string]interface{} `mapstructure:"parameters"` |
| 12 | Resources map[string]interface{} `mapstructure:"resources"` |
| 13 | } |
| 14 | |
| 15 | type GetResult struct { |
| 16 | gophercloud.Result |
| 17 | } |
| 18 | |
| 19 | func (r GetResult) Extract() (*Template, error) { |
| 20 | if r.Err != nil { |
| 21 | return nil, r.Err |
| 22 | } |
| 23 | |
| 24 | var res Template |
| 25 | if err := mapstructure.Decode(r.Body, &res); err != nil { |
| 26 | return nil, err |
| 27 | } |
| 28 | |
| 29 | return &res, nil |
| 30 | } |
| 31 | |
| 32 | type ValidatedTemplate struct { |
| 33 | Description string |
| 34 | Parameters map[string]interface{} |
| 35 | } |
| 36 | |
| 37 | type ValidateResult struct { |
| 38 | gophercloud.Result |
| 39 | } |
| 40 | |
| 41 | func (r ValidateResult) Extract() (*ValidatedTemplate, error) { |
| 42 | if r.Err != nil { |
| 43 | return nil, r.Err |
| 44 | } |
| 45 | |
| 46 | var res ValidatedTemplate |
| 47 | if err := mapstructure.Decode(r.Body, &res); err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | |
| 51 | return &res, nil |
| 52 | } |