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 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame^] | 8 | // Template represents a stack template. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 9 | type 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 Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame^] | 16 | // GetResult represents the result of a Get operation. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 17 | type GetResult struct { |
| 18 | gophercloud.Result |
| 19 | } |
| 20 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame^] | 21 | // Extract returns a pointer to a Template object and is called after a |
| 22 | // Get operation. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 23 | func (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 Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame^] | 36 | // ValidatedTemplate represents the parsed object returned from a Validate request. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 37 | type ValidatedTemplate struct { |
| 38 | Description string |
| 39 | Parameters map[string]interface{} |
| 40 | } |
| 41 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame^] | 42 | // ValidateResult represents the result of a Validate operation. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 43 | type ValidateResult struct { |
| 44 | gophercloud.Result |
| 45 | } |
| 46 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame^] | 47 | // Extract returns a pointer to a ValidatedTemplate object and is called after a |
| 48 | // Validate operation. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 49 | func (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 | } |