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 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 27 | func commonExtract(err error, body interface{}) (*Instance, error) { |
| 28 | if err != nil { |
| 29 | return nil, err |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | var response struct { |
| 33 | Instance Instance `mapstructure:"instance"` |
| 34 | } |
| 35 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 36 | err = mapstructure.Decode(body, &response) |
Jamie Hannaford | 3dbfb2d | 2015-02-10 11:06:47 +0100 | [diff] [blame] | 37 | return &response.Instance, err |
| 38 | } |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 39 | |
| 40 | // CreateResult represents the result of a Create operation. |
| 41 | type CreateResult struct { |
| 42 | os.CreateResult |
| 43 | } |
| 44 | |
| 45 | func (r CreateResult) Extract() (*Instance, error) { |
| 46 | return commonExtract(r.Err, r.Body) |
| 47 | } |
| 48 | |
| 49 | type GetResult struct { |
| 50 | os.GetResult |
| 51 | } |
| 52 | |
| 53 | func (r GetResult) Extract() (*Instance, error) { |
| 54 | return commonExtract(r.Err, r.Body) |
| 55 | } |