diff --git a/app/models/mixins/supports_feature_mixin.rb b/app/models/mixins/supports_feature_mixin.rb index 19121ba0682..ad325a6a8b8 100644 --- a/app/models/mixins/supports_feature_mixin.rb +++ b/app/models/mixins/supports_feature_mixin.rb @@ -91,9 +91,11 @@ module SupportsFeatureMixin :cockpit_console => 'Cockpit Console', :html5_console => 'HTML5 Console', :vmrc_console => 'VMRC Console', + :native_console => 'Native Console', :launch_cockpit => 'Launch Cockpit UI', :launch_html5_console => 'Launch HTML5 Console', :launch_vmrc_console => 'Launch VMRC Console', + :launch_native_console => 'Launch Native Console', :admin_ui => 'Open Admin UI for a Provider', :live_migrate => 'Live Migration', :warm_migrate => 'Warm Migration', diff --git a/app/models/vm.rb b/app/models/vm.rb index a2c3d443599..00de0237f30 100644 --- a/app/models/vm.rb +++ b/app/models/vm.rb @@ -31,6 +31,11 @@ def validate_remote_console_vmrc_support _("VMRC remote console is not supported on %{vendor}.") % {:vendor => vendor}) end + def validate_native_console_support + raise(MiqException::RemoteConsoleNotSupportedError, + _("NATIVE remote console is not supported on %{vendor}.") % {:vendor => vendor}) + end + def add_to_service(service) service.add_resource!(self) end @@ -115,7 +120,8 @@ def supported_consoles { :html5 => html5_support, :vmrc => vmrc_support, - :cockpit => cockpit_support + :cockpit => cockpit_support, + :native => native_support } end @@ -148,4 +154,12 @@ def cockpit_support :message => unsupported_reason(:launch_cockpit) } end + + def native_support + { + :visible => supports_native_console?, + :enabled => supports_launch_native_console?, + :message => unsupported_reason(:launch_native_console) + } + end end diff --git a/app/models/vm/operations.rb b/app/models/vm/operations.rb index 67cc1f79f27..6f4bd6e48e5 100644 --- a/app/models/vm/operations.rb +++ b/app/models/vm/operations.rb @@ -18,6 +18,10 @@ module Vm::Operations unsupported_reason_add(:vmrc_console, _("VMRC Console not supported")) unless console_supported?('VMRC') end + supports :native_console do + unsupported_reason_add(:native_console, _("VM NATIVE Console not supported")) unless console_supported?('NATIVE') + end + supports :launch_html5_console do unsupported_reason_add(:launch_html5_console, _("The web-based HTML5 Console is not available because the VM is not powered on")) unless power_state == 'on' end @@ -29,6 +33,12 @@ module Vm::Operations unsupported_reason_add(:launch_vmrc_console, _('VM VMRC Console error: %{error}') % {:error => err}) end end + + supports :launch_native_console do + validate_native_console_support + rescue StandardError => err + unsupported_reason_add(:launch_native_console, _('VM NATIVE Console error: %{error}') % {:error => err}) + end end def cockpit_url diff --git a/db/fixtures/miq_product_features.yml b/db/fixtures/miq_product_features.yml index 8f994f8a285..c4baa8738df 100644 --- a/db/fixtures/miq_product_features.yml +++ b/db/fixtures/miq_product_features.yml @@ -5438,6 +5438,10 @@ :description: Open the Cockpit console for VMs :feature_type: control :identifier: cockpit_console + - :name: Native Console + :description: Open the Native console for VMs + :feature_type: control + :identifier: vm_native_console - :name: Edit Tags :description: Edit VM Tags :feature_type: control diff --git a/db/fixtures/miq_user_roles.yml b/db/fixtures/miq_user_roles.yml index 0a38892f048..12f40baf53e 100644 --- a/db/fixtures/miq_user_roles.yml +++ b/db/fixtures/miq_user_roles.yml @@ -165,6 +165,7 @@ - vm_html5_console - vm_vmrc_console - cockpit_console + - vm_native_console - vm_perf - vm_policy_sim - vm_show diff --git a/spec/models/vm/operations_spec.rb b/spec/models/vm/operations_spec.rb index b795fb6d505..ad0efb75893 100644 --- a/spec/models/vm/operations_spec.rb +++ b/spec/models/vm/operations_spec.rb @@ -88,6 +88,21 @@ end end + describe '#supports_native_console?' do + it 'returns false if type is not supported' do + allow(@vm).to receive(:console_supported?).with('NATIVE').and_return(false) + + expect(@vm.supports_native_console?).to be_falsey + expect(@vm.unsupported_reason(:native_console)).to include('NATIVE Console not supported') + end + + it 'supports it if all conditions are met' do + allow(@vm).to receive(:console_supported?).with('NATIVE').and_return(true) + + expect(@vm.supports_native_console?).to be_truthy + end + end + describe '#supports_launch_vmrc_console?' do it 'does not support it if validate_remote_console_vmrc_support raises an error' do allow(@vm).to receive(:validate_remote_console_vmrc_support).and_raise(StandardError) @@ -117,4 +132,19 @@ expect(@vm.supports_launch_html5_console?).to be_truthy end end + + describe '#supports_launch_native_console?' do + it 'does not support it if validate_native_console_support raises an error' do + allow(@vm).to receive(:validate_native_console_support).and_raise(StandardError) + + expect(@vm.supports_launch_native_console?).to be_falsey + expect(@vm.unsupported_reason(:launch_native_console)).to include('VM NATIVE Console error:') + end + + it 'supports it if all conditions are met' do + allow(@vm).to receive(:validate_native_console_support) + + expect(@vm.supports_launch_native_console?).to be_truthy + end + end end diff --git a/spec/models/vm_spec.rb b/spec/models/vm_spec.rb index ab3aa99e9a9..2801d7205aa 100644 --- a/spec/models/vm_spec.rb +++ b/spec/models/vm_spec.rb @@ -40,6 +40,11 @@ expect { vm.validate_remote_console_vmrc_support }.to raise_error MiqException::RemoteConsoleNotSupportedError end + it "#validate_native_console_support must be overridden" do + vm = FactoryBot.create(:vm_vmware, :vendor => 'vmware') + expect { vm.validate_native_console_support }.to raise_error MiqException::RemoteConsoleNotSupportedError + end + context ".find_all_by_mac_address_and_hostname_and_ipaddress" do before do @hardware1 = FactoryBot.create(:hardware) @@ -309,7 +314,7 @@ context "#supported_consoles" do it 'returns all of the console types' do vm = FactoryBot.create(:vm) - expect(vm.supported_consoles.keys).to match_array([:html5, :vmrc, :cockpit]) + expect(vm.supported_consoles.keys).to match_array([:html5, :vmrc, :cockpit, :native]) end end end