@@ -2,108 +2,9 @@ package instances
2
2
3
3
import (
4
4
"github.com/rackspace/gophercloud"
5
- osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
6
5
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"
9
6
)
10
7
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
-
107
8
// Get retrieves the status and information for a specified database instance.
108
9
func Get (client * gophercloud.ServiceClient , id string ) GetResult {
109
10
return GetResult {os .Get (client , id )}
0 commit comments