[hp|compute_v2] Add request methods for console, along with tests.

This commit is contained in:
Rupak Ganguly 2013-04-30 10:28:44 -04:00
parent 0740d40a7d
commit 5b3ba81469
5 changed files with 109 additions and 25 deletions

View File

@ -29,7 +29,6 @@ module Fog
#request :allocate_address
#request :associate_address
#request :attach_volume
#request :change_password_server
#request :confirm_resized_server
request :create_image
request :create_key_pair
@ -42,14 +41,14 @@ module Fog
#request :detach_volume
#request :disassociate_address
#request :get_address
#request :get_console_output
request :get_console_output
request :get_flavor_details
request :get_image_details
request :get_key_pair
request :get_meta
#request :get_windows_password
request :get_server_details
#request :get_vnc_console
request :get_vnc_console
#request :list_addresses
request :list_flavors
request :list_flavors_detail

View File

@ -0,0 +1,41 @@
module Fog
module Compute
class HPV2
class Real
# Retrieve console output for specified instance
#
# ==== Parameters
# * 'server_id'<~Stribng> - UUId of instance to get console output from
# * 'num_lines'<~Integer> - Number of lines of console output from the end
# ==== Returns
# # * response<~Excon::Response>:
# * body<~Hash>:
# * 'output'<~String> - Console output
#
def get_console_output(server_id, num_lines)
body = { 'os-getConsoleOutput' => { 'length' => num_lines }}
server_action(server_id, body, 200)
end
end
class Mock
def get_console_output(server_id, num_lines)
output = ""
response = Excon::Response.new
if list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
(1..num_lines).each {|i| output += "Console Output Line #{i} \r\n"}
response.body = { 'output' => output }
response.status = 200
else
raise Fog::Compute::HPV2::NotFound
end
response
end
end
end
end
end

View File

@ -0,0 +1,45 @@
module Fog
module Compute
class HPV2
class Real
# Retrieve VNC console for the specified instance
#
# ==== Parameters
# * 'server_id'<~String> - UUId of instance to get console output from
# * 'type'<~String> - Type of the vnc console, defaults to 'novnc'
# ==== Returns
# # * response<~Excon::Response>:
# * body<~Hash>:
# * 'console'
# * 'type'<~String> - Type of the vnc console
# * 'url'<~String> - Url to access a VNC console of a server from a browser
#
def get_vnc_console(server_id, type='novnc')
body = { 'os-getVNCConsole' => { 'type' => type }}
server_action(server_id, body, 200)
end
end
class Mock
def get_vnc_console(server_id, type='novnc')
output = {
'type' => type,
'url' => 'https://region.compute.hpcloud.com/vnc_auto.html?token=123ABX234'
}
response = Excon::Response.new
if list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
response.body = { 'console' => output }
response.status = 200
else
raise Fog::Compute::HPV2::NotFound
end
response
end
end
end
end
end

View File

@ -20,7 +20,7 @@ module Fog
def reboot_server(server_id, type = 'SOFT')
response = Excon::Response.new
if list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
response.body['status'] = type == 'SOFT'? 'REBOOT' : 'HARD_REBOOT'
self.data[:servers][server_id]['status'] = (type == 'SOFT') ? 'REBOOT' : 'HARD_REBOOT'
response.status = 202
response
else

View File

@ -63,23 +63,18 @@ Shindo.tests("Fog::Compute::HPV2 | server requests", ['hp', 'v2', 'compute']) do
service.update_server(@server_id, :name => 'fogupdateserver')
end
#tests("#reboot_server(#{@server_id}, 'SOFT')").succeeds do
# Fog::Compute[:hp].reboot_server(@server_id, 'SOFT')
#end
tests("#reboot_server(#{@server_id}, 'SOFT')").succeeds do
pending unless Fog.mocking?
service.reboot_server(@server_id, 'SOFT')
end
#Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }
#
#tests("#change_password_server(#{@server_id}, 'new_password')").succeeds do
# Fog::Compute[:hp].change_password_server(@server_id, 'new_password')
tests("#get_console_output('#{@server_id}', 10)").formats(@get_console_output_format) do
service.get_console_output(@server_id, 10).body
end
#tests("#get_vnc_console('#{@server_id}', 'novnc')").succeeds do
# service.get_console_output(@server_id, 'novnc')
#end
#
#Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }
#
#tests("#get_console_output('#{@server_id}', 10)").formats(@get_console_output_format) do
# Fog::Compute[:hp].get_console_output(@server_id, 10).body
#end
#
#Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }
tests("#delete_server(#{@server_id})").succeeds do
service.delete_server(@server_id)
@ -101,12 +96,16 @@ Shindo.tests("Fog::Compute::HPV2 | server requests", ['hp', 'v2', 'compute']) do
service.update_server(0, :name => 'fognonserver')
end
#tests('#reboot_server(0)').raises(Fog::Compute::HPV2::NotFound) do
# service.reboot_server(0)
#end
#
#tests("#change_password_server(0}, 'new_password')").raises(Excon::Errors::InternalServerError) do
# service.change_password_server(0, 'new_password')
tests('#reboot_server(0)').raises(Fog::Compute::HPV2::NotFound) do
service.reboot_server(0)
end
tests('#get_console_output(0, 10)').raises(Fog::Compute::HPV2::NotFound) do
service.get_console_output(0, 10).body
end
#tests("#get_vnc_console(0, 'novnc')").raises(Fog::Compute::HPV2::NotFound) do
# service.get_console_output(0, 'novnc')
#end
end