class OneAndOne::Server
Attributes
first_ip[RW]
first_password[RW]
id[RW]
specs[RW]
Public Class Methods
new(test: false)
click to toggle source
# 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
Public Instance Methods
add_firewall(server_id: @id, ip_id: nil, firewall_id: nil)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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'] = 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/1and1/server.rb, line 231 def get_baremetal(baremetal_id: @id) # If user passed in baremetal ID, reassign @id = baremetal_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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/1and1/server.rb, line 60 def list_baremetal_models(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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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