diff --git a/lib/fog/hp/compute.rb b/lib/fog/hp/compute.rb index 2faf7eacd..cbe9eb866 100644 --- a/lib/fog/hp/compute.rb +++ b/lib/fog/hp/compute.rb @@ -39,6 +39,7 @@ module Fog request :delete_server request :disassociate_address request :get_address + request :get_console_output request :get_flavor_details request :get_image_details request :get_security_group diff --git a/lib/fog/hp/models/compute/server.rb b/lib/fog/hp/models/compute/server.rb index 25493d3a9..e97e567b8 100644 --- a/lib/fog/hp/models/compute/server.rb +++ b/lib/fog/hp/models/compute/server.rb @@ -41,6 +41,11 @@ module Fog super end + def console_output(num_lines) + requires :id + connection.get_console_output(id, num_lines) + end + def destroy requires :id connection.delete_server(id) diff --git a/lib/fog/hp/requests/compute/get_console_output.rb b/lib/fog/hp/requests/compute/get_console_output.rb new file mode 100644 index 000000000..4cd4021ef --- /dev/null +++ b/lib/fog/hp/requests/compute/get_console_output.rb @@ -0,0 +1,43 @@ +module Fog + module Compute + class HP + class Real + + require 'fog/aws/parsers/compute/get_console_output' + + # Retrieve console output for specified instance + # + # ==== Parameters + # * server_id<~Integer> - Id 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::HP::NotFound + end + response + end + + end + end + end +end diff --git a/tests/hp/requests/compute/server_tests.rb b/tests/hp/requests/compute/server_tests.rb index c4f4bcaec..f9c064a00 100644 --- a/tests/hp/requests/compute/server_tests.rb +++ b/tests/hp/requests/compute/server_tests.rb @@ -31,7 +31,7 @@ Shindo.tests('Fog::Compute[:hp] | server requests', ['hp']) do } @get_console_output_format = { - + 'output' => String } @base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242 @@ -87,9 +87,8 @@ Shindo.tests('Fog::Compute[:hp] | server requests', ['hp']) do Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? } - tests("#get_console_output('#{@server_id}')").formats(@get_console_output_format) do - pending - Fog::Compute[:hp].get_console_output(@server_id).body + 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? }