Skip to content

Commit 2309576

Browse files
committed
drop use of unsupported_reason_add an supports_feature
1 parent 2fe9c81 commit 2309576

File tree

10 files changed

+41
-46
lines changed

10 files changed

+41
-46
lines changed

app/models/manageiq/providers/ibm_cloud/container_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ManageIQ::Providers::IbmCloud::ContainerManager < ManageIQ::Providers::Kub
66
METRICS_ROLES = %w[prometheus].freeze
77

88
supports :metrics do
9-
unsupported_reason_add(:metrics, _("No metrics endpoint has been added")) unless metrics_endpoint_exists?
9+
_("No metrics endpoint has been added") unless metrics_endpoint_exists?
1010
end
1111

1212
def metrics_endpoint_exists?

app/models/manageiq/providers/ibm_cloud/power_virtual_servers/cloud_manager/template.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ class ManageIQ::Providers::IbmCloud::PowerVirtualServers::CloudManager::Template
55

66
supports :provisioning do
77
if ext_management_system
8-
unsupported_reason_add(:provisioning, ext_management_system.unsupported_reason(:provisioning)) unless ext_management_system.supports?(:provisioning)
8+
ext_management_system.unsupported_reason(:provisioning)
99
else
10-
unsupported_reason_add(:provisioning, _('not connected to ems'))
10+
_('not connected to ems')
1111
end
1212
end
1313

app/models/manageiq/providers/ibm_cloud/power_virtual_servers/cloud_manager/vm.rb

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,44 @@ class ManageIQ::Providers::IbmCloud::PowerVirtualServers::CloudManager::Vm < Man
44
supports :capture
55
supports :terminate
66
supports :reboot_guest do
7-
unsupported_reason_add(:reboot_guest, _("The VM is not powered on")) unless current_state == "on"
7+
_("The VM is not powered on") unless current_state == "on"
88
end
99
supports :reset do
10-
unsupported_reason_add(:reset, _("The VM is not powered on")) unless current_state == "on"
10+
_("The VM is not powered on") unless current_state == "on"
1111
end
1212
supports :snapshots
1313
supports :snapshot_create
1414
supports :revert_to_snapshot do
15-
unsupported_reason_add(:revert_to_snapshot, _("Cannot revert to snapshot while VM is running")) unless current_state == "off"
15+
_("Cannot revert to snapshot while VM is running") unless current_state == "off"
1616
end
1717
supports :remove_snapshot
1818
supports :remove_all_snapshots
1919

2020
supports_not :suspend
2121

2222
supports :publish do
23-
reason = _("Publish not supported because VM is blank") if blank?
24-
reason ||= _("Publish not supported because VM is orphaned") if orphaned?
25-
reason ||= _("Publish not supported because VM is archived") if archived?
26-
unsupported_reason_add(:publish, reason) if reason
23+
return _("Publish not supported because VM is blank") if blank?
24+
return _("Publish not supported because VM is orphaned") if orphaned?
25+
return _("Publish not supported because VM is archived") if archived?
2726
end
2827

28+
# TODO: converge these all into console and use unsupported_reason(:console) for all
2929
supports :html5_console do
30-
reason = _("VM Console not supported because VM is not powered on") unless current_state == "on"
31-
reason ||= _("VM Console not supported because VM is orphaned") if orphaned?
32-
reason ||= _("VM Console not supported because VM is archived") if archived?
33-
unsupported_reason_add(:html5_console, reason) if reason
30+
return _("VM Console not supported because VM is not powered on") unless current_state == "on"
31+
return _("VM Console not supported because VM is orphaned") if orphaned?
32+
return _("VM Console not supported because VM is archived") if archived?
3433
end
3534
supports :launch_html5_console
3635

3736
supports :native_console do
38-
reason ||= _("VM Console not supported because VM is orphaned") if orphaned?
39-
reason ||= _("VM Console not supported because VM is archived") if archived?
40-
unsupported_reason_add(:native_console, reason) if reason
37+
return _("VM Console not supported because VM is orphaned") if orphaned?
38+
return _("VM Console not supported because VM is archived") if archived?
4139
end
4240

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

4947
def cloud_instance_id

app/models/manageiq/providers/ibm_cloud/power_virtual_servers/network_manager/cloud_subnet.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class ManageIQ::Providers::IbmCloud::PowerVirtualServers::NetworkManager::CloudSubnet < ::CloudSubnet
22
supports :create
33
supports :delete do
4-
if number_of(:vms) > 0
5-
unsupported_reason_add(:delete, _("The Network has active VMIs related to it"))
6-
end
4+
_("The Network has active VMIs related to it") if number_of(:vms) > 0
75
end
86

97
def self.params_for_create(_ems)

app/models/manageiq/providers/ibm_cloud/power_virtual_servers/storage_manager/cloud_volume.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ class ManageIQ::Providers::IbmCloud::PowerVirtualServers::StorageManager::CloudV
22
supports :create
33
supports :clone
44
supports :delete do
5-
unsupported_reason_add(:delete, _("the volume is not connected to an active Provider")) unless ext_management_system
6-
unsupported_reason_add(:delete, _("cannot delete volume that is in use.")) if status == "in-use"
5+
return _("the volume is not connected to an active Provider") unless ext_management_system
6+
return _("cannot delete volume that is in use.") if status == "in-use"
77
end
88
supports_not :snapshot_create
99
supports_not :update
1010
supports :attach do
11-
unsupported_reason_add(:attach, _("the volume is not connected to an active Provider")) unless ext_management_system
12-
unsupported_reason_add(:attach, _("cannot attach non-shareable volume that is in use.")) if status == "in-use" && !multi_attachment
11+
return _("the volume is not connected to an active Provider") unless ext_management_system
12+
return _("cannot attach non-shareable volume that is in use.") if status == "in-use" && !multi_attachment
1313
end
1414
supports :detach do
15-
unsupported_reason_add(:detach, _("the volume is not connected to an active Provider")) unless ext_management_system
16-
unsupported_reason_add(:detach, _("the volume status is '%{status}' but should be 'in-use'") % {:status => status}) unless status == "in-use"
15+
return _("the volume is not connected to an active Provider") unless ext_management_system
16+
return _("the volume status is '%{status}' but should be 'in-use'") % {:status => status} unless status == "in-use"
1717
end
1818

1919
def available_vms

app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/template.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ class ManageIQ::Providers::IbmCloud::VPC::CloudManager::Template < ManageIQ::Pro
66

77
supports :provisioning do
88
if ext_management_system
9-
unsupported_reason_add(:provisioning, ext_management_system.unsupported_reason(:provisioning)) unless ext_management_system.supports_provisioning?
9+
ext_management_system.unsupported_reason(:provisioning)
1010
else
11-
unsupported_reason_add(:provisioning, _('not connected to ems'))
11+
_('not connected to ems')
1212
end
1313
end
1414

app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/vm.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def raw_pause
7070

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

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

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

9898
# Force the the VM to restart.
@@ -101,7 +101,7 @@ def raw_reset
101101
end
102102

103103
supports :terminate do
104-
unsupported_reason_add(:terminate, unsupported_reason(:control)) unless supports_control?
104+
unsupported_reason(:control)
105105
end
106106

107107
def raw_destroy
@@ -112,8 +112,8 @@ def raw_destroy
112112
end
113113

114114
supports :resize do
115-
unsupported_reason_add(:resize, _('The VM is not powered off')) unless current_state == "off"
116-
unsupported_reason_add(:resize, _('The VM is not connected to a provider')) unless ext_management_system
115+
return _('The VM is not powered off') unless current_state == "off"
116+
return _('The VM is not connected to a provider') unless ext_management_system
117117
end
118118

119119
def raw_resize(options)

app/models/manageiq/providers/ibm_cloud/vpc/network_manager/cloud_network.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ class ManageIQ::Providers::IbmCloud::VPC::NetworkManager::CloudNetwork < ::Cloud
44
supports :create
55
supports :delete do
66
if ext_management_system.nil?
7-
unsupported_reason_add(:delete_cloud_network, _("The Cloud Network is not connected to an active %{table}") % {
7+
_("The Cloud Network is not connected to an active %{table}") % {
88
:table => ui_lookup(:table => "ext_management_systems")
9-
})
9+
}
1010
end
1111
end
1212

app/models/manageiq/providers/ibm_cloud/vpc/network_manager/cloud_subnet.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ class ManageIQ::Providers::IbmCloud::VPC::NetworkManager::CloudSubnet < ::CloudS
44
supports :create
55
supports :delete do
66
if ext_management_system.nil?
7-
unsupported_reason_add(:delete, _("The subnet is not connected to an active %{table}") % {
7+
_("The subnet is not connected to an active %{table}") % {
88
:table => ui_lookup(:table => "ext_management_systems")
9-
})
10-
end
11-
if number_of(:vms) > 0
12-
unsupported_reason_add(:delete, _("The subnet has an active %{table}") % {
9+
}
10+
elsif number_of(:vms) > 0
11+
_("The subnet has an active %{table}") % {
1312
:table => ui_lookup(:table => "vm_cloud")
14-
})
13+
}
1514
end
1615
end
1716

app/models/manageiq/providers/ibm_cloud/vpc/storage_manager/cloud_volume.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ class ManageIQ::Providers::IbmCloud::VPC::StorageManager::CloudVolume < ::CloudV
22
supports :create
33
supports :delete do
44
if ext_management_system.nil?
5-
unsupported_reason_add(:delete_volume, _("The Cloud Volume is not connected to an active %{table}") % {
5+
_("The Cloud Volume is not connected to an active %{table}") % {
66
:table => ui_lookup(:table => "ext_management_systems")
7-
})
7+
}
88
end
99
end
1010

0 commit comments

Comments
 (0)