Skip to content

Commit

Permalink
Merge pull request #486 from kbrock/unsupports_supports
Browse files Browse the repository at this point in the history
drop use of unsupported_reason_add an supports_feature
  • Loading branch information
agrare committed Feb 26, 2024
2 parents 2fe9c81 + 2309576 commit e0d3d0a
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ManageIQ::Providers::IbmCloud::ContainerManager < ManageIQ::Providers::Kub
METRICS_ROLES = %w[prometheus].freeze

supports :metrics do
unsupported_reason_add(:metrics, _("No metrics endpoint has been added")) unless metrics_endpoint_exists?
_("No metrics endpoint has been added") unless metrics_endpoint_exists?
end

def metrics_endpoint_exists?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class ManageIQ::Providers::IbmCloud::PowerVirtualServers::CloudManager::Template

supports :provisioning do
if ext_management_system
unsupported_reason_add(:provisioning, ext_management_system.unsupported_reason(:provisioning)) unless ext_management_system.supports?(:provisioning)
ext_management_system.unsupported_reason(:provisioning)
else
unsupported_reason_add(:provisioning, _('not connected to ems'))
_('not connected to ems')
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,44 @@ class ManageIQ::Providers::IbmCloud::PowerVirtualServers::CloudManager::Vm < Man
supports :capture
supports :terminate
supports :reboot_guest do
unsupported_reason_add(:reboot_guest, _("The VM is not powered on")) unless current_state == "on"
_("The VM is not powered on") unless current_state == "on"
end
supports :reset do
unsupported_reason_add(:reset, _("The VM is not powered on")) unless current_state == "on"
_("The VM is not powered on") unless current_state == "on"
end
supports :snapshots
supports :snapshot_create
supports :revert_to_snapshot do
unsupported_reason_add(:revert_to_snapshot, _("Cannot revert to snapshot while VM is running")) unless current_state == "off"
_("Cannot revert to snapshot while VM is running") unless current_state == "off"
end
supports :remove_snapshot
supports :remove_all_snapshots

supports_not :suspend

supports :publish do
reason = _("Publish not supported because VM is blank") if blank?
reason ||= _("Publish not supported because VM is orphaned") if orphaned?
reason ||= _("Publish not supported because VM is archived") if archived?
unsupported_reason_add(:publish, reason) if reason
return _("Publish not supported because VM is blank") if blank?
return _("Publish not supported because VM is orphaned") if orphaned?
return _("Publish not supported because VM is archived") if archived?
end

# TODO: converge these all into console and use unsupported_reason(:console) for all
supports :html5_console do
reason = _("VM Console not supported because VM is not powered on") unless current_state == "on"
reason ||= _("VM Console not supported because VM is orphaned") if orphaned?
reason ||= _("VM Console not supported because VM is archived") if archived?
unsupported_reason_add(:html5_console, reason) if reason
return _("VM Console not supported because VM is not powered on") unless current_state == "on"
return _("VM Console not supported because VM is orphaned") if orphaned?
return _("VM Console not supported because VM is archived") if archived?
end
supports :launch_html5_console

supports :native_console do
reason ||= _("VM Console not supported because VM is orphaned") if orphaned?
reason ||= _("VM Console not supported because VM is archived") if archived?
unsupported_reason_add(:native_console, reason) if reason
return _("VM Console not supported because VM is orphaned") if orphaned?
return _("VM Console not supported because VM is archived") if archived?
end

supports :resize do
unsupported_reason_add(:resize, _('The VM is not powered off')) unless current_state == "off"
unsupported_reason_add(:resize, _('The VM is not connected to a provider')) unless ext_management_system
unsupported_reason_add(:resize, _('SAP VM resize not supported')) if flavor.kind_of?(ManageIQ::Providers::IbmCloud::PowerVirtualServers::CloudManager::SAPProfile)
return _('The VM is not powered off') unless current_state == "off"
return _('The VM is not connected to a provider') unless ext_management_system
return _('SAP VM resize not supported') if flavor.kind_of?(ManageIQ::Providers::IbmCloud::PowerVirtualServers::CloudManager::SAPProfile)
end

def cloud_instance_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class ManageIQ::Providers::IbmCloud::PowerVirtualServers::NetworkManager::CloudSubnet < ::CloudSubnet
supports :create
supports :delete do
if number_of(:vms) > 0
unsupported_reason_add(:delete, _("The Network has active VMIs related to it"))
end
_("The Network has active VMIs related to it") if number_of(:vms) > 0
end

def self.params_for_create(_ems)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ class ManageIQ::Providers::IbmCloud::PowerVirtualServers::StorageManager::CloudV
supports :create
supports :clone
supports :delete do
unsupported_reason_add(:delete, _("the volume is not connected to an active Provider")) unless ext_management_system
unsupported_reason_add(:delete, _("cannot delete volume that is in use.")) if status == "in-use"
return _("the volume is not connected to an active Provider") unless ext_management_system
return _("cannot delete volume that is in use.") if status == "in-use"
end
supports_not :snapshot_create
supports_not :update
supports :attach do
unsupported_reason_add(:attach, _("the volume is not connected to an active Provider")) unless ext_management_system
unsupported_reason_add(:attach, _("cannot attach non-shareable volume that is in use.")) if status == "in-use" && !multi_attachment
return _("the volume is not connected to an active Provider") unless ext_management_system
return _("cannot attach non-shareable volume that is in use.") if status == "in-use" && !multi_attachment
end
supports :detach do
unsupported_reason_add(:detach, _("the volume is not connected to an active Provider")) unless ext_management_system
unsupported_reason_add(:detach, _("the volume status is '%{status}' but should be 'in-use'") % {:status => status}) unless status == "in-use"
return _("the volume is not connected to an active Provider") unless ext_management_system
return _("the volume status is '%{status}' but should be 'in-use'") % {:status => status} unless status == "in-use"
end

def available_vms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class ManageIQ::Providers::IbmCloud::VPC::CloudManager::Template < ManageIQ::Pro

supports :provisioning do
if ext_management_system
unsupported_reason_add(:provisioning, ext_management_system.unsupported_reason(:provisioning)) unless ext_management_system.supports_provisioning?
ext_management_system.unsupported_reason(:provisioning)
else
unsupported_reason_add(:provisioning, _('not connected to ems'))
_('not connected to ems')
end
end

Expand Down
10 changes: 5 additions & 5 deletions app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def raw_pause

# Show reboot in the instance menu when on.
supports :reboot_guest do
unsupported_reason_add(:reboot_guest, _('The VM is not powered on')) unless current_state == 'on'
_('The VM is not powered on') unless current_state == 'on'
end

# Gracefully reboot the quest.
Expand All @@ -92,7 +92,7 @@ def raw_reboot_guest(force: false)

# Tell UI to show reset in UI only when VM is on.
supports :reset do
unsupported_reason_add(:reset, _('The VM is not powered on')) unless current_state == "on"
_('The VM is not powered on') unless current_state == "on"
end

# Force the the VM to restart.
Expand All @@ -101,7 +101,7 @@ def raw_reset
end

supports :terminate do
unsupported_reason_add(:terminate, unsupported_reason(:control)) unless supports_control?
unsupported_reason(:control)
end

def raw_destroy
Expand All @@ -112,8 +112,8 @@ def raw_destroy
end

supports :resize do
unsupported_reason_add(:resize, _('The VM is not powered off')) unless current_state == "off"
unsupported_reason_add(:resize, _('The VM is not connected to a provider')) unless ext_management_system
return _('The VM is not powered off') unless current_state == "off"
return _('The VM is not connected to a provider') unless ext_management_system
end

def raw_resize(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class ManageIQ::Providers::IbmCloud::VPC::NetworkManager::CloudNetwork < ::Cloud
supports :create
supports :delete do
if ext_management_system.nil?
unsupported_reason_add(:delete_cloud_network, _("The Cloud Network is not connected to an active %{table}") % {
_("The Cloud Network is not connected to an active %{table}") % {
:table => ui_lookup(:table => "ext_management_systems")
})
}
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ class ManageIQ::Providers::IbmCloud::VPC::NetworkManager::CloudSubnet < ::CloudS
supports :create
supports :delete do
if ext_management_system.nil?
unsupported_reason_add(:delete, _("The subnet is not connected to an active %{table}") % {
_("The subnet is not connected to an active %{table}") % {
:table => ui_lookup(:table => "ext_management_systems")
})
end
if number_of(:vms) > 0
unsupported_reason_add(:delete, _("The subnet has an active %{table}") % {
}
elsif number_of(:vms) > 0
_("The subnet has an active %{table}") % {
:table => ui_lookup(:table => "vm_cloud")
})
}
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ class ManageIQ::Providers::IbmCloud::VPC::StorageManager::CloudVolume < ::CloudV
supports :create
supports :delete do
if ext_management_system.nil?
unsupported_reason_add(:delete_volume, _("The Cloud Volume is not connected to an active %{table}") % {
_("The Cloud Volume is not connected to an active %{table}") % {
:table => ui_lookup(:table => "ext_management_systems")
})
}
end
end

Expand Down

0 comments on commit e0d3d0a

Please sign in to comment.