From 4ad17c33f9868d13cf82927f6d8b02c16a11e81e Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Tue, 12 Jul 2022 21:05:03 -0400 Subject: [PATCH] convert from AvailabilityMixin to SupportsFeatureMixin --- app/models/host.rb | 11 +++------- .../providers/cloud_manager/template.rb | 20 +++--------------- app/models/physical_storage.rb | 5 +---- app/models/vm_or_template/operations.rb | 21 ++++++------------- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/app/models/host.rb b/app/models/host.rb index 3050e9b064be..5956b8b9c66e 100644 --- a/app/models/host.rb +++ b/app/models/host.rb @@ -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 @@ -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 diff --git a/app/models/manageiq/providers/cloud_manager/template.rb b/app/models/manageiq/providers/cloud_manager/template.rb index 249efda18934..2c0b16bc779a 100644 --- a/app/models/manageiq/providers/cloud_manager/template.rb +++ b/app/models/manageiq/providers/cloud_manager/template.rb @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/app/models/physical_storage.rb b/app/models/physical_storage.rb index e9d7c87263b5..15a42e0d956d 100644 --- a/app/models/physical_storage.rb +++ b/app/models/physical_storage.rb @@ -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 @@ -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 diff --git a/app/models/vm_or_template/operations.rb b/app/models/vm_or_template/operations.rb index bda2e5c78aa2..fc0b520d1ead 100644 --- a/app/models/vm_or_template/operations.rb +++ b/app/models/vm_or_template/operations.rb @@ -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