Skip to content

Commit

Permalink
convert from AvailabilityMixin to SupportsFeatureMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Jul 13, 2022
1 parent a4f4636 commit 4ad17c3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 44 deletions.
11 changes: 3 additions & 8 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ class Host < ApplicationRecord
before_create :make_smart
after_save :process_events


supports :check_compliance_queue
supports :destroy
supports_not :quick_stats
supports_not :refresh_advanced_settings
supports_not :refresh_firewall_rules
supports_not :refresh_logs
supports_not :refresh_network_interfaces
supports :scan_and_check_compliance_queue
supports_not :set_node_maintenance
supports_not :smartstate_analysis
supports_not :unset_node_maintenance
Expand Down Expand Up @@ -273,14 +276,6 @@ def raise_cluster_event(ems_cluster, event)
end
private :raise_cluster_event

def validate_scan_and_check_compliance_queue
{:available => true, :message => nil}
end

def validate_check_compliance_queue
{:available => true, :message => nil}
end

def has_active_ems?
!!ext_management_system
end
Expand Down
20 changes: 3 additions & 17 deletions app/models/manageiq/providers/cloud_manager/template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class ManageIQ::Providers::CloudManager::Template < ::MiqTemplate
supports_not :create_image
supports_not :delete_image
supports_not :import_image
supports_not :update_image

default_value_for :cloud, true

Expand Down Expand Up @@ -44,10 +47,6 @@ def self.raw_create_image(_ext_management_system, _options = {})
raise NotImplementedError, "raw_create_image must be implemented in a subclass"
end

def validate_create_image(_ext_management_system, _options = {})
validate_unsupported(_("Create Image Operation"))
end

def self.create_image(ems_id, options)
raise ArgumentError, _("ems cannot be nil") if ems_id.nil?
ext_management_system = ExtManagementSystem.find(ems_id)
Expand Down Expand Up @@ -118,10 +117,6 @@ def update_image(options = {})
raw_update_image(options)
end

def validate_update_image
validate_unsupported("Update Image Operation")
end

def raw_update_image(_options = {})
raise NotImplementedError, _("raw_update_image must be implemented in a subclass")
end
Expand Down Expand Up @@ -152,19 +147,10 @@ def raw_delete_image
raise NotImplementedError, _("raw_delete_image must be implemented in a subclass")
end

def validate_delete_image
validate_unsupported(_("Delete Cloud Template Operation"))
end

def delete_image
raw_delete_image
end

def validate_unsupported(message_prefix)
{:available => false,
:message => _("%{message} is not available for %{name}.") % {:message => message_prefix, :name => name}}
end

def self.display_name(number = 1)
n_('Image', 'Images', number)
end
Expand Down
5 changes: 1 addition & 4 deletions app/models/physical_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PhysicalStorage < ApplicationRecord

supports_not :create
supports_not :delete
supports_not :update_physical_storage
supports_not :validate
acts_as_miq_taggable

Expand Down Expand Up @@ -159,10 +160,6 @@ def update_physical_storage(options = {})
raw_update_physical_storage(options)
end

def validate_update_physical_storage
validate_unsupported("Update Volume Operation")
end

def raw_update_physical_storage(_options = {})
raise NotImplementedError, _("raw_update_volume must be implemented in a subclass")
end
Expand Down
21 changes: 6 additions & 15 deletions app/models/vm_or_template/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,12 @@ def log_user_event(user_event)
supports_not :quick_stats
supports_not :rename
supports_not :terminate
end

def validate_vm_control_powered_on
validate_vm_control_power_state(true)
end

def validate_vm_control_power_state(check_powered_on)
unless supports?(:control)
return {:available => false, :message => unsupported_reason(:control)}
supports :vm_control_powered_on do
if !supports?(:control)
unsupported_reason_add(:vm_control_powered_on, unsupported_reason(:control))
elsif current_state != "on"
unsupported_reason_add(:vm_control_powered_on, "The VM is not powered on")
end
end
return {:available => true, :message => nil} if current_state.send(check_powered_on ? "==" : "!=", "on")
{:available => false, :message => "The VM is#{" not" if check_powered_on} powered on"}
end

def validate_unsupported(message_prefix)
{:available => false, :message => "#{message_prefix} is not available for #{self.class.model_suffix} VM or Template."}
end
end

0 comments on commit 4ad17c3

Please sign in to comment.