upcloud_api 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b9499c81732dab73f760bcfc382a7c288d82960
4
- data.tar.gz: 61ec8087b5b00f870495fdf4c9859e962c8675f4
3
+ metadata.gz: 8b54b7fb711a64b56613be72b899acdc0305e9d0
4
+ data.tar.gz: b88391e2f5aff4f02b5f16f1849f215038081303
5
5
  SHA512:
6
- metadata.gz: 52496d8d4289e67cf15da5703500e497201d312553c78eaf58e548d1958796075177405ae5b5acc75dbfc1a594bc6b6fc7913cc8d789c7cce7cbdbb47b4c7e8e
7
- data.tar.gz: edab2b929517934e42e082142ae19b5c186116b4a3cc248cf31df506974b415641dd4e46efbe07d175fa100c120b63f642bcd799ac06352ac35de4a0e66d3660
6
+ metadata.gz: 993b7e0461cd0bd75e700a8099a25ee50aa67facb21034201c01417c796d86d339b5790c6ad87a0c95a73cc6221b0d2f33ef47ade05eaaf6d419a216884914a7
7
+ data.tar.gz: f5f091a10d094926a09e1357d832524ef76643b5fd730e51c854e64201d1f1e1d2a87ea9984d749c15dc4b484f3e3797c830a61f61c0c94b9277616dcb9581f5
@@ -1,3 +1,3 @@
1
1
  class UpcloudApi
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.1.0".freeze
3
3
  end
data/lib/upcloud_api.rb CHANGED
@@ -19,7 +19,7 @@ class UpcloudApi
19
19
  #
20
20
  # Calls GET /1.2/server
21
21
  #
22
- # Returns true in success, false if not.
22
+ # @return true in success, false if not.
23
23
  def login
24
24
  response = get "server"
25
25
  response.code == 200
@@ -29,7 +29,9 @@ class UpcloudApi
29
29
  #
30
30
  # Calls GET /1.2/server_size.
31
31
  #
32
- # Returns array of server size hashes:
32
+ # @return array of server size hashes
33
+ #
34
+ # @example Return hash
33
35
  # {
34
36
  # "core_number": "1",
35
37
  # "memory_amount": "512"
@@ -43,7 +45,7 @@ class UpcloudApi
43
45
  #
44
46
  # Calls GET /1.2/acccount
45
47
  #
46
- # Returns available credits in the account as a string.
48
+ # @return available credits in the account as a string.
47
49
  def account_information
48
50
  response = get "account"
49
51
  data = JSON.parse response.body
@@ -54,14 +56,16 @@ class UpcloudApi
54
56
  #
55
57
  # Calls GET /1.2/server.
56
58
  #
57
- # Returns array of servers with following values or empty array if no servers found.
58
- # - zone
59
- # - core_number
60
- # - title
61
- # - hostname
62
- # - memory_amount
63
- # - uuid
64
- # - state
59
+ # @return array of servers with following values or empty array if no servers found.
60
+ #
61
+ # @example Return values
62
+ # - zone
63
+ # - core_number
64
+ # - title
65
+ # - hostname
66
+ # - memory_amount
67
+ # - uuid
68
+ # - state
65
69
  def servers
66
70
  response = get "server"
67
71
  data = JSON.parse response.body
@@ -74,7 +78,9 @@ class UpcloudApi
74
78
  #
75
79
  # @param uuid from UpcloudApi#servers
76
80
  #
77
- # Returns hash of server details or nil:
81
+ # @return hash of server details or nil
82
+ #
83
+ # @example Return values
78
84
  # {
79
85
  # "boot_order" => "cdrom,disk",
80
86
  # "core_number" => "3",
@@ -137,8 +143,7 @@ class UpcloudApi
137
143
  #
138
144
  # Calls POST /1.2/server.
139
145
  #
140
- # Storage devices should be array of hashes containing following data:
141
- #
146
+ # @example Storage devices should be array of hashes containing following data
142
147
  # {
143
148
  # "action" => "clone" # Can be "create", "clone" or "attach"
144
149
  # "storage" => template_uuid, # Should be passed only for "clone" or "attach"
@@ -149,7 +154,7 @@ class UpcloudApi
149
154
  # @param plan [String] Preconfigured plan for the server. If nil, a custom plan will be created from input data, otherwise this overrides custom configuration.
150
155
  # Predefined plans can be fetched with {#plans}.
151
156
  #
152
- # login_user should be following hash or nil:
157
+ # @example login_user should be following hash or nil
153
158
  # {
154
159
  # "username": "upclouduser",
155
160
  # "ssh_keys": {
@@ -160,12 +165,12 @@ class UpcloudApi
160
165
  # }
161
166
  # }
162
167
  #
163
- # ip_addresses should be an array containing :public, :private and/or :ipv6. It defaults to
168
+ # @param ip_addresses should be an array containing :public, :private and/or :ipv6. It defaults to
164
169
  # :all, which means the server will get public IPv4, private IPv4 and public IPv6 addresses.
165
170
  #
166
171
  # @param other [Hash] Other optional arguments create_server API call takes. See Upcloud’s documentation for possible values.
167
172
  #
168
- # Returns HTTParty response object.
173
+ # @return HTTParty response object.
169
174
  def create_server(zone: "fi-hel1", title:, hostname:, core_number: 1,
170
175
  memory_amount: 1024, storage_devices:, ip_addresses: :all,
171
176
  plan: nil, login_user: nil, other: nil)
@@ -212,12 +217,12 @@ class UpcloudApi
212
217
  #
213
218
  # In order to modify a server, the server must be stopped first.
214
219
  #
215
- # Calls PUT /1.2/server/_uuid_.
220
+ # Calls PUT /1.2/server/_server_uuid_.
216
221
  #
217
222
  # @param server_uuid [String] UUID of the server that will be modified.
218
223
  # @param params [Hash] Hash of params that will be passed to be changed.
219
224
  #
220
- # Returns HTTParty response object.
225
+ # @return HTTParty response object.
221
226
  def modify_server(server_uuid, params)
222
227
  data = { "server" => params }
223
228
  json = JSON.generate data
@@ -230,9 +235,9 @@ class UpcloudApi
230
235
  #
231
236
  # In order to delete a server, the server must be stopped first.
232
237
  #
233
- # Calls DELETE /1.2/server/_uuid_.
238
+ # Calls DELETE /1.2/server/_server_uuid_.
234
239
  #
235
- # Returns HTTParty response object.
240
+ # @return HTTParty response object.
236
241
  def delete_server(server_uuid)
237
242
  response = delete "server/#{server_uuid}"
238
243
 
@@ -241,11 +246,11 @@ class UpcloudApi
241
246
 
242
247
  # Starts server that is shut down.
243
248
  #
244
- # Calls POST /1.2/server/_uuid_/start.
249
+ # Calls POST /1.2/server/_server_uuid_/start.
245
250
  #
246
251
  # @param server_uuid UUID of the server.
247
252
  #
248
- # Returns HTTParty response object.
253
+ # @return HTTParty response object.
249
254
  def start_server(server_uuid)
250
255
  response = post "server/#{server_uuid}/start"
251
256
 
@@ -264,16 +269,16 @@ class UpcloudApi
264
269
  #
265
270
  # @param server_uuid UUID of the server
266
271
  # @param type Type of the shutdown. Available types are :hard and :soft.
267
- # Defaults to :soft.
272
+ # Defaults to :soft.
268
273
  # @param timeout Time after server will be hard stopped if it did not
269
- # close cleanly. Only affects :soft type.
274
+ # close cleanly. Only affects :soft type.
270
275
  # @param asynchronous If false, this call will wait until the server
271
- # has really stopped.
276
+ # has really stopped.
272
277
  #
273
- # Raises Timeout::Error in case server does not shut down in 300
274
- # seconds in non-asynchronous mode.
278
+ # @raise Timeout::Error in case server does not shut down in 300
279
+ # seconds in non-asynchronous mode.
275
280
  #
276
- # Returns HTTParty response object if server was removed successfully or request is asynchronous and nil otherwise
281
+ # @return HTTParty response object if server was removed successfully or request is asynchronous and nil otherwise
277
282
  def stop_server(server_uuid, type: :soft, timeout: nil, asynchronous: false)
278
283
  data = {
279
284
  "stop_server" => {
@@ -311,14 +316,14 @@ class UpcloudApi
311
316
  #
312
317
  # @param server_uuid UUID of the server
313
318
  # @param type Type of the shutdown. Available types are :hard and :soft.
314
- # Defaults to :soft.
319
+ # Defaults to :soft.
315
320
  # @param timeout Time after server will be hard stopped if it did not
316
- # close cleanly. Only affects :soft type.
321
+ # close cleanly. Only affects :soft type.
317
322
  # @param timeout_action What will happen when timeout happens.
318
- # :destroy hard stops the server and :ignore stops the operation
319
- # if timeout happens. Default is :ignore.
323
+ # :destroy hard stops the server and :ignore stops the operation
324
+ # if timeout happens. Default is :ignore.
320
325
  #
321
- # Returns HTTParty response object.
326
+ # @return HTTParty response object.
322
327
  def restart_server(server_uuid, type: :soft, timeout: nil, timeout_action: :ignore)
323
328
  data = {
324
329
  "restart_server" => {
@@ -339,18 +344,18 @@ class UpcloudApi
339
344
  #
340
345
  # Calls GET /1.2/storage or /1.2/storage/_type_.
341
346
  #
342
- # Available types:
343
- # - public
344
- # - private
345
- # - normal
346
- # - backup
347
- # - cdrom
348
- # - template
349
- # - favorite
347
+ # @example Available types
348
+ # - public
349
+ # - private
350
+ # - normal
351
+ # - backup
352
+ # - cdrom
353
+ # - template
354
+ # - favorite
350
355
  #
351
356
  # @param type Type of the storages to be returned on nil.
352
357
  #
353
- # Returns array of storages, inside "storage" key in the API or empty array if none found.
358
+ # @return array of storages, inside "storage" key in the API or empty array if none found.
354
359
  def storages(type: nil)
355
360
  response = get(type && "storage/#{type}" || "storage")
356
361
  data = JSON.parse response.body
@@ -363,7 +368,8 @@ class UpcloudApi
363
368
  #
364
369
  # @param storage_uuid UUID of the storage.
365
370
  #
366
- # Returns hash of following storage details or nil:
371
+ # @return hash of following storage details or nil
372
+ # @example Return values
367
373
  # {
368
374
  # "access" => "public",
369
375
  # "license" => 0,
@@ -389,21 +395,21 @@ class UpcloudApi
389
395
  #
390
396
  # Calls POST /1.2/storage.
391
397
  #
392
- # backup_rule should be hash with following attributes:
393
- # - interval # allowed values: daily / mon / tue / wed / thu / fri / sat / sun
394
- # - time # allowed values: 0000-2359
395
- # - retention # How many days backup will be kept. Allowed values: 1-1095
398
+ # @example backup_rule should be hash with following attributes
399
+ # - interval # allowed values: daily / mon / tue / wed / thu / fri / sat / sun
400
+ # - time # allowed values: 0000-2359
401
+ # - retention # How many days backup will be kept. Allowed values: 1-1095
396
402
  #
397
403
  # @param size Size of the storage in gigabytes
398
404
  # @param tier Type of the disk. maxiops is SSD powered disk, other
399
- # allowed value is "hdd"
405
+ # allowed value is "hdd"
400
406
  # @param title Name of the disk
401
407
  # @param zone Where the disk will reside. Needs to be within same zone
402
- # with the server
408
+ # with the server
403
409
  # @param backup_rule Hash of backup information. If not given, no
404
- # backups will be automatically created.
410
+ # backups will be automatically created.
405
411
  #
406
- # Returns HTTParty response object.
412
+ # @return HTTParty response object.
407
413
  def create_storage(size:, tier: "maxiops", title:, zone: "fi-hel1",
408
414
  backup_rule: nil)
409
415
  data = {
@@ -426,18 +432,18 @@ class UpcloudApi
426
432
  #
427
433
  # Calls PUT /1.2/storage/_uuid_.
428
434
  #
429
- # backup_rule should be hash with following attributes:
430
- # - interval # allowed values: daily / mon / tue / wed / thu / fri / sat / sun
431
- # - time # allowed values: 0000-2359
432
- # - retention # How many days backup will be kept. Allowed values: 1-1095
435
+ # @example backup_rule should be hash with following attributes
436
+ # - interval # allowed values: daily / mon / tue / wed / thu / fri / sat / sun
437
+ # - time # allowed values: 0000-2359
438
+ # - retention # How many days backup will be kept. Allowed values: 1-1095
433
439
  #
434
440
  # @param storage_uuid UUID of the storage that will be modified
435
441
  # @param size Size of the storage in gigabytes
436
442
  # @param title Name of the disk
437
443
  # @param backup_rule Hash of backup information. If not given, no
438
- # backups will be automatically created.
444
+ # backups will be automatically created.
439
445
  #
440
- # Returns HTTParty response object.
446
+ # @return HTTParty response object.
441
447
  def modify_storage(storage_uuid, size:, title:, backup_rule: nil)
442
448
  data = {
443
449
  "storage" => {
@@ -462,12 +468,12 @@ class UpcloudApi
462
468
  #
463
469
  # @param storage_uuid UUID of the storage that will be modified
464
470
  # @param tier Type of the disk. maxiops is SSD powered disk, other
465
- # allowed value is "hdd"
471
+ # allowed value is "hdd"
466
472
  # @param title Name of the disk
467
473
  # @param zone Where the disk will reside. Needs to be within same zone
468
- # with the server
474
+ # with the server
469
475
  #
470
- # Returns HTTParty response object.
476
+ # @return HTTParty response object.
471
477
  def clone_storage(storage_uuid, zone: "fi-hel1", title:, tier: "maxiops")
472
478
  data = {
473
479
  "storage" => {
@@ -493,7 +499,7 @@ class UpcloudApi
493
499
  # @param storage_uuid UUID of the storage that will be templatized
494
500
  # @param title Name of the template storage
495
501
  #
496
- # Returns HTTParty response object.
502
+ # @return HTTParty response object.
497
503
  def templatize_storage(storage_uuid, title:)
498
504
  data = {
499
505
  "storage" => {
@@ -519,9 +525,9 @@ class UpcloudApi
519
525
  # @param storage_uuid UUID of the storage that will be attached.
520
526
  # @param type Type of the disk. Valid values are "disk" and "cdrom".
521
527
  # @param address Address where the disk will be attached to. Defaults
522
- # to next available address.
528
+ # to next available address.
523
529
  #
524
- # Returns HTTParty response object.
530
+ # @return HTTParty response object.
525
531
  def attach_storage(server_uuid, storage_uuid:, type: "disk", address: nil)
526
532
  data = {
527
533
  "storage_device" => {
@@ -546,7 +552,7 @@ class UpcloudApi
546
552
  # @param server_uuid UUID of the server from which to detach the storage.
547
553
  # @param address Address where the storage that will be detached resides.
548
554
  #
549
- # Returns HTTParty response object.
555
+ # @return HTTParty response object.
550
556
  def detach_storage(server_uuid, address:)
551
557
  data = {
552
558
  "storage_device" => {
@@ -570,7 +576,7 @@ class UpcloudApi
570
576
  # @param storage_uuid UUID of the storage to be backed-up
571
577
  # @param title Name of the backup
572
578
  #
573
- # Returns HTTParty response object.
579
+ # @return HTTParty response object.
574
580
  def create_backup(storage_uuid, title:)
575
581
  data = {
576
582
  "storage" => {
@@ -593,7 +599,7 @@ class UpcloudApi
593
599
  #
594
600
  # @param backup_uuid UUID of the backup
595
601
  #
596
- # Returns HTTParty response object.
602
+ # @return HTTParty response object.
597
603
  def restore_backup(backup_uuid)
598
604
  response = post "storage/#{backup_uuid}/restore"
599
605
 
@@ -606,7 +612,7 @@ class UpcloudApi
606
612
  #
607
613
  # @param storage_uuid UUID of the storage to be included in favorites
608
614
  #
609
- # Returns HTTParty response object.
615
+ # @return HTTParty response object.
610
616
  def favorite_storage(storage_uuid)
611
617
  response = post "storage/#{storage_uuid}/favorite"
612
618
 
@@ -619,7 +625,7 @@ class UpcloudApi
619
625
  #
620
626
  # @param storage_uuid UUID of the storage to be removed from favorites
621
627
  #
622
- # Returns HTTParty response object.
628
+ # @return HTTParty response object.
623
629
  def defavorite_storage(storage_uuid)
624
630
  response = delete "storage/#{storage_uuid}/favorite"
625
631
 
@@ -634,7 +640,7 @@ class UpcloudApi
634
640
  #
635
641
  # @param storage_uuid UUID of the storage that will be deleted.
636
642
  #
637
- # Returns HTTParty response object.
643
+ # @return HTTParty response object.
638
644
  def delete_storage(storage_uuid)
639
645
  response = delete "storage/#{storage_uuid}"
640
646
 
@@ -643,7 +649,8 @@ class UpcloudApi
643
649
 
644
650
  # Lists available predefined plans that can be used to create a server.
645
651
  #
646
- # Returns Array of plan hashes:
652
+ # @return Array of plan hashes
653
+ # @example Return values
647
654
  # [
648
655
  # {
649
656
  # "core_number" : 1,
@@ -661,6 +668,353 @@ class UpcloudApi
661
668
  data["plans"]["plan"]
662
669
  end
663
670
 
671
+ # Lists firewall rules of a server.
672
+ #
673
+ # Calls POST /1.2/server/_uuid_/firewall_rule.
674
+ #
675
+ # @param server_uuid [String] UUID of server
676
+ #
677
+ # @return Array of firewall rules
678
+ # @example Return values
679
+ # [
680
+ # {
681
+ # "action": "accept",
682
+ # "destination_address_end": "",
683
+ # "destination_address_start": "",
684
+ # "destination_port_end": "80",
685
+ # "destination_port_start": "80",
686
+ # "direction": "in",
687
+ # "family": "IPv4",
688
+ # "icmp_type": "",
689
+ # "position": "1",
690
+ # "protocol": "",
691
+ # "source_address_end": "",
692
+ # "source_address_start": "",
693
+ # "source_port_end": "",
694
+ # "source_port_start": ""
695
+ # }
696
+ # ]
697
+ def firewall_rules server_uuid
698
+ response = get "server/#{server_uuid}/firewall_rule"
699
+
700
+ data = JSON.parse response.body
701
+ data["firewall_rules"]["firewall_rule"]
702
+ end
703
+
704
+
705
+ # Creates new firewall rule to a server specified by _server_uuid_.
706
+ #
707
+ # Calls POST /1.2/server/_server_uuid_/firewall_rule.
708
+ #
709
+ # _params_ should contain data as documented in Upcloud’s API:
710
+ # https://www.upcloud.com/api/1.2.3/11-firewall/#create-firewall-rule .
711
+ # It should not contain "firewall_rule" wrapper hash, but only the values inside a hash.
712
+ #
713
+ # @example _params_ contents
714
+ # {
715
+ # "position": "1",
716
+ # "direction": "in",
717
+ # "family": "IPv4",
718
+ # "protocol": "tcp",
719
+ # "source_address_start": "192.168.1.1",
720
+ # "source_address_end": "192.168.1.255",
721
+ # "source_port_end": "",
722
+ # "source_port_start": "",
723
+ # "destination_address_start": "",
724
+ # "destination_address_end": "",
725
+ # "destination_port_start": "22",
726
+ # "destination_port_end": "22",
727
+ # "icmp_type": "",
728
+ # "action": "accept"
729
+ # }
730
+ #
731
+ # @param server_uuid [String] UUID of server
732
+ # @param params [Hash] Parameters for the firewall rule.
733
+ #
734
+ # @return HTTParty response object.
735
+ def create_firewall_rule server_uuid, params
736
+ data = {
737
+ "firewall_rule" => params
738
+ }
739
+
740
+ json = JSON.generate data
741
+
742
+ response = post "server/#{server_uuid}/firewall_rule", json
743
+
744
+ response
745
+ end
746
+
747
+ # Removes a firewall rule at position _position_.
748
+ #
749
+ # Calls DELETE /1.2/server/_server_uuid_/firewall_rule/_position_.
750
+ #
751
+ # A position of a rule can be seen with firewall_rules().
752
+ #
753
+ # @param server_uuid [String] UUID of server
754
+ # @param position [Integer] position of the rule in rule list that will be removed
755
+ #
756
+ # @return HTTParty response object.
757
+ def remove_firewall_rule server_uuid, position
758
+ response = delete "server/#{server_uuid}/firewall_rule/#{position}"
759
+
760
+ response
761
+ end
762
+
763
+ # Lists all tags with UUIDs of servers they are attached to.
764
+ #
765
+ # Calls GET /1.2/tags.
766
+ #
767
+ # @return Array of tag hashes
768
+ # @example Return values
769
+ # [
770
+ # {
771
+ # "description": "Development servers",
772
+ # "name": "DEV",
773
+ # "servers": {
774
+ # "server": [
775
+ # "0077fa3d-32db-4b09-9f5f-30d9e9afb565"
776
+ # ]
777
+ # }
778
+ # }
779
+ # ]
780
+ def tags
781
+ response = get "tags"
782
+
783
+ data = JSON.parse response.body
784
+ data["tags"]["tag"]
785
+ end
786
+
787
+ # Creates new tag.
788
+ #
789
+ # Calls POST /1.2/tag.
790
+ #
791
+ # _params_ should contain following data
792
+ # name *required*
793
+ # description
794
+ # servers *required*
795
+ #
796
+ # @example _params_ hash’s contents
797
+ # {
798
+ # "name": "DEV", # required
799
+ # "description": "Development servers",
800
+ # "servers": [
801
+ # "0077fa3d-32db-4b09-9f5f-30d9e9afb565",
802
+ # ".."
803
+ # ]
804
+ # }
805
+ #
806
+ # @example Response body
807
+ # {
808
+ # "name": "DEV",
809
+ # "description": "Development servers",
810
+ # "servers": {
811
+ # "server": [
812
+ # "0077fa3d-32db-4b09-9f5f-30d9e9afb565"
813
+ # ]
814
+ # }
815
+ # }
816
+ #
817
+ # @param server_uuid [String] UUID of server
818
+ # @param params [Hash] Parameters for the firewall rule.
819
+ #
820
+ # @return Tag parameters as Hash or HTTParty response object in case of error.
821
+ def create_tag server_uuid, params
822
+ data = {
823
+ "tag" => params
824
+ }
825
+ temp = data["servers"]
826
+ data["servers"] = { "server" => temp }
827
+
828
+ json = JSON.generate data
829
+
830
+ response = post "tag", json
831
+ return response unless response.code == 201
832
+
833
+ body = JSON.parse response.body
834
+ body["tag"]
835
+ end
836
+
837
+ # Modifies existing tag.
838
+ #
839
+ # Calls PUT /1.2/tag/_tag_.
840
+ #
841
+ # @note Attributes are same as with create_tag().
842
+ #
843
+ # @return Tag parameters as Hash or HTTParty response object in case of error.
844
+ def modify_tag tag
845
+ data = {
846
+ "tag" => params
847
+ }
848
+ temp = data["servers"]
849
+ data["servers"] = { "server" => temp }
850
+
851
+ json = JSON.generate data
852
+
853
+ response = put "tag/#{tag}", json
854
+ return response unless response.code == 200
855
+
856
+ body = JSON.parse response.body
857
+ body["tag"]
858
+ end
859
+
860
+ # Deletes existing tag.
861
+ #
862
+ # Calls DELETE /1.2/tag/_tag_.
863
+ #
864
+ # @return HTTParty response object.
865
+ def delete_tag tag
866
+ delete "tag/#{tag}"
867
+ end
868
+
869
+ # Attaches one or more tags to a server.
870
+ #
871
+ # Calls POST /1.2/server/_uuid_/tag/_tags_.
872
+ #
873
+ # @param server_uuid [String] UUID of the server
874
+ # @param tags [Array, String] Tags that will be attached to the server
875
+ #
876
+ # @return HTTParty response object.
877
+ def add_tag_to_server server_uuid, tags
878
+ tag = (tags.respond_to? :join && tags.join(",") || tags)
879
+
880
+ post "server/#{server_uuid}/tag/#{tag}"
881
+ end
882
+
883
+ # Removes one or more tags to a server.
884
+ #
885
+ # Calls POST /1.2/server/_uuid_/untag/_tags_.
886
+ #
887
+ # @param server_uuid [String] UUID of the server
888
+ # @param tags [Array, String] Tags that will be removed from the server
889
+ #
890
+ # @return HTTParty response object.
891
+ def remove_tag_from_server server_uuid, tags
892
+ tag = (tags.respond_to? :join && tags.join(",") || tags)
893
+
894
+ post "server/#{server_uuid}/untag/#{tag}"
895
+ end
896
+
897
+ # Lists all IP addresses visible to user specified in contructor along with
898
+ # their information and UUIDs of the servers they are bound to.
899
+ #
900
+ # Calls GET /1.2/ip_address.
901
+ #
902
+ # @return [Hash] details of IP addresses
903
+ # @example Return hash
904
+ # [
905
+ # {
906
+ # "access": "private",
907
+ # "address": "10.0.0.0",
908
+ # "family": "IPv4",
909
+ # "ptr_record": "",
910
+ # "server": "0053cd80-5945-4105-9081-11192806a8f7"
911
+ # }
912
+ # ]
913
+ def ip_addresses
914
+ response = get "ip_address"
915
+ body = JSON.parse response.body
916
+ body["ip_addresses"]["ip_address"]
917
+ end
918
+
919
+ # Gives details of specific IP address.
920
+ #
921
+ # Calls GET /1.2/ip_address/_ip_address_.
922
+ #
923
+ # @param ip_address [String] IP address to get details for.
924
+ #
925
+ # @return [Hash] details of an IP address
926
+ # @example Return hash
927
+ # {
928
+ # "access": "public",
929
+ # "address": "0.0.0.0"
930
+ # "family": "IPv4",
931
+ # "part_of_plan": "yes",
932
+ # "ptr_record": "test.example.com",
933
+ # "server": "009d64ef-31d1-4684-a26b-c86c955cbf46",
934
+ # }
935
+ def ip_address_details ip_address
936
+ response = get "ip_address/#{ip_address}"
937
+ body = JSON.parse response.body
938
+ body["ip_address"]
939
+ end
940
+
941
+ # Adds new IP address to given server.
942
+ #
943
+ # Calls POST /1.2/ip_address.
944
+ #
945
+ # @note To add a new IP address, the server must be stopped.
946
+ # @note Only public IP addresses can be added. There is always exactly one private IP address per server.
947
+ # @note There is a maximum of five public IP addresses per server.
948
+ #
949
+ # @param server_uuid [String] UUID of the server
950
+ # @param family ["IPv4", "IPv6"] Type of the IP address.
951
+ #
952
+ # @see https://www.upcloud.com/api/1.2.3/10-ip-addresses/#assign-ip-address Upcloud’s API
953
+ #
954
+ # @return HTTParty response object.
955
+ def new_ip_address_to_server server_uuid, family: "IPv4"
956
+ data = {
957
+ "ip_address" => {
958
+ "family" => family,
959
+ "server" => server_uuid
960
+ }
961
+ }
962
+ json = JSON.generate data
963
+
964
+ post "ip_address", json
965
+ end
966
+
967
+ # Changes given IP address’s PTR record.
968
+ #
969
+ # Calls PUT /1.2/ip_address.
970
+ #
971
+ # @note Can only be set to public IP addresses.
972
+ #
973
+ # @return HTTParty response object.
974
+ def change_ip_address_ptr ip_address, ptr_record
975
+ data = {
976
+ "ip_address" => {
977
+ "ptr_record" => ptr_record
978
+ }
979
+ }
980
+ json = JSON.generate data
981
+
982
+ put "ip_address/#{ip_address}", json
983
+ end
984
+
985
+ # Removes IP address (from a server).
986
+ #
987
+ # Calls DELETE /1.2/_ip_address_.
988
+ #
989
+ # @todo I’m fairly sure the API call is wrong, but this is what their documentation says. Please tell me if you test if this one works.
990
+ #
991
+ # @return HTTParty response object.
992
+ def remove_ip_address ip_address
993
+ delete "#{ip_address}"
994
+ end
995
+
996
+ # Lists prices for specific components that can be tied to a server.
997
+ #
998
+ # @see https://www.upcloud.com/api/1.2.3/4-pricing/ Upcloud’s documentation for more details.
999
+ #
1000
+ # @return [Array] list of prices per component
1001
+ def prices
1002
+ response = get "price"
1003
+ body = JSON.parse response.body
1004
+ body["prices"]["zone"]
1005
+ end
1006
+
1007
+ # Lists available zones and their details.
1008
+ #
1009
+ # @see https://www.upcloud.com/api/1.2.3/5-zones/ Upcloud’s zone documentation for more details
1010
+ #
1011
+ # @return [Array] list of zones
1012
+ def zones
1013
+ response = get "zone"
1014
+ body = JSON.parse response.body
1015
+ body["zones"]["zone"]
1016
+ end
1017
+
664
1018
  private
665
1019
 
666
1020
  def get(action)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upcloud_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samu Voutilainen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-27 00:00:00.000000000 Z
12
+ date: 2017-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  requirements: []
56
56
  rubyforge_project:
57
- rubygems_version: 2.5.1
57
+ rubygems_version: 2.5.2
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: Implementation of Upcloud API for VPS management