From 63617483d4d5d05f030b07784622d01f52514a48 Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Tue, 12 Mar 2013 18:17:33 -0400 Subject: [PATCH] [hp|compute] Add vnc console feature into request layer and server model. --- lib/fog/hp/compute.rb | 1 + lib/fog/hp/models/compute/server.rb | 19 ++++++-- .../hp/requests/compute/get_vnc_console.rb | 47 +++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 lib/fog/hp/requests/compute/get_vnc_console.rb diff --git a/lib/fog/hp/compute.rb b/lib/fog/hp/compute.rb index 6660fa362..a233fd1cd 100644 --- a/lib/fog/hp/compute.rb +++ b/lib/fog/hp/compute.rb @@ -57,6 +57,7 @@ module Fog request :get_windows_password request :get_security_group request :get_server_details + request :get_vnc_console request :list_addresses request :list_flavors request :list_flavors_detail diff --git a/lib/fog/hp/models/compute/server.rb b/lib/fog/hp/models/compute/server.rb index 87c711a8f..42d6ac89c 100644 --- a/lib/fog/hp/models/compute/server.rb +++ b/lib/fog/hp/models/compute/server.rb @@ -47,11 +47,6 @@ module Fog super end - def console_output(num_lines) - requires :id - service.get_console_output(id, num_lines) - end - def metadata @metadata ||= begin Fog::Compute::HP::Metadata.new({ @@ -71,6 +66,20 @@ module Fog self.user_data_encoded = [ascii_userdata].pack('m') # same as Base64.encode64 end + def console_output(num_lines) + requires :id + service.get_console_output(id, num_lines) + end + + def vnc_console_url(type='novnc') + requires :id + if resp = service.get_vnc_console(id, type).body + resp['console']['url'] + else + nil + end + end + def destroy requires :id service.delete_server(id) diff --git a/lib/fog/hp/requests/compute/get_vnc_console.rb b/lib/fog/hp/requests/compute/get_vnc_console.rb new file mode 100644 index 000000000..d69184a28 --- /dev/null +++ b/lib/fog/hp/requests/compute/get_vnc_console.rb @@ -0,0 +1,47 @@ +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 + # * 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::HP::NotFound + end + response + end + + end + end + end +end