blob: c2c68e13108e88b8e84f64fc07cca5f0ede86872 [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}
Jamie Hannaford936a5472015-02-10 14:38:28 +010056
57type ConfigResult struct {
58 gophercloud.Result
59}
60
61func (r ConfigResult) Extract() (map[string]string, error) {
Jamie Hannafordf77fc102015-02-10 14:56:02 +010062 if r.Err != nil {
63 return nil, r.Err
Jamie Hannaford936a5472015-02-10 14:38:28 +010064 }
65
66 var response struct {
67 Instance struct {
68 Config map[string]string `mapstructure:"configuration"`
69 } `mapstructure:"instance"`
70 }
71
Jamie Hannafordf77fc102015-02-10 14:56:02 +010072 err := mapstructure.Decode(r.Body, &response)
73 return response.Instance.Config, err
74}
75
76type UpdateResult struct {
77 gophercloud.ErrResult
Jamie Hannaford936a5472015-02-10 14:38:28 +010078}