blob: c5ff37aee1aa69e8e4b5f3103c53559b083e125d [file] [log] [blame]
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +01001package instances
2
3import (
Jamie Hannaford72749162015-10-14 12:14:32 +02004 "fmt"
Jamie Hannaforde65ad952015-11-16 14:05:11 +01005 "time"
Jamie Hannaford72749162015-10-14 12:14:32 +02006
Jamie Hannaforde635b7d2015-02-18 14:11:46 +01007 "github.com/rackspace/gophercloud"
Jamie Hannaford52dbcee2015-10-06 16:09:56 +02008 "github.com/rackspace/gophercloud/openstack/db/v1/datastores"
Jamie Hannaford11108402015-02-23 10:31:41 +01009 "github.com/rackspace/gophercloud/openstack/db/v1/flavors"
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010010 os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010011)
12
Jamie Hannaforde65ad952015-11-16 14:05:11 +010013var (
14 timestamp = "2015-11-12T14:22:42Z"
15 timeVal, _ = time.Parse(time.RFC3339, timestamp)
16)
17
18var instance = `
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010019{
Jamie Hannaforde65ad952015-11-16 14:05:11 +010020 "created": "` + timestamp + `",
Jamie Hannaford72749162015-10-14 12:14:32 +020021 "datastore": {
22 "type": "mysql",
23 "version": "5.6"
24 },
25 "flavor": {
26 "id": "1",
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010027 "links": [
28 {
29 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
30 "rel": "self"
Jamie Hannaford72749162015-10-14 12:14:32 +020031 },
32 {
33 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
34 "rel": "bookmark"
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010035 }
Jamie Hannaford72749162015-10-14 12:14:32 +020036 ]
37 },
38 "links": [
39 {
40 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
41 "rel": "self"
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010042 }
Jamie Hannaford72749162015-10-14 12:14:32 +020043 ],
44 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
45 "id": "{instanceID}",
46 "name": "json_rack_instance",
47 "status": "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +010048 "updated": "` + timestamp + `",
Jamie Hannaford72749162015-10-14 12:14:32 +020049 "volume": {
50 "size": 2
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010051 }
52}
53`
54
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010055var createReq = `
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010056{
57 "instance": {
58 "databases": [
59 {
60 "character_set": "utf8",
61 "collate": "utf8_general_ci",
62 "name": "sampledb"
63 },
64 {
65 "name": "nextround"
66 }
67 ],
68 "flavorRef": "1",
69 "name": "json_rack_instance",
70 "users": [
71 {
72 "databases": [
73 {
74 "name": "sampledb"
75 }
76 ],
77 "name": "demouser",
78 "password": "demopassword"
79 }
80 ],
81 "volume": {
82 "size": 2
83 },
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010084 "restorePoint": {
85 "backupRef": "1234567890"
86 }
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010087 }
88}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010089`
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010090
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010091var createReplicaReq = `
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010092{
93 "instance": {
94 "volume": {
95 "size": 1
96 },
97 "flavorRef": "9",
98 "name": "t2s1_ALT_GUEST",
99 "replica_of": "6bdca2fc-418e-40bd-a595-62abda61862d"
100 }
101}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100102`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100103
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100104var createReplicaResp = `
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100105{
106 "instance": {
107 "status": "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100108 "updated": "` + timestamp + `",
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100109 "name": "t2s1_ALT_GUEST",
110 "links": [
111 {
112 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/5919009/instances/8367c312-7c40-4a66-aab1-5767478914fc",
113 "rel": "self"
114 },
115 {
116 "href": "https://ord.databases.api.rackspacecloud.com/instances/8367c312-7c40-4a66-aab1-5767478914fc",
117 "rel": "bookmark"
118 }
119 ],
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100120 "created": "` + timestamp + `",
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100121 "id": "8367c312-7c40-4a66-aab1-5767478914fc",
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100122 "volume": {
123 "size": 1
124 },
125 "flavor": {
126 "id": "9"
127 },
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100128 "datastore": {
129 "version": "5.6",
130 "type": "mysql"
131 },
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100132 "replica_of": {
133 "id": "6bdca2fc-418e-40bd-a595-62abda61862d"
134 }
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100135 }
136}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100137`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100138
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100139var listReplicasResp = `
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100140{
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100141 "instances": [
142 {
143 "status": "ACTIVE",
144 "name": "t1s1_ALT_GUEST",
145 "links": [
146 {
147 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254",
148 "rel": "self"
149 },
150 {
151 "href": "https://ord.databases.api.rackspacecloud.com/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254",
152 "rel": "bookmark"
153 }
154 ],
155 "ip": [
156 "10.0.0.3"
157 ],
158 "id": "3c691f06-bf9a-4618-b7ec-2817ce0cf254",
159 "volume": {
160 "size": 1
161 },
162 "flavor": {
163 "id": "9"
164 },
165 "datastore": {
166 "version": "5.6",
167 "type": "mysql"
168 },
169 "replica_of": {
170 "id": "8b499b45-52d6-402d-b398-f9d8f279c69a"
171 }
172 }
173 ]
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100174}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100175`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100176
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100177var getReplicaResp = `
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100178{
179 "instance": {
180 "status": "ACTIVE",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100181 "updated": "` + timestamp + `",
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100182 "name": "t1_ALT_GUEST",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100183 "created": "` + timestamp + `",
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100184 "ip": [
185 "10.0.0.2"
186 ],
187 "replicas": [
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100188 {
189 "id": "3c691f06-bf9a-4618-b7ec-2817ce0cf254"
190 }
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100191 ],
192 "id": "8b499b45-52d6-402d-b398-f9d8f279c69a",
193 "volume": {
194 "used": 0.54,
195 "size": 1
196 },
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100197 "flavor": {
198 "id": "9"
199 },
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100200 "datastore": {
201 "version": "5.6",
202 "type": "mysql"
203 }
204 }
205}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100206`
207
208var detachReq = `
209{
210 "instance": {
211 "replica_of": "",
212 "slave_of": ""
213 }
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100214}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100215`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100216
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100217var getConfigResp = `
Jamie Hannaford936a5472015-02-10 14:38:28 +0100218{
219 "instance": {
220 "configuration": {
221 "basedir": "/usr",
222 "connect_timeout": "15",
223 "datadir": "/var/lib/mysql",
224 "default_storage_engine": "innodb",
225 "innodb_buffer_pool_instances": "1",
226 "innodb_buffer_pool_size": "175M",
227 "innodb_checksum_algorithm": "crc32",
228 "innodb_data_file_path": "ibdata1:10M:autoextend",
229 "innodb_file_per_table": "1",
230 "innodb_io_capacity": "200",
231 "innodb_log_file_size": "256M",
232 "innodb_log_files_in_group": "2",
233 "innodb_open_files": "8192",
234 "innodb_thread_concurrency": "0",
235 "join_buffer_size": "1M",
236 "key_buffer_size": "50M",
237 "local-infile": "0",
238 "log-error": "/var/log/mysql/mysqld.log",
239 "max_allowed_packet": "16M",
240 "max_connect_errors": "10000",
241 "max_connections": "40",
242 "max_heap_table_size": "16M",
243 "myisam-recover": "BACKUP",
244 "open_files_limit": "8192",
245 "performance_schema": "off",
246 "pid_file": "/var/run/mysqld/mysqld.pid",
247 "port": "3306",
248 "query_cache_limit": "1M",
249 "query_cache_size": "8M",
250 "query_cache_type": "1",
251 "read_buffer_size": "256K",
252 "read_rnd_buffer_size": "1M",
253 "server_id": "1",
254 "skip-external-locking": "1",
255 "skip_name_resolve": "1",
256 "sort_buffer_size": "256K",
257 "table_open_cache": "4096",
258 "thread_stack": "192K",
259 "tmp_table_size": "16M",
260 "tmpdir": "/var/tmp",
261 "user": "mysql",
262 "wait_timeout": "3600"
263 }
264 }
265}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100266`
Jamie Hannafordf77fc102015-02-10 14:56:02 +0100267
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100268var associateReq = `{"instance": {"configuration": "{configGroupID}"}}`
Jamie Hannafordf77fc102015-02-10 14:56:02 +0100269
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100270var listBackupsResp = `
Jamie Hannaford2e817322015-02-16 15:29:17 +0100271{
272 "backups": [
273 {
274 "status": "COMPLETED",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100275 "updated": "` + timestamp + `",
Jamie Hannaford2e817322015-02-16 15:29:17 +0100276 "description": "Backup from Restored Instance",
277 "datastore": {
278 "version": "5.1",
279 "type": "MySQL",
280 "version_id": "20000000-0000-0000-0000-000000000002"
281 },
282 "id": "87972694-4be2-40f5-83f8-501656e0032a",
283 "size": 0.141026,
284 "name": "restored_backup",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100285 "created": "` + timestamp + `",
Jamie Hannaford2e817322015-02-16 15:29:17 +0100286 "instance_id": "29af2cd9-0674-48ab-b87a-b160f00208e6",
287 "parent_id": null,
288 "locationRef": "http://localhost/path/to/backup"
289 }
290 ]
291}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100292`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100293
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100294var (
Jamie Hannaford72749162015-10-14 12:14:32 +0200295 createResp = fmt.Sprintf(`{"instance":%s}`, instance)
296 getResp = fmt.Sprintf(`{"instance":%s}`, instance)
297 associateResp = fmt.Sprintf(`{"instance":%s}`, instance)
298 listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance)
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100299)
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100300
Jamie Hannaford72749162015-10-14 12:14:32 +0200301var instanceID = "{instanceID}"
302
303var expectedInstance = &Instance{
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100304 Created: timeVal,
305 Updated: timeVal,
Jamie Hannaford72749162015-10-14 12:14:32 +0200306 Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"},
307 Flavor: flavors.Flavor{
308 ID: "1",
309 Links: []gophercloud.Link{
310 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
311 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
312 },
313 },
314 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
315 ID: instanceID,
316 Links: []gophercloud.Link{
317 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
318 },
319 Name: "json_rack_instance",
320 Status: "BUILD",
321 Volume: os.Volume{Size: 2},
322}
323
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100324var expectedReplica = &Instance{
325 Status: "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100326 Updated: timeVal,
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100327 Name: "t2s1_ALT_GUEST",
328 Links: []gophercloud.Link{
329 gophercloud.Link{Rel: "self", Href: "https://ord.databases.api.rackspacecloud.com/v1.0/5919009/instances/8367c312-7c40-4a66-aab1-5767478914fc"},
330 gophercloud.Link{Rel: "bookmark", Href: "https://ord.databases.api.rackspacecloud.com/instances/8367c312-7c40-4a66-aab1-5767478914fc"},
331 },
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100332 Created: timeVal,
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100333 ID: "8367c312-7c40-4a66-aab1-5767478914fc",
334 Volume: os.Volume{Size: 1},
Jamie Hannaford11108402015-02-23 10:31:41 +0100335 Flavor: flavors.Flavor{ID: "9"},
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100336 Datastore: datastores.DatastorePartial{Version: "5.6", Type: "mysql"},
337 ReplicaOf: &Instance{
338 ID: "6bdca2fc-418e-40bd-a595-62abda61862d",
339 },
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100340}