upcloud_api 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/upcloud_api/version.rb +1 -1
- data/lib/upcloud_api.rb +218 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b145630b5a65cce82856ed253d85e59a598814a
|
4
|
+
data.tar.gz: c125d9477ddb35c16744cc2dbf87ea8c3efc61c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a09082fd8700233b8b14479d86c210b76b075549ddb955fb6f57f4efdb2af95530935607644dd990dc6e7663bea74986a78892fdd1bc8bbe4466ec837752ca9
|
7
|
+
data.tar.gz: dbe49e4b6dc737786fb35217cb894e72375d3c17f7a1f9f5ecf9a63c4498771336d95b1755de68a672a465057930ff084eb50254e4bc5283e670af9ce7c67b74
|
data/lib/upcloud_api/version.rb
CHANGED
data/lib/upcloud_api.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
|
2
|
+
require "timeout"
|
3
|
+
|
2
4
|
require "httparty"
|
3
5
|
|
4
6
|
class UpcloudApi
|
@@ -169,7 +171,7 @@ class UpcloudApi
|
|
169
171
|
|
170
172
|
return response if asynchronous
|
171
173
|
|
172
|
-
Timeout 300 do
|
174
|
+
Timeout::timeout 300 do
|
173
175
|
loop do
|
174
176
|
details = server_details server_uuid
|
175
177
|
return response if details["server"]["state"] == "stopped"
|
@@ -205,6 +207,221 @@ class UpcloudApi
|
|
205
207
|
response
|
206
208
|
end
|
207
209
|
|
210
|
+
# Lists all storages or storages matching to given type.
|
211
|
+
#
|
212
|
+
# Calls GET /1.2/storage or /1.2/storage/#{type}
|
213
|
+
#
|
214
|
+
# Available types:
|
215
|
+
# - public
|
216
|
+
# - private
|
217
|
+
# - normal
|
218
|
+
# - backup
|
219
|
+
# - cdrom
|
220
|
+
# - template
|
221
|
+
# - favorite
|
222
|
+
#
|
223
|
+
# @param type Type of the storages to be returned on nil
|
224
|
+
def storages type: nil
|
225
|
+
response = get(type && "storage/#{type}" || "storage")
|
226
|
+
data = JSON.parse response.body
|
227
|
+
data
|
228
|
+
end
|
229
|
+
|
230
|
+
# Shows detailed information of single storage.
|
231
|
+
#
|
232
|
+
# Calls GET /1.2/storage/#{uuid}
|
233
|
+
#
|
234
|
+
# @param storage_uuid UUID of the storage
|
235
|
+
def storage_details storage_uuid
|
236
|
+
response = get "storage/#{storage_uuid}"
|
237
|
+
data = JSON.parse response.body
|
238
|
+
data
|
239
|
+
end
|
240
|
+
|
241
|
+
# Creates new storage.
|
242
|
+
#
|
243
|
+
# Calls POST /1.2/storage
|
244
|
+
#
|
245
|
+
# backup_rule should be hash with following attributes:
|
246
|
+
# - interval # allowed values: daily / mon / tue / wed / thu / fri / sat / sun
|
247
|
+
# - time # allowed values: 0000-2359
|
248
|
+
# - retention # How many days backup will be kept. Allowed values: 1-1095
|
249
|
+
#
|
250
|
+
# @param size Size of the storage in gigabytes
|
251
|
+
# @param tier Type of the disk. maxiops is SSD powered disk, other allowed value is "hdd"
|
252
|
+
# @param title Name of the disk
|
253
|
+
# @param zone Where the disk will reside. Needs to be within same zone with the server
|
254
|
+
# @param backup_rule Hash of backup information. If not given, no backups will be automatically created.
|
255
|
+
def create_storage size:, tier: "maxiops", title:, zone: "fi-hel1", backup_rule: nil
|
256
|
+
data = {
|
257
|
+
"storage" => {
|
258
|
+
"size" => size,
|
259
|
+
"tier" => tier,
|
260
|
+
"title" => title,
|
261
|
+
"zone" => zone,
|
262
|
+
"backup_rule" => backup_rule
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
json = JSON.generate data
|
267
|
+
|
268
|
+
response = post "storage", json
|
269
|
+
|
270
|
+
response
|
271
|
+
end
|
272
|
+
|
273
|
+
# Modifies existing storage.
|
274
|
+
#
|
275
|
+
# Calls PUT /1.2/storage/#{uuid}
|
276
|
+
#
|
277
|
+
# backup_rule should be hash with following attributes:
|
278
|
+
# - interval # allowed values: daily / mon / tue / wed / thu / fri / sat / sun
|
279
|
+
# - time # allowed values: 0000-2359
|
280
|
+
# - retention # How many days backup will be kept. Allowed values: 1-1095
|
281
|
+
#
|
282
|
+
# @param storage_uuid UUID of the storage that will be modified
|
283
|
+
# @param size Size of the storage in gigabytes
|
284
|
+
# @param title Name of the disk
|
285
|
+
# @param backup_rule Hash of backup information. If not given, no backups will be automatically created.
|
286
|
+
def modify_storage storage_uuid, size:, title:, backup_rule: nil
|
287
|
+
data = {
|
288
|
+
"storage" => {
|
289
|
+
"size" => size,
|
290
|
+
"title" => title,
|
291
|
+
"backup_rule" => backup_rule
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
json = JSON.generate data
|
296
|
+
|
297
|
+
response = put "storage/#{storage_uuid}", json
|
298
|
+
|
299
|
+
response
|
300
|
+
end
|
301
|
+
|
302
|
+
# Clones existing storage.
|
303
|
+
#
|
304
|
+
# This operation is asynchronous.
|
305
|
+
#
|
306
|
+
# Calls POST /1.2/storage/#{uuid}/clone
|
307
|
+
#
|
308
|
+
# backup_rule should be hash with following attributes:
|
309
|
+
# - interval # allowed values: daily / mon / tue / wed / thu / fri / sat / sun
|
310
|
+
# - time # allowed values: 0000-2359
|
311
|
+
# - retention # How many days backup will be kept. Allowed values: 1-1095
|
312
|
+
#
|
313
|
+
# @param storage_uuid UUID of the storage that will be modified
|
314
|
+
# @param tier Type of the disk. maxiops is SSD powered disk, other allowed value is "hdd"
|
315
|
+
# @param title Name of the disk
|
316
|
+
# @param zone Where the disk will reside. Needs to be within same zone with the server
|
317
|
+
def clone_storage storage_uuid, zone: "fi-hel1", title:, tier: "maxiops"
|
318
|
+
data = {
|
319
|
+
"storage" => {
|
320
|
+
"zone" => zone,
|
321
|
+
"title" => title,
|
322
|
+
"tier" => tier
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
json = JSON.generate data
|
327
|
+
|
328
|
+
response = post "storage/#{storage_uuid}/clone", json
|
329
|
+
|
330
|
+
response
|
331
|
+
end
|
332
|
+
|
333
|
+
# Attaches a storage to a server. Server must be stopped before the storage can be attached.
|
334
|
+
#
|
335
|
+
# Calls POST /1.2/server/#{server_uuid}/storage/attach
|
336
|
+
#
|
337
|
+
# Valid values for address are: ide[01]:[01] / scsi:0:[0-7] / virtio:[0-7]
|
338
|
+
#
|
339
|
+
# @param type Type of the disk. Valid values are "disk" and "cdrom".
|
340
|
+
# @param address Address where the disk will be attached to. Defaults to next available address.
|
341
|
+
# @param server_uuid UUID of the server where the disk will be attached to.
|
342
|
+
# @param storage_uuid UUID of the storage that will be attached.
|
343
|
+
def attach_storage type: "disk", address: nil, server_uuid:, storage_uuid:
|
344
|
+
data = {
|
345
|
+
"storage_device" => {
|
346
|
+
"type" => type,
|
347
|
+
"address" => address,
|
348
|
+
"storage" => storage_uuid
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
json = JSON.generate data
|
353
|
+
|
354
|
+
response = post "server/#{server_uuid}/storage/attach", json
|
355
|
+
|
356
|
+
response
|
357
|
+
end
|
358
|
+
|
359
|
+
# Detaches storage from a server. Server must be stopped before the storage can be detached.
|
360
|
+
#
|
361
|
+
# Calls POST /1.2/server/#{server_uuid}/storage/detach
|
362
|
+
#
|
363
|
+
# @param address Address where the storage that will be detached resides.
|
364
|
+
def detach_storage address
|
365
|
+
data = {
|
366
|
+
"storage_device" => {
|
367
|
+
"address" => address
|
368
|
+
}
|
369
|
+
}
|
370
|
+
|
371
|
+
json = JSON.generate data
|
372
|
+
|
373
|
+
response = post "server/#{server_uuid}/storage/detach", json
|
374
|
+
|
375
|
+
response
|
376
|
+
end
|
377
|
+
|
378
|
+
# Creates backup from a storage.
|
379
|
+
#
|
380
|
+
# This operation is asynchronous.
|
381
|
+
#
|
382
|
+
# Calls /1.2/storage/#{uuid}/backup
|
383
|
+
#
|
384
|
+
# @param storage_uuid UUID of the storage to be cloned
|
385
|
+
# @param title Name of the backup
|
386
|
+
def create_backup storage_uuid, title:
|
387
|
+
data = {
|
388
|
+
"storage" => {
|
389
|
+
"title" => title
|
390
|
+
}
|
391
|
+
}
|
392
|
+
|
393
|
+
json = JSON.generate data
|
394
|
+
|
395
|
+
response = post "storage/#{storage_uuid}/backup", json
|
396
|
+
|
397
|
+
response
|
398
|
+
end
|
399
|
+
|
400
|
+
# Restores a backup.
|
401
|
+
#
|
402
|
+
# If the storage is attached to server, the server must first be stopped.
|
403
|
+
#
|
404
|
+
# Calls /1.2/storage/#{uuid}/restore.
|
405
|
+
#
|
406
|
+
# @param storage_uuid TODO: is this supposed to be UUID of the storage or the backup?
|
407
|
+
def create_backup storage_uuid
|
408
|
+
response = post "storage/#{storage_uuid}/restore"
|
409
|
+
|
410
|
+
response
|
411
|
+
end
|
412
|
+
|
413
|
+
# Deletes a storage.
|
414
|
+
#
|
415
|
+
# The storage must be in "online" state and it must not be attached to any server.
|
416
|
+
# Backups will not be deleted.
|
417
|
+
#
|
418
|
+
# @param storage_uuid UUID of the storage that will be deleted.
|
419
|
+
def delete_storage storage_uuid
|
420
|
+
response = delete "storage/#{storage_uuid}"
|
421
|
+
|
422
|
+
response
|
423
|
+
end
|
424
|
+
|
208
425
|
private
|
209
426
|
|
210
427
|
def get action
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upcloud_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samu Voutilainen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|