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" |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 6 | os "github.com/rackspace/gophercloud/openstack/db/v1/instances" |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | type Datastore struct { |
| 10 | Type string |
| 11 | Version string |
| 12 | } |
| 13 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 14 | type Instance struct { |
| 15 | Created string //time.Time |
| 16 | Updated string //time.Time |
| 17 | Datastore Datastore |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 18 | Flavor os.Flavor |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 19 | Hostname string |
| 20 | ID string |
| 21 | Links []gophercloud.Link |
| 22 | Name string |
| 23 | Status string |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 24 | Volume os.Volume |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 25 | } |
Jamie Hannaford | 2a4beaa | 2015-02-09 17:27:18 +0100 | [diff] [blame] | 26 | |
| 27 | // CreateResult represents the result of a Create operation. |
| 28 | type CreateResult struct { |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 29 | os.CreateResult |
Jamie Hannaford | 2a4beaa | 2015-02-09 17:27:18 +0100 | [diff] [blame] | 30 | } |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 31 | |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 32 | func (r CreateResult) Extract() (*Instance, error) { |
| 33 | if r.Err != nil { |
| 34 | return nil, r.Err |
| 35 | } |
| 36 | |
| 37 | var response struct { |
| 38 | Instance Instance `mapstructure:"instance"` |
| 39 | } |
| 40 | |
| 41 | err := mapstructure.Decode(r.Body, &response) |
| 42 | |
| 43 | return &response.Instance, err |
| 44 | } |