blob: cab403ad38b78fe5e473271de12f980694fa8ca0 [file] [log] [blame]
Jamie Hannaford2a4beaa2015-02-09 17:27:18 +01001package instances
2
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +01003import (
4 "github.com/mitchellh/mapstructure"
5 "github.com/rackspace/gophercloud"
Jamie Hannaford9fdda582015-02-10 12:15:43 +01006 os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +01007)
8
9type Datastore struct {
10 Type string
11 Version string
12}
13
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010014type Instance struct {
15 Created string //time.Time
16 Updated string //time.Time
17 Datastore Datastore
Jamie Hannaford9fdda582015-02-10 12:15:43 +010018 Flavor os.Flavor
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010019 Hostname string
20 ID string
21 Links []gophercloud.Link
22 Name string
23 Status string
Jamie Hannaford9fdda582015-02-10 12:15:43 +010024 Volume os.Volume
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010025}
Jamie Hannaford2a4beaa2015-02-09 17:27:18 +010026
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010027func commonExtract(err error, body interface{}) (*Instance, error) {
28 if err != nil {
29 return nil, err
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010030 }
31
32 var response struct {
33 Instance Instance `mapstructure:"instance"`
34 }
35
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010036 err = mapstructure.Decode(body, &response)
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010037 return &response.Instance, err
38}
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010039
40// CreateResult represents the result of a Create operation.
41type CreateResult struct {
42 os.CreateResult
43}
44
45func (r CreateResult) Extract() (*Instance, error) {
46 return commonExtract(r.Err, r.Body)
47}
48
49type GetResult struct {
50 os.GetResult
51}
52
53func (r GetResult) Extract() (*Instance, error) {
54 return commonExtract(r.Err, r.Body)
55}