Skip to content

Commit

Permalink
Native viewer
Browse files Browse the repository at this point in the history
Show native viewer button for redhat providers and allow
connection file (usually named console.vv) to be dowloaded after
requiring via task
  • Loading branch information
gekorob committed Dec 24, 2019
1 parent 72dd687 commit 4cc30e5
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
44 changes: 44 additions & 0 deletions app/controllers/vm_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ def html5_console
params[:task_id] ? console_after_task('html5') : console_before_task('html5')
end

def native_viewer_console
native_viewer_console_launch_task
end

def launch_native_viewer_console
miq_task = MiqTask.find(params[:task_id])
results = miq_task.task_results

disable_client_cache
send_data(Base64.decode64(results[:connection]), :type => results[:type], :filename => results[:name])
end

def launch_vmrc_console
render :template => "vm_common/console_vmrc", :layout => false, :locals => params.slice(:remote_url)
end
Expand Down Expand Up @@ -94,4 +106,36 @@ def console_after_task(console_type)
javascript_open_window(url)
end
end

def native_viewer_console_launch_task
record = identify_record(params[:id], VmOrTemplate)

task_id = record.native_viewer_connection_queue(session[:userid])
unless task_id.kind_of?(Integer)
add_flash(_("Native viewer access failed: Task start failed"), :error)
end

if @flash_array
javascript_flash(:spinner_off => true)
else
initiate_wait_for_task(:task_id => task_id, :action => 'native_viewer_console_task_complete')
end
end

def native_viewer_console_task_complete
miq_task = MiqTask.find(params[:task_id])
unless miq_task.results_ready?
add_flash(_("Native viewer access failed: %{message}") % {:message => miq_task.message}, :error)
end

if @flash_array
javascript_flash(:spinner_off => true)
else
url = url_for_only_path(:controller => controller_name,
:action => 'launch_native_viewer_console',
:id => j(params[:id]),
:params => {:task_id => miq_task.id})
javascript_open_window(url)
end
end
end
16 changes: 16 additions & 0 deletions app/helpers/application_helper/button/vm_native_viewer_console.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ApplicationHelper::Button::VmNativeViewerConsole < ApplicationHelper::Button::Basic
needs :@record

def visible?
@record.vendor == 'redhat'
end

def disabled?
begin
@record.validate_native_viewer_support
rescue MiqException::RemoteConsoleNotSupportedError => err
@error_message = _('VM Native viewer error: %{error}') % {:error => err}
end
@error_message.present?
end
end
15 changes: 13 additions & 2 deletions app/helpers/application_helper/toolbar/x_vm_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ class ApplicationHelper::Toolbar::XVmCenter < ApplicationHelper::Toolbar::Basic
N_('VM Console'),
:keepSpinner => true,
:url => "html5_console",
:klass => ApplicationHelper::Button::VmHtml5Console),
:klass => ApplicationHelper::Button::VmHtml5Console
),
button(
:vm_vmrc_console,
'pficon pficon-screen fa-lg',
Expand All @@ -278,7 +279,17 @@ class ApplicationHelper::Toolbar::XVmCenter < ApplicationHelper::Toolbar::Basic
:keepSpinner => true,
:url => "vmrc_console",
:confirm => N_("Opening a VMRC console requires that VMRC is installed and pre-configured to work in your browser. Are you sure?"),
:klass => ApplicationHelper::Button::VmVmrcConsole),
:klass => ApplicationHelper::Button::VmVmrcConsole
),
button(
:vm_native_viewer_console,
'pficon pficon-screen fa-lg',
N_('Open a native viewer console for this VM'),
N_('Native viewer'),
:keepSpinner => true,
:url => "native_viewer_console",
:klass => ApplicationHelper::Button::VmNativeViewerConsole
),
button(
:cockpit_console,
'pficon pficon-screen fa-lg',
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,7 @@
right_size_print
launch_html5_console
launch_vmrc_console
launch_native_viewer_console
perf_chart_chooser
policies
protect
Expand Down Expand Up @@ -3188,6 +3189,7 @@
vm_pre_prov
vm_vdi
html5_console
native_viewer_console
wait_for_task
win32_services
ownership_update
Expand Down Expand Up @@ -3215,6 +3217,7 @@
explorer
launch_html5_console
launch_vmrc_console
launch_native_viewer_console
retirement_info
reconfigure_form_fields
policies
Expand Down Expand Up @@ -3286,6 +3289,7 @@
vm_pre_prov
vmrc_console
html5_console
native_viewer_console
wait_for_task
win32_services
x_button
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe ApplicationHelper::Button::VmNativeViewerConsole do
let(:view_context) { setup_view_context_with_sandbox({}) }
let(:ems) { FactoryBot.create(:ems_redhat) }
let(:record) { FactoryBot.create(:vm_redhat, :ext_management_system => ems) }
let(:button) { described_class.new(view_context, {}, {'record' => record}, {}) }

describe '#visible?' do
subject { button.visible? }

it { is_expected.to be true }
end

describe '#calculate_properties' do
before(:each) do
remote_console_validation
button.calculate_properties
end

context 'and remote control is supported' do
let(:remote_console_validation) do
allow(record).to receive(:validate_native_viewer_support).and_return(true)
end
it_behaves_like 'an enabled button'
end
context 'and remote control is not supported' do
let(:err_msg) { 'Remote console is not supported' }
let(:remote_console_validation) do
allow(record).to receive(:validate_native_viewer_support)
.and_raise(MiqException::RemoteConsoleNotSupportedError, err_msg)
end
it_behaves_like 'a disabled button', "VM Native viewer error: Remote console is not supported"
end
end
end

0 comments on commit 4cc30e5

Please sign in to comment.