Jamie Hannaford | 2a4beaa | 2015-02-09 17:27:18 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame^] | 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | "github.com/rackspace/gophercloud" |
| 6 | ) |
| 7 | |
| 8 | type Datastore struct { |
| 9 | Type string |
| 10 | Version string |
| 11 | } |
| 12 | |
| 13 | type Flavor struct { |
| 14 | ID string |
| 15 | Links []gophercloud.Link |
| 16 | } |
| 17 | |
| 18 | type Volume struct { |
| 19 | Size int |
| 20 | } |
| 21 | |
| 22 | type Instance struct { |
| 23 | Created string //time.Time |
| 24 | Updated string //time.Time |
| 25 | Datastore Datastore |
| 26 | Flavor Flavor |
| 27 | Hostname string |
| 28 | ID string |
| 29 | Links []gophercloud.Link |
| 30 | Name string |
| 31 | Status string |
| 32 | Volume Volume |
| 33 | } |
Jamie Hannaford | 2a4beaa | 2015-02-09 17:27:18 +0100 | [diff] [blame] | 34 | |
| 35 | // CreateResult represents the result of a Create operation. |
| 36 | type CreateResult struct { |
| 37 | gophercloud.Result |
| 38 | } |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame^] | 39 | |
| 40 | // func handleInstanceConversion(from reflect.Kind, to reflect.Kind, data interface{}) (interface{}, error) { |
| 41 | // if (from == reflect.String) && (to == reflect.Map) { |
| 42 | // return map[string]interface{}{}, nil |
| 43 | // } |
| 44 | // return data, nil |
| 45 | // } |
| 46 | |
| 47 | func (r CreateResult) Extract() (*Instance, error) { |
| 48 | if r.Err != nil { |
| 49 | return nil, r.Err |
| 50 | } |
| 51 | |
| 52 | var response struct { |
| 53 | Instance Instance `mapstructure:"instance"` |
| 54 | } |
| 55 | |
| 56 | err := mapstructure.Decode(r.Body, &response) |
| 57 | |
| 58 | return &response.Instance, err |
| 59 | } |