diff --git a/app/helpers/application_helper/button/instance_reset.rb b/app/helpers/application_helper/button/instance_reset.rb index 1a3aa586ab6..133a246af26 100644 --- a/app/helpers/application_helper/button/instance_reset.rb +++ b/app/helpers/application_helper/button/instance_reset.rb @@ -3,6 +3,6 @@ class ApplicationHelper::Button::InstanceReset < ApplicationHelper::Button::Basi def visible? return true if @display == "instances" - @record.is_available?(:reset) + @record.supports_reset? end end diff --git a/app/models/host.rb b/app/models/host.rb index 5c8b3bc957e..cdaaf68c635 100644 --- a/app/models/host.rb +++ b/app/models/host.rb @@ -179,6 +179,14 @@ class Host < ApplicationRecord before_create :make_smart after_save :process_events + supports :reset do + unsupported_reason_add(:reset, _("The Host is not configured for IPMI")) if ipmi_address.blank? + unsupported_reason_add(:reset, _("The Host has no IPMI credentials")) if authentication_type(:ipmi).nil? + if authentication_userid(:ipmi).blank? || authentication_password(:ipmi).blank? + unsupported_reason_add(:reset, _("The Host has invalid IPMI credentials")) + end + end + def self.include_descendant_classes_in_expressions? true end @@ -256,10 +264,6 @@ def validate_stop validate_ipmi('on') end - def validate_reset - validate_ipmi - end - def validate_ipmi(pstate = nil) return {:available => false, :message => "The Host is not configured for IPMI"} if ipmi_address.blank? return {:available => false, :message => "The Host has no IPMI credentials"} if authentication_type(:ipmi).nil? @@ -361,11 +365,10 @@ def ipmi_power_reset end def reset - msg = validate_reset - if msg[:available] + if supports_reset? check_policy_prevent("request_host_reset", "ipmi_power_reset") else - _log.warn("Cannot stop because <#{msg[:message]}>") + _log.warn("Cannot stop because <#{unsupported_reason(:reset)}>") end end diff --git a/app/models/manageiq/providers/openstack/cloud_manager/vm/operations/guest.rb b/app/models/manageiq/providers/openstack/cloud_manager/vm/operations/guest.rb index 4e9621e77f1..2fa347dc0f3 100644 --- a/app/models/manageiq/providers/openstack/cloud_manager/vm/operations/guest.rb +++ b/app/models/manageiq/providers/openstack/cloud_manager/vm/operations/guest.rb @@ -6,10 +6,11 @@ module ManageIQ::Providers::Openstack::CloudManager::Vm::Operations::Guest unsupported_reason_add(:reboot_guest, unsupported_reason(:control)) unless supports_control? unsupported_reason_add(:reboot_guest, _("The VM is not powered on")) unless current_state == "on" end - end - def validate_reset - validate_vm_control_powered_on + supports :reset do + unsupported_reason_add(:reset, unsupported_reason(:control)) unless supports_control? + unsupported_reason_add(:reset, _("The VM is not powered on")) unless current_state == "on" + end end def raw_reboot_guest diff --git a/app/models/manageiq/providers/openstack/infra_manager.rb b/app/models/manageiq/providers/openstack/infra_manager.rb index 8938247ba85..a314e1c2cfd 100644 --- a/app/models/manageiq/providers/openstack/infra_manager.rb +++ b/app/models/manageiq/providers/openstack/infra_manager.rb @@ -156,8 +156,4 @@ def register_and_configure_nodes(nodes_json) def validate_shutdown {:available => false, :message => nil} end - - def validate_reset - {:available => false, :message => nil} - end end diff --git a/app/models/manageiq/providers/vmware/infra_manager/vm/operations/guest.rb b/app/models/manageiq/providers/vmware/infra_manager/vm/operations/guest.rb index 5451db47830..fac4405cb6d 100644 --- a/app/models/manageiq/providers/vmware/infra_manager/vm/operations/guest.rb +++ b/app/models/manageiq/providers/vmware/infra_manager/vm/operations/guest.rb @@ -15,13 +15,14 @@ module ManageIQ::Providers::Vmware::InfraManager::Vm::Operations::Guest end end end - end - def validate_standby_guest - validate_vm_control_powered_on + supports :reset do + unsupported_reason_add(:reset, unsupported_reason(:control)) unless supports_control? + unsupported_reason_add(:reset, _("The VM is not powered on")) unless current_state == "on" + end end - def validate_reset + def validate_standby_guest validate_vm_control_powered_on end end diff --git a/app/models/miq_template/operations.rb b/app/models/miq_template/operations.rb index 0ed73c3f82a..51e7d3f8be9 100644 --- a/app/models/miq_template/operations.rb +++ b/app/models/miq_template/operations.rb @@ -25,10 +25,6 @@ def validate_standby_guest validate_invalid_for_template(_("Standby Guest Operation")) end - def validate_reset - validate_invalid_for_template(_("Reset Operation")) - end - private def validate_invalid_for_template(message_prefix) diff --git a/app/models/mixins/supports_feature_mixin.rb b/app/models/mixins/supports_feature_mixin.rb index 663a1865fd4..9fd46f0fffe 100644 --- a/app/models/mixins/supports_feature_mixin.rb +++ b/app/models/mixins/supports_feature_mixin.rb @@ -88,6 +88,7 @@ module SupportsFeatureMixin :refresh_new_target => 'Refresh non-existing record', :regions => 'Regions of a Provider', :remove_host => 'Remove Host', + :reset => 'Reset', :resize => 'Resizing', :retire => 'Retirement', :smartstate_analysis => 'Smartstate Analaysis', diff --git a/app/models/vm/operations/guest.rb b/app/models/vm/operations/guest.rb index 0e958d6377c..c0101a198ad 100644 --- a/app/models/vm/operations/guest.rb +++ b/app/models/vm/operations/guest.rb @@ -11,10 +11,6 @@ def validate_standby_guest validate_unsupported("Standby Guest Operation") end - def validate_reset - validate_unsupported("Reset Guest Operation") - end - def raw_shutdown_guest unless has_active_ems? raise _("VM has no %{table}, unable to shutdown guest OS") % diff --git a/spec/helpers/application_helper/buttons/instance_reset_spec.rb b/spec/helpers/application_helper/buttons/instance_reset_spec.rb index 7f0f6a0fb8f..ff09f5ecf9c 100644 --- a/spec/helpers/application_helper/buttons/instance_reset_spec.rb +++ b/spec/helpers/application_helper/buttons/instance_reset_spec.rb @@ -3,7 +3,7 @@ context "when record is resetable" do before do @record = FactoryGirl.create(:vm_openstack) - allow(@record).to receive(:is_available?).with(:reset).and_return(true) + allow(@record).to receive(:supports_reset?).and_return(true) end it_behaves_like "will not be skipped for this record" @@ -12,7 +12,7 @@ context "when record is not resetable" do before do @record = FactoryGirl.create(:vm_openstack) - allow(@record).to receive(:is_available?).with(:reset).and_return(false) + allow(@record).to receive(:supports_reset?).and_return(false) end it_behaves_like "will be skipped for this record" diff --git a/spec/models/host_spec.rb b/spec/models/host_spec.rb index d7194a8b9af..02b57f7b6ac 100644 --- a/spec/models/host_spec.rb +++ b/spec/models/host_spec.rb @@ -594,9 +594,9 @@ def assert_remote_credentials_validated end end - describe "#validate_reset" do - it "returns available true" do - expect(host_with_ipmi.validate_reset).to eq(:available => true, :message => nil) + describe "#supports_reset" do + it "returns true for supports_reset?" do + expect(host_with_ipmi.supports_reset?).to be_truthy end end end