Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 7274916

Browse files
author
Jamie Hannaford
committed
Add list options
1 parent d87c7d6 commit 7274916

File tree

5 files changed

+217
-157
lines changed

5 files changed

+217
-157
lines changed

rackspace/db/v1/instances/delegate.go

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,108 +2,9 @@ package instances
22

33
import (
44
"github.com/rackspace/gophercloud"
5-
osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
65
os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
7-
osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users"
8-
"github.com/rackspace/gophercloud/pagination"
96
)
107

11-
// CreateOpts is the struct responsible for configuring a new database instance.
12-
type CreateOpts struct {
13-
// Either the integer UUID (in string form) of the flavor, or its URI
14-
// reference as specified in the response from the List() call. Required.
15-
FlavorRef string
16-
17-
// Specifies the volume size in gigabytes (GB). The value must be between 1
18-
// and 300. Required.
19-
Size int
20-
21-
// Name of the instance to create. The length of the name is limited to
22-
// 255 characters and any characters are permitted. Optional.
23-
Name string
24-
25-
// A slice of database information options.
26-
Databases osDBs.BatchCreateOpts
27-
28-
// A slice of user information options.
29-
Users osUsers.BatchCreateOpts
30-
31-
// ID of the configuration group to associate with the instance. Optional.
32-
ConfigID string
33-
34-
// Options to configure the type of datastore the instance will use. This is
35-
// optional, and if excluded will default to MySQL.
36-
Datastore *os.DatastoreOpts
37-
38-
// Specifies the backup ID from which to restore the database instance. There
39-
// are some things to be aware of before using this field. When you execute
40-
// the Restore Backup operation, a new database instance is created to store
41-
// the backup whose ID is specified by the restorePoint attribute. This will
42-
// mean that:
43-
// - All users, passwords and access that were on the instance at the time of
44-
// the backup will be restored along with the databases.
45-
// - You can create new users or databases if you want, but they cannot be
46-
// the same as the ones from the instance that was backed up.
47-
RestorePoint string
48-
49-
ReplicaOf string
50-
}
51-
52-
func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) {
53-
instance, err := os.CreateOpts{
54-
FlavorRef: opts.FlavorRef,
55-
Size: opts.Size,
56-
Name: opts.Name,
57-
Databases: opts.Databases,
58-
Users: opts.Users,
59-
}.ToInstanceCreateMap()
60-
61-
if err != nil {
62-
return nil, err
63-
}
64-
65-
instance = instance["instance"].(map[string]interface{})
66-
67-
if opts.ConfigID != "" {
68-
instance["configuration"] = opts.ConfigID
69-
}
70-
71-
if opts.Datastore != nil {
72-
ds, err := opts.Datastore.ToMap()
73-
if err != nil {
74-
return nil, err
75-
}
76-
instance["datastore"] = ds
77-
}
78-
79-
if opts.RestorePoint != "" {
80-
instance["restorePoint"] = map[string]string{"backupRef": opts.RestorePoint}
81-
}
82-
83-
if opts.ReplicaOf != "" {
84-
instance["replica_of"] = opts.ReplicaOf
85-
}
86-
87-
return map[string]interface{}{"instance": instance}, nil
88-
}
89-
90-
// Create asynchronously provisions a new database instance. It requires the
91-
// user to specify a flavor and a volume size. The API service then provisions
92-
// the instance with the requested flavor and sets up a volume of the specified
93-
// size, which is the storage for the database instance.
94-
//
95-
// Although this call only allows the creation of 1 instance per request, you
96-
// can create an instance with multiple databases and users. The default
97-
// binding for a MySQL instance is port 3306.
98-
func Create(client *gophercloud.ServiceClient, opts os.CreateOptsBuilder) CreateResult {
99-
return CreateResult{os.Create(client, opts)}
100-
}
101-
102-
// List retrieves the status and information for all database instances.
103-
func List(client *gophercloud.ServiceClient) pagination.Pager {
104-
return os.List(client)
105-
}
106-
1078
// Get retrieves the status and information for a specified database instance.
1089
func Get(client *gophercloud.ServiceClient, id string) GetResult {
10910
return GetResult{os.Get(client, id)}

rackspace/db/v1/instances/delegate_test.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ package instances
33
import (
44
"testing"
55

6-
"github.com/rackspace/gophercloud"
76
osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
8-
"github.com/rackspace/gophercloud/openstack/db/v1/datastores"
9-
"github.com/rackspace/gophercloud/openstack/db/v1/flavors"
107
os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
118
osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users"
129
th "github.com/rackspace/gophercloud/testhelper"
@@ -15,32 +12,10 @@ import (
1512
)
1613

1714
var (
18-
instanceID = "{instanceID}"
19-
_rootURL = "/instances"
20-
resURL = "/instances/" + instanceID
15+
_rootURL = "/instances"
16+
resURL = "/instances/" + instanceID
2117
)
2218

23-
var expectedInstance = &Instance{
24-
Created: "2014-02-13T21:47:13",
25-
Updated: "2014-02-13T21:47:13",
26-
Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"},
27-
Flavor: flavors.Flavor{
28-
ID: "1",
29-
Links: []gophercloud.Link{
30-
gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
31-
gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
32-
},
33-
},
34-
Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
35-
ID: instanceID,
36-
Links: []gophercloud.Link{
37-
gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
38-
},
39-
Name: "json_rack_instance",
40-
Status: "BUILD",
41-
Volume: os.Volume{Size: 2},
42-
}
43-
4419
func TestCreate(t *testing.T) {
4520
th.SetupHTTP()
4621
defer th.TeardownHTTP()

rackspace/db/v1/instances/fixtures.go

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package instances
22

33
import (
4+
"fmt"
5+
46
"github.com/rackspace/gophercloud"
57
"github.com/rackspace/gophercloud/openstack/db/v1/datastores"
68
"github.com/rackspace/gophercloud/openstack/db/v1/flavors"
@@ -9,39 +11,37 @@ import (
911

1012
const instance = `
1113
{
12-
"instance": {
13-
"created": "2014-02-13T21:47:13",
14-
"datastore": {
15-
"type": "mysql",
16-
"version": "5.6"
17-
},
18-
"flavor": {
19-
"id": "1",
20-
"links": [
21-
{
22-
"href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
23-
"rel": "self"
24-
},
25-
{
26-
"href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
27-
"rel": "bookmark"
28-
}
29-
]
30-
},
14+
"created": "2014-02-13T21:47:13",
15+
"datastore": {
16+
"type": "mysql",
17+
"version": "5.6"
18+
},
19+
"flavor": {
20+
"id": "1",
3121
"links": [
3222
{
3323
"href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
3424
"rel": "self"
25+
},
26+
{
27+
"href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
28+
"rel": "bookmark"
3529
}
36-
],
37-
"hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
38-
"id": "{instanceID}",
39-
"name": "json_rack_instance",
40-
"status": "BUILD",
41-
"updated": "2014-02-13T21:47:13",
42-
"volume": {
43-
"size": 2
30+
]
31+
},
32+
"links": [
33+
{
34+
"href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
35+
"rel": "self"
4436
}
37+
],
38+
"hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
39+
"id": "{instanceID}",
40+
"name": "json_rack_instance",
41+
"status": "BUILD",
42+
"updated": "2014-02-13T21:47:13",
43+
"volume": {
44+
"size": 2
4545
}
4646
}
4747
`
@@ -286,11 +286,35 @@ var listBackupsResp = `
286286
`
287287

288288
var (
289-
createResp = instance
290-
getResp = instance
291-
associateResp = instance
289+
createResp = fmt.Sprintf(`{"instance":%s}`, instance)
290+
getResp = fmt.Sprintf(`{"instance":%s}`, instance)
291+
associateResp = fmt.Sprintf(`{"instance":%s}`, instance)
292+
listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance)
292293
)
293294

295+
var instanceID = "{instanceID}"
296+
297+
var expectedInstance = &Instance{
298+
Created: "2014-02-13T21:47:13",
299+
Updated: "2014-02-13T21:47:13",
300+
Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"},
301+
Flavor: flavors.Flavor{
302+
ID: "1",
303+
Links: []gophercloud.Link{
304+
gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
305+
gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
306+
},
307+
},
308+
Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
309+
ID: instanceID,
310+
Links: []gophercloud.Link{
311+
gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
312+
},
313+
Name: "json_rack_instance",
314+
Status: "BUILD",
315+
Volume: os.Volume{Size: 2},
316+
}
317+
294318
var expectedReplica = &Instance{
295319
Status: "BUILD",
296320
Updated: "2014-10-14T18:42:15",

0 commit comments

Comments
 (0)