Class: OneAndOne::Server
- Inherits:
-
Object
- Object
- OneAndOne::Server
- Defined in:
- lib/1and1/server.rb
Instance Attribute Summary collapse
-
#first_ip ⇒ Object
Returns the value of attribute first_ip.
-
#first_password ⇒ Object
Returns the value of attribute first_password.
-
#id ⇒ Object
Returns the value of attribute id.
-
#specs ⇒ Object
Returns the value of attribute specs.
Instance Method Summary collapse
- #add_firewall(server_id: @id, ip_id: nil, firewall_id: nil) ⇒ Object
- #add_hdds(server_id: @id, hdds: nil) ⇒ Object
- #add_ip(server_id: @id, ip_type: nil) ⇒ Object
- #add_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil) ⇒ Object
- #add_private_network(server_id: @id, private_network_id: nil) ⇒ Object
- #change_status(server_id: @id, action: nil, method: nil, recovery_mode: nil, recovery_image_id: nil) ⇒ Object
- #check_state(response) ⇒ Object
- #clone(server_id: @id, name: nil, datacenter_id: nil) ⇒ Object
- #create(name: nil, description: nil, rsa_key: nil, fixed_instance_id: nil, vcore: nil, cores_per_processor: nil, ram: nil, appliance_id: nil, datacenter_id: nil, hdds: nil, password: nil, power_on: nil, firewall_id: nil, ip_id: nil, load_balancer_id: nil, monitoring_policy_id: nil, public_key: nil, server_type: nil, baremetal_model_id: nil) ⇒ Object
- #create_snapshot(server_id: @id) ⇒ Object
- #delete(server_id: @id, keep_ips: nil) ⇒ Object
- #delete_hdd(server_id: @id, hdd_id: nil) ⇒ Object
- #delete_snapshot(server_id: @id, snapshot_id: nil) ⇒ Object
- #dvd(server_id: @id) ⇒ Object
- #eject_dvd(server_id: @id) ⇒ Object
- #firewall(server_id: @id, ip_id: nil) ⇒ Object
- #get(server_id: @id) ⇒ Object
- #get_baremetal(baremetal_id: @id) ⇒ Object
- #get_fixed(fixed_instance_id: nil) ⇒ Object
- #get_hdd(server_id: @id, hdd_id: nil) ⇒ Object
- #hardware(server_id: @id) ⇒ Object
- #hdds(server_id: @id) ⇒ Object
- #image(server_id: @id) ⇒ Object
-
#initialize(test: false) ⇒ Server
constructor
A new instance of Server.
- #install_image(server_id: @id, image_id: nil, password: nil, firewall_id: nil) ⇒ Object
- #ip(server_id: @id, ip_id: nil) ⇒ Object
- #ips(server_id: @id) ⇒ Object
- #list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil) ⇒ Object
- #list_baremetal_models(page: nil, per_page: nil, sort: nil, q: nil, fields: nil) ⇒ Object
- #list_fixed ⇒ Object
- #load_balancers(server_id: @id, ip_id: nil) ⇒ Object
- #load_dvd(server_id: @id, dvd_id: nil) ⇒ Object
- #modify(server_id: @id, name: nil, description: nil) ⇒ Object
- #modify_hardware(server_id: @id, fixed_instance_id: nil, vcore: nil, cores_per_processor: nil, ram: nil) ⇒ Object
- #modify_hdd(server_id: @id, hdd_id: nil, size: nil) ⇒ Object
- #parser(response) ⇒ Object
- #private_network(server_id: @id, private_network_id: nil) ⇒ Object
- #private_networks(server_id: @id) ⇒ Object
- #release_ip(server_id: @id, ip_id: nil, keep_ip: nil) ⇒ Object
- #reload ⇒ Object
- #remove_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil) ⇒ Object
- #remove_private_network(server_id: @id, private_network_id: nil) ⇒ Object
- #restore_snapshot(server_id: @id, snapshot_id: nil) ⇒ Object
- #snapshot(server_id: @id) ⇒ Object
- #status(server_id: @id) ⇒ Object
- #wait_deleted(server_id: @id, timeout: 25, interval: 15) ⇒ Object
- #wait_for(timeout: 25, interval: 15) ⇒ Object
Constructor Details
#initialize(test: false) ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/1and1/server.rb', line 13 def initialize(test: false) @id = nil @first_ip = nil @first_password = nil @specs = nil # Check if hitting mock api or live api if test @connection = Excon.new($base_url, :mock => true) else @connection = Excon.new($base_url) end end |
Instance Attribute Details
#first_ip ⇒ Object
Returns the value of attribute first_ip.
8 9 10 |
# File 'lib/1and1/server.rb', line 8 def first_ip @first_ip end |
#first_password ⇒ Object
Returns the value of attribute first_password.
9 10 11 |
# File 'lib/1and1/server.rb', line 9 def first_password @first_password end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/1and1/server.rb', line 7 def id @id end |
#specs ⇒ Object
Returns the value of attribute specs.
10 11 12 |
# File 'lib/1and1/server.rb', line 10 def specs @specs end |
Instance Method Details
#add_firewall(server_id: @id, ip_id: nil, firewall_id: nil) ⇒ Object
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
# File 'lib/1and1/server.rb', line 688 def add_firewall(server_id: @id, ip_id: nil, firewall_id: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body firewall_specs = { 'id' => firewall_id } # Clean out null keys in PUT body body = OneAndOne.clean_hash(firewall_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/firewall_policy") # Perform request response = @connection.request(:method => :put, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#add_hdds(server_id: @id, hdds: nil) ⇒ Object
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/1and1/server.rb', line 407 def add_hdds(server_id: @id, hdds: nil) # If user passed in server ID, reassign @id = server_id # Build POST body new_hdds = { 'hdds' => hdds } # Stringify the POST body string_body = new_hdds.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds") # Perform request response = @connection.request(:method => :post, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#add_ip(server_id: @id, ip_type: nil) ⇒ Object
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/1and1/server.rb', line 599 def add_ip(server_id: @id, ip_type: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body ip_specs = { 'type' => ip_type } # Clean out null keys in PUT body body = OneAndOne.clean_hash(ip_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips") # Perform Request response = @connection.request(:method => :post, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#add_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil) ⇒ Object
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 |
# File 'lib/1and1/server.rb', line 766 def add_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body load_balancer_specs = { 'load_balancer_id' => load_balancer_id } # Clean out null keys in PUT body body = OneAndOne.clean_hash(load_balancer_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers") # Perform request response = @connection.request(:method => :post, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#add_private_network(server_id: @id, private_network_id: nil) ⇒ Object
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 |
# File 'lib/1and1/server.rb', line 1026 def add_private_network(server_id: @id, private_network_id: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body private_network_specs = { 'id' => private_network_id } # Clean out null keys in PUT body body = OneAndOne.clean_hash(private_network_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/private_networks") # Perform request response = @connection.request(:method => :post, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#change_status(server_id: @id, action: nil, method: nil, recovery_mode: nil, recovery_image_id: nil) ⇒ Object
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 |
# File 'lib/1and1/server.rb', line 844 def change_status(server_id: @id, action: nil, method: nil, recovery_mode: nil, recovery_image_id: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body status_specs = { 'action' => action, 'method' => method } status_specs['recovery_mode'] = recovery_mode unless recovery_mode.nil? status_specs['recovery_image_id'] = recovery_image_id unless recovery_image_id.nil? # Clean out null keys in PUT body body = OneAndOne.clean_hash(status_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/status/action") # Perform request response = @connection.request(:method => :put, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#check_state(response) ⇒ Object
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 |
# File 'lib/1and1/server.rb', line 1191 def check_state(response) # Parse out server state and percent from response state = response['status']['state'] percent = response['status']['percent'] # This is the ideal server state we are looking for ($good_states.include? state) && (percent == nil) end |
#clone(server_id: @id, name: nil, datacenter_id: nil) ⇒ Object
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 |
# File 'lib/1and1/server.rb', line 1148 def clone(server_id: @id, name: nil, datacenter_id: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body clone_specs = { 'name' => name, 'datacenter_id' => datacenter_id } # Clean out null keys in PUT body body = OneAndOne.clean_hash(clone_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/clone") # Perform request response = @connection.request(:method => :post, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#create(name: nil, description: nil, rsa_key: nil, fixed_instance_id: nil, vcore: nil, cores_per_processor: nil, ram: nil, appliance_id: nil, datacenter_id: nil, hdds: nil, password: nil, power_on: nil, firewall_id: nil, ip_id: nil, load_balancer_id: nil, monitoring_policy_id: nil, public_key: nil, server_type: nil, baremetal_model_id: nil) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/1and1/server.rb', line 92 def create(name: nil, description: nil, rsa_key: nil, fixed_instance_id: nil, vcore: nil, cores_per_processor: nil, ram: nil, appliance_id: nil, datacenter_id: nil, hdds: nil, password: nil, power_on: nil, firewall_id: nil, ip_id: nil, load_balancer_id: nil, monitoring_policy_id: nil, public_key: nil, server_type: nil, baremetal_model_id: nil) server_type = 'cloud' if server_type.nil? # Build hardware hash hardware_params = { 'fixed_instance_size_id' => fixed_instance_id, 'vcore' => vcore, 'cores_per_processor' => cores_per_processor, 'ram' => ram, 'hdds' => hdds } hardware_params['baremetal_model_id'] = if server_type == 'baremetal' # Clean out null keys in hardware hash hardware = OneAndOne.clean_hash(hardware_params) # Build POST body new_server = { 'name' => name, 'description' => description, 'hardware' => hardware, 'appliance_id' => appliance_id, 'datacenter_id' => datacenter_id, 'rsa_key' => rsa_key, 'password' => password, 'power_on' => power_on, 'firewall_policy_id' => firewall_id, 'ip_id' => ip_id, 'load_balancer_id' => load_balancer_id, 'monitoring_policy_id' => monitoring_policy_id, 'public_key' => public_key, 'server_type' => server_type } # Clean out null keys in POST body body = OneAndOne.clean_hash(new_server) # Stringify the POST body string_body = body.to_json # Build URL path = OneAndOne.build_url('/servers') # Perform request response = @connection.request(:method => :post, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string json = JSON.parse(response.body) # Save new server ID to Server instance @specs = json @id = json['id'] @first_password = json['first_password'] # If all good, return JSON json end |
#create_snapshot(server_id: @id) ⇒ Object
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 |
# File 'lib/1and1/server.rb', line 1060 def create_snapshot(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/snapshots") # Perform request response = @connection.request(:method => :post, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#delete(server_id: @id, keep_ips: nil) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/1and1/server.rb', line 294 def delete(server_id: @id, keep_ips: nil) # If user passed in server ID, reassign @id = server_id # Build hash for query parameters keyword_args = { 'keep_ips' => keep_ips } # Clean out null query parameters params = OneAndOne.clean_hash(keyword_args) # Build URL path = OneAndOne.build_url("/servers/#{@id}") # Perform request response = @connection.request(:method => :delete, :path => path, :headers => $header, :query => params) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#delete_hdd(server_id: @id, hdd_id: nil) ⇒ Object
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/1and1/server.rb', line 494 def delete_hdd(server_id: @id, hdd_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}") # Perform request response = @connection.request(:method => :delete, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#delete_snapshot(server_id: @id, snapshot_id: nil) ⇒ Object
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
# File 'lib/1and1/server.rb', line 1126 def delete_snapshot(server_id: @id, snapshot_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/snapshots/#{snapshot_id}") # Perform request response = @connection.request(:method => :delete, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#dvd(server_id: @id) ⇒ Object
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
# File 'lib/1and1/server.rb', line 882 def dvd(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/dvd") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#eject_dvd(server_id: @id) ⇒ Object
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 |
# File 'lib/1and1/server.rb', line 938 def eject_dvd(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/dvd") # Perform request response = @connection.request(:method => :delete, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#firewall(server_id: @id, ip_id: nil) ⇒ Object
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'lib/1and1/server.rb', line 722 def firewall(server_id: @id, ip_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/firewall_policy") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#get(server_id: @id) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/1and1/server.rb', line 203 def get(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string json = JSON.parse(response.body) # Reload specs attribute @specs = json # If all good, return JSON json end |
#get_baremetal(baremetal_id: @id) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/1and1/server.rb', line 231 def (baremetal_id: @id) # If user passed in baremetal ID, reassign @id = # Build URL path = OneAndOne.build_url("/servers/baremetal_models/#{@id}") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string json = JSON.parse(response.body) # Reload specs attribute @specs = json # If all good, return JSON json end |
#get_fixed(fixed_instance_id: nil) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/1and1/server.rb', line 184 def get_fixed(fixed_instance_id: nil) # Build URL path = OneAndOne.build_url("/servers/fixed_instance_sizes/#{fixed_instance_id}") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#get_hdd(server_id: @id, hdd_id: nil) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/1and1/server.rb', line 438 def get_hdd(server_id: @id, hdd_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#hardware(server_id: @id) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/1and1/server.rb', line 325 def hardware(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/hardware") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#hdds(server_id: @id) ⇒ Object
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/1and1/server.rb', line 385 def hdds(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#image(server_id: @id) ⇒ Object
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/1and1/server.rb', line 516 def image(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/image") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#install_image(server_id: @id, image_id: nil, password: nil, firewall_id: nil) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/1and1/server.rb', line 538 def install_image(server_id: @id, image_id: nil, password: nil, firewall_id: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body image_specs = { 'id' => image_id, 'password' => password, 'firewall_policy' => { 'id' => firewall_id } } # Clean out null keys in PUT body body = OneAndOne.clean_hash(image_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/image") # Perform Request response = @connection.request(:method => :put, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#ip(server_id: @id, ip_id: nil) ⇒ Object
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 |
# File 'lib/1and1/server.rb', line 633 def ip(server_id: @id, ip_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#ips(server_id: @id) ⇒ Object
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/1and1/server.rb', line 577 def ips(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/1and1/server.rb', line 29 def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil) # Build hash for query parameters keyword_args = { :page => page, :per_page => per_page, :sort => sort, :q => q, :fields => fields } # Clean out null query parameters params = OneAndOne.clean_hash(keyword_args) # Build URL path = OneAndOne.build_url('/servers') # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header, :query => params) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#list_baremetal_models(page: nil, per_page: nil, sort: nil, q: nil, fields: nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/1and1/server.rb', line 60 def (page: nil, per_page: nil, sort: nil, q: nil, fields: nil) # Build hash for query parameters keyword_args = { :page => page, :per_page => per_page, :sort => sort, :q => q, :fields => fields } # Clean out null query parameters params = OneAndOne.clean_hash(keyword_args) # Build URL path = OneAndOne.build_url('/servers/baremetal_models') # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header, :query => params) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#list_fixed ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/1and1/server.rb', line 165 def list_fixed # Build URL path = OneAndOne.build_url('/servers/fixed_instance_sizes') # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#load_balancers(server_id: @id, ip_id: nil) ⇒ Object
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/1and1/server.rb', line 744 def load_balancers(server_id: @id, ip_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#load_dvd(server_id: @id, dvd_id: nil) ⇒ Object
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 |
# File 'lib/1and1/server.rb', line 904 def load_dvd(server_id: @id, dvd_id: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body dvd_specs = { 'id' => dvd_id } # Clean out null keys in PUT body body = OneAndOne.clean_hash(dvd_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/dvd") # Perform request response = @connection.request(:method => :put, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#modify(server_id: @id, name: nil, description: nil) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/1and1/server.rb', line 259 def modify(server_id: @id, name: nil, description: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body server_specs = { 'name' => name, 'description' => description } # Clean out null keys in PUT body body = OneAndOne.clean_hash(server_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}") # Perform Request response = @connection.request(:method => :put, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#modify_hardware(server_id: @id, fixed_instance_id: nil, vcore: nil, cores_per_processor: nil, ram: nil) ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/1and1/server.rb', line 347 def modify_hardware(server_id: @id, fixed_instance_id: nil, vcore: nil, cores_per_processor: nil, ram: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body hardware_specs = { 'fixed_instance_size_id' => fixed_instance_id, 'vcore' => vcore, 'cores_per_processor' => cores_per_processor, 'ram' => ram } # Clean out null keys in PUT body body = OneAndOne.clean_hash(hardware_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/hardware") # Perform Request response = @connection.request(:method => :put, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#modify_hdd(server_id: @id, hdd_id: nil, size: nil) ⇒ Object
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/1and1/server.rb', line 460 def modify_hdd(server_id: @id, hdd_id: nil, size: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body hdd_specs = { 'size' => size } # Clean out null keys in PUT body body = OneAndOne.clean_hash(hdd_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}") # Perform Request response = @connection.request(:method => :put, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#parser(response) ⇒ Object
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 |
# File 'lib/1and1/server.rb', line 1203 def parser(response) # Check for first IP ips = response['ips'] if ips.length == 1 @first_ip = ips[0] end end |
#private_network(server_id: @id, private_network_id: nil) ⇒ Object
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 |
# File 'lib/1and1/server.rb', line 982 def private_network(server_id: @id, private_network_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/private_networks/#{private_network_id}") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#private_networks(server_id: @id) ⇒ Object
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 |
# File 'lib/1and1/server.rb', line 960 def private_networks(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/private_networks") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#release_ip(server_id: @id, ip_id: nil, keep_ip: nil) ⇒ Object
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/1and1/server.rb', line 654 def release_ip(server_id: @id, ip_id: nil, keep_ip: nil) # If user passed in server ID, reassign @id = server_id # Build PUT body ip_specs = { 'keep_ip' => keep_ip } # Clean out null keys in PUT body body = OneAndOne.clean_hash(ip_specs) # Stringify the PUT body string_body = body.to_json # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}") # Perform request response = @connection.request(:method => :delete, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#reload ⇒ Object
1183 1184 1185 1186 1187 1188 |
# File 'lib/1and1/server.rb', line 1183 def reload # This reload fx is just a wrapper for the get fx get end |
#remove_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil) ⇒ Object
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 |
# File 'lib/1and1/server.rb', line 800 def remove_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers/#{load_balancer_id}") # Perform request response = @connection.request(:method => :delete, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#remove_private_network(server_id: @id, private_network_id: nil) ⇒ Object
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
# File 'lib/1and1/server.rb', line 1004 def remove_private_network(server_id: @id, private_network_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/private_networks/#{private_network_id}") # Perform request response = @connection.request(:method => :delete, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#restore_snapshot(server_id: @id, snapshot_id: nil) ⇒ Object
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 |
# File 'lib/1and1/server.rb', line 1104 def restore_snapshot(server_id: @id, snapshot_id: nil) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/snapshots/#{snapshot_id}") # Perform request response = @connection.request(:method => :put, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#snapshot(server_id: @id) ⇒ Object
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 |
# File 'lib/1and1/server.rb', line 1082 def snapshot(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/snapshots") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#status(server_id: @id) ⇒ Object
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/1and1/server.rb', line 822 def status(server_id: @id) # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}/status") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end |
#wait_deleted(server_id: @id, timeout: 25, interval: 15) ⇒ Object
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 |
# File 'lib/1and1/server.rb', line 1251 def wait_deleted(server_id: @id, timeout: 25, interval: 15) # Capture start time start = Time.now # If user passed in server ID, reassign @id = server_id # Build URL path = OneAndOne.build_url("/servers/#{@id}") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # OneAndOne.check_response(response.body, response.status) puts "before until #{response.status}" # Keep polling the server's state until 404 until response.status == 404 # Wait 15 seconds before polling again sleep interval puts "checking server deleted status #{response.status}" # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Calculate current duration and check for timeout duration = (Time.now - start) / 60 if duration > timeout puts "The operation timed out after #{timeout} minutes.\n" return end end # Return Duration {:duration => duration} end |
#wait_for(timeout: 25, interval: 15) ⇒ Object
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/1and1/server.rb', line 1215 def wait_for(timeout: 25, interval: 15) # Capture start time start = Time.now # Poll server and check initial state initial_response = get server_state = check_state(initial_response) # Keep polling the server's state until good until server_state # Wait 15 seconds before polling again sleep interval # Check server state and percent again current_response = get server_state = check_state(current_response) # Calculate current duration and check for timeout duration = (Time.now - start) / 60 if duration > timeout puts "The operation timed out after #{timeout} minutes.\n" return end # Parse for first IP parser(current_response) end # Return Duration {:duration => duration} end |