blob: 66b3ce103a126ea4c1a828d8beef6fb3996516ab [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"
6)
7
8type Datastore struct {
9 Type string
10 Version string
11}
12
13type Flavor struct {
14 ID string
15 Links []gophercloud.Link
16}
17
18type Volume struct {
19 Size int
20}
21
22type 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 Hannaford2a4beaa2015-02-09 17:27:18 +010034
35// CreateResult represents the result of a Create operation.
36type CreateResult struct {
37 gophercloud.Result
38}
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010039
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
47func (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}