Skip to content

Commit

Permalink
Merge pull request #23077 from kbrock/supports_unsupports-drop_supports
Browse files Browse the repository at this point in the history
Remove calls to supports and supports back to back
  • Loading branch information
agrare committed Jul 10, 2024
2 parents 5f2d274 + c0f9c8e commit 0937672
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 48 deletions.
12 changes: 6 additions & 6 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ class Host < ApplicationRecord

# if you change this, please check in on VmWare#start
supports :start do
if !supports?(:ipmi)
unsupported_reason(:ipmi)
elsif power_state != "off"
if power_state != "off"
_("The Host is not in power state off")
else
unsupported_reason(:ipmi)
end
end

supports :stop do
if !supports?(:ipmi)
unsupported_reason(:ipmi)
elsif power_state != "on"
if power_state != "on"
_("The Host is not in powered on")
else
unsupported_reason(:ipmi)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ def self.scan_timer(zone_name = nil)
end

def scan(userid = "system", _role = "ems_operations")
unless supports?(:smartstate_analysis)
if (reason = unsupported_reason(:smartstate_analysis))
raise(MiqException::MiqUnsupportedStorage,
_("Action not supported for Datastore type [%{store_type}], [%{name}] with id: [%{id}] %{error}") %
{:store_type => store_type, :name => name, :id => id, :error => unsupported_reason(:smartstate_analysis)})
{:store_type => store_type, :name => name, :id => id, :error => reason})
end

task_name = "SmartState Analysis for [#{name}]"
Expand Down
37 changes: 11 additions & 26 deletions app/models/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def self.find_all_by_mac_address_and_hostname_and_ipaddress(mac_address, hostnam

def running_processes
pl = {}
unless supports?(:collect_running_processes)
_log.warn(unsupported_reason(:collect_running_processes))
raise unsupported_reason(:collect_running_processes)
if (reason = unsupported_reason(:collect_running_processes))
_log.warn(reason)
raise reason
end

begin
Expand Down Expand Up @@ -118,9 +118,9 @@ def remote_console_url=(url, user_id)

def supported_consoles
{
:html5 => html5_support,
:vmrc => vmrc_support,
:native => native_support
:html5 => support_hash(:html5_console, :launch_html5_console),
:vmrc => support_hash(:vmrc_console, :launch_vmrc_console),
:native => support_hash(:native_console, :launch_native_console)
}
end

Expand All @@ -144,27 +144,12 @@ def self.display_name(number = 1)

private

def html5_support
def support_hash(visible, launch)
reason = unsupported_reason(launch)
{
:visible => supports?(:html5_console),
:enabled => supports?(:launch_html5_console),
:message => unsupported_reason(:launch_html5_console)
}
end

def vmrc_support
{
:visible => supports?(:vmrc_console),
:enabled => supports?(:launch_vmrc_console),
:message => unsupported_reason(:launch_vmrc_console)
}
end

def native_support
{
:visible => supports?(:native_console),
:enabled => supports?(:launch_native_console),
:message => unsupported_reason(:launch_native_console)
:visible => supports?(visible),
:enabled => !reason,
:message => reason
}
end

Expand Down
18 changes: 9 additions & 9 deletions app/models/vm/operations/power.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ module Vm::Operations::Power
api_relay_method :suspend

supports :suspend do
if !supports?(:control)
unsupported_reason(:control)
elsif !vm_powered_on?
if !vm_powered_on?
_('The VM is not powered on')
else
unsupported_reason(:control)
end
end

supports :start do
if !supports?(:control)
unsupported_reason(:control)
elsif vm_powered_on?
if vm_powered_on?
_('The VM is powered on')
else
unsupported_reason(:control)
end
end

supports :stop do
if !supports?(:control)
unsupported_reason(:control)
elsif !vm_powered_on?
if !vm_powered_on?
_('The VM is not powered on')
else
unsupported_reason(:control)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/vm_or_template/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ def log_user_event(user_event)
end

supports :vm_control_powered_on do
if !supports?(:control)
unsupported_reason(:control)
elsif current_state != "on"
if current_state != "on"
"The VM is not powered on"
else
unsupported_reason(:control)
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/models/vm_scan/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ def get_eligible_proxies_for_job(job)
return []
end

unless @vm.supports?(:smartstate_analysis)
msg = @vm.unsupported_reason(:smartstate_analysis)
if (msg = @vm.unsupported_reason(:smartstate_analysis))
queue_signal(job, {:args => [:abort, msg, "error"]})
return []
end
Expand Down

0 comments on commit 0937672

Please sign in to comment.