blob: d2eff6bcb14c4e837f6302d6a2c316c5e7fc801c [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 Hannaford27957b22015-02-12 12:50:55 +010014// Instance represents a remote MySQL instance.
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010015type Instance struct {
Jamie Hannaford27957b22015-02-12 12:50:55 +010016 // Indicates the datetime that the instance was created
17 Created string //time.Time
18
19 // Indicates the most recent datetime that the instance was updated.
20 Updated string //time.Time
21
22 // Indicates how the instance stores data.
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010023 Datastore Datastore
Jamie Hannaford27957b22015-02-12 12:50:55 +010024
25 // Indicates the hardware flavor the instance uses.
26 Flavor os.Flavor
27
28 // A DNS-resolvable hostname associated with the database instance (rather
29 // than an IPv4 address). Since the hostname always resolves to the correct
30 // IP address of the database instance, this relieves the user from the task
31 // of maintaining the mapping. Note that although the IP address may likely
32 // change on resizing, migrating, and so forth, the hostname always resolves
33 // to the correct database instance.
34 Hostname string
35
36 // Indicates the unique identifier for the instance resource.
37 ID string
38
39 // Exposes various links that reference the instance resource.
40 Links []gophercloud.Link
41
42 // The human-readable name of the instance.
43 Name string
44
45 // The build status of the instance.
46 Status string
47
48 // Information about the attached volume of the instance.
49 Volume os.Volume
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010050}
Jamie Hannaford2a4beaa2015-02-09 17:27:18 +010051
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010052func commonExtract(err error, body interface{}) (*Instance, error) {
53 if err != nil {
54 return nil, err
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010055 }
56
57 var response struct {
58 Instance Instance `mapstructure:"instance"`
59 }
60
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010061 err = mapstructure.Decode(body, &response)
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010062 return &response.Instance, err
63}
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010064
65// CreateResult represents the result of a Create operation.
66type CreateResult struct {
67 os.CreateResult
68}
69
70func (r CreateResult) Extract() (*Instance, error) {
71 return commonExtract(r.Err, r.Body)
72}
73
Jamie Hannaford27957b22015-02-12 12:50:55 +010074// GetResult represents the result of a Get operation.
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010075type GetResult struct {
76 os.GetResult
77}
78
Jamie Hannaford27957b22015-02-12 12:50:55 +010079// Extract will extract an Instance from a GetResult.
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010080func (r GetResult) Extract() (*Instance, error) {
81 return commonExtract(r.Err, r.Body)
82}
Jamie Hannaford936a5472015-02-10 14:38:28 +010083
84type ConfigResult struct {
85 gophercloud.Result
86}
87
Jamie Hannaford27957b22015-02-12 12:50:55 +010088// Extract will extract the configuration information (in the form of a map)
89// about a particular instance.
Jamie Hannaford936a5472015-02-10 14:38:28 +010090func (r ConfigResult) Extract() (map[string]string, error) {
Jamie Hannafordf77fc102015-02-10 14:56:02 +010091 if r.Err != nil {
92 return nil, r.Err
Jamie Hannaford936a5472015-02-10 14:38:28 +010093 }
94
95 var response struct {
96 Instance struct {
97 Config map[string]string `mapstructure:"configuration"`
98 } `mapstructure:"instance"`
99 }
100
Jamie Hannafordf77fc102015-02-10 14:56:02 +0100101 err := mapstructure.Decode(r.Body, &response)
102 return response.Instance.Config, err
103}
104
Jamie Hannaford27957b22015-02-12 12:50:55 +0100105// UpdateResult represents the result of an Update operation.
Jamie Hannafordf77fc102015-02-10 14:56:02 +0100106type UpdateResult struct {
107 gophercloud.ErrResult
Jamie Hannaford936a5472015-02-10 14:38:28 +0100108}