Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statuses to the host statuses page #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/models/concerns/foreman_wreckingball/host_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ module HostExtensions

included do
ForemanWreckingball::Engine::WRECKINGBALL_STATUSES.map(&:constantize).each do |status|
has_one(status.host_association, class_name: status.to_s,
foreign_key: 'host_id',
inverse_of: :host,
dependent: :destroy)
has_one(status::HOST_ASSOCIATION, class_name: status.to_s,
foreign_key: 'host_id',
inverse_of: :host,
dependent: :destroy)

scoped_search :relation => status::HOST_ASSOCIATION,
:on => :status,
:rename => status::HOST_ASSOCIATION.to_s.chomp('_object'),
:only_explicit => true,
:operators => ['=', '!=', '<>'],
:complete_value => status::SEARCH_VALUES
end

scope :owned_by_current_user, -> { where(owner_type: 'User', owner_id: User.current.id) }
Expand Down
62 changes: 19 additions & 43 deletions app/models/foreman_wreckingball/cpu_hot_add_status.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,37 @@
# frozen_string_literal: true

module ForemanWreckingball
class CpuHotAddStatus < ::HostStatus::Status
class CpuHotAddStatus < ::ForemanWreckingball::Status
NAME = N_('CPU Hot Plug').freeze
DESCRIPTION = N_('Enabling CPU hot-add disables vNUMA, the virtual machine will instead use UMA. This might cause a performance degradation.').freeze
HOST_ASSOCIATION = :vmware_cpu_hot_add_status_object

OK = 0
PERFORMANCE_DEGRATION = 1
PERFORMANCE_DEGRADATION = 1

def self.status_name
N_('CPU Hot Plug')
end
OK_STATUSES = [OK].freeze
WARN_STATUSES = [].freeze
ERROR_STATUSES = [PERFORMANCE_DEGRADATION].freeze

def self.host_association
:vmware_cpu_hot_add_status_object
end
LABELS = {
OK => N_('No Impact'),
PERFORMANCE_DEGRADATION => N_('Possible performance degradation')
}.freeze

def self.description
N_('Enabling CPU hot-add disables vNUMA, the virtual machine will instead use UMA. This might cause a performance degration.')
end

def self.supports_remediate?
false
end
SEARCH_VALUES = {
ok: OK,
performance_degradation: PERFORMANCE_DEGRADATION
}.freeze

def to_status(_options = {})
performance_degration? ? PERFORMANCE_DEGRATION : OK
end

def to_global(_options = {})
self.class.to_global(status)
end

def self.to_global(status)
case status
when PERFORMANCE_DEGRATION
HostStatus::Global::ERROR
else
HostStatus::Global::OK
end
end

def self.global_ok_list
[OK]
end

def to_label(_options = {})
case status
when PERFORMANCE_DEGRATION
N_('Possible performance degration')
else
N_('No Impact')
end
performance_degradation? ? PERFORMANCE_DEGRADATION : OK
end

def relevant?(_options = {})
host&.vmware_facet && host.vmware_facet.try(:cpu_hot_add?)
end

def performance_degration?
def performance_degradation?
min_cores = hypervisor_min_cores
return false unless min_cores
host.vmware_facet.cpu_hot_add? && host.vmware_facet.cpus > min_cores
Expand Down
65 changes: 18 additions & 47 deletions app/models/foreman_wreckingball/hardware_version_status.rb
Original file line number Diff line number Diff line change
@@ -1,64 +1,35 @@
# frozen_string_literal: true

module ForemanWreckingball
class HardwareVersionStatus < ::HostStatus::Status
class HardwareVersionStatus < ::ForemanWreckingball::Status
NAME = N_('vSphere Hardware Version').freeze
DESCRIPTION = N_('In order to use recent vSphere features, the VM must use a recent virtual hardware version.').freeze
HOST_ASSOCIATION = :vmware_hardware_version_status_object

OK = 0
OUTOFDATE = 1

def self.status_name
N_('vSphere Hardware Version')
end
OK_STATUSES = [OK].freeze
WARN_STATUSES = [OUTOFDATE].freeze
ERROR_STATUSES = [].freeze

def self.host_association
:vmware_hardware_version_status_object
end
LABELS = {
OK => N_('OK'),
OUTOFDATE => N_('Out of date')
}.freeze

def self.description
N_('In order to use recent vSphere features, the VM must use a recent virtual hardware version.')
end
SEARCH_VALUES = {
ok: OK,
out_of_date: OUTOFDATE
}.freeze

def self.supports_remediate?
true
end

def self.dangerous_remediate?
true
end

def self.remediate_action
::Actions::ForemanWreckingball::Host::RemediateHardwareVersion
end
REMEDIATE_ACTION = ::Actions::ForemanWreckingball::Host::RemediateHardwareVersion
DANGEROUS_REMEDIATE = true

def to_status(_options = {})
recent_hw_version? ? OK : OUTOFDATE
end

def to_global(_options = {})
self.class.to_global(status)
end

def self.to_global(status)
case status
when OUTOFDATE
HostStatus::Global::WARN
else
HostStatus::Global::OK
end
end

def self.global_ok_list
[OK]
end

def to_label(_options = {})
case status
when OUTOFDATE
N_('Out of date')
else
N_('OK')
end
end

def relevant?(_options = {})
host && host&.vmware_facet && host.vmware_facet.hardware_version.present?
end
Expand Down
65 changes: 18 additions & 47 deletions app/models/foreman_wreckingball/operatingsystem_status.rb
Original file line number Diff line number Diff line change
@@ -1,64 +1,35 @@
# frozen_string_literal: true

module ForemanWreckingball
class OperatingsystemStatus < ::HostStatus::Status
class OperatingsystemStatus < ::ForemanWreckingball::Status
NAME = N_('VM Operatingsystem').freeze
DESCRIPTION = N_('The VM operatingsystem should match the operatingsystem installed.').freeze
HOST_ASSOCIATION = :vmware_operatingsystem_status_object

OK = 0
MISMATCH = 1

def self.status_name
N_('VM Operatingsystem')
end
OK_STATUSES = [OK].freeze
WARN_STATUSES = [MISMATCH].freeze
ERROR_STATUSES = [].freeze

def self.host_association
:vmware_operatingsystem_status_object
end

def self.description
N_('The VM operatingsystem should match the operatingsystem installed.')
end
LABELS = {
OK => N_('OK'),
MISMATCH => N_('VM OS is incorrect')
}.freeze

def self.supports_remediate?
true
end
SEARCH_VALUES = {
ok: OK,
mismatch: MISMATCH
}.freeze

def self.dangerous_remediate?
true
end

def self.remediate_action
::Actions::ForemanWreckingball::Host::RemediateVmwareOperatingsystem
end
REMEDIATE_ACTION = ::Actions::ForemanWreckingball::Host::RemediateVmwareOperatingsystem
DANGEROUS_REMEDIATE = true

def to_status(_options = {})
os_matches_identifier? ? OK : MISMATCH
end

def to_global(_options = {})
self.class.to_global(status)
end

def self.to_global(status)
case status
when MISMATCH
HostStatus::Global::WARN
else
HostStatus::Global::OK
end
end

def self.global_ok_list
[OK]
end

def to_label(_options = {})
case status
when MISMATCH
N_('VM OS is incorrect')
else
N_('OK')
end
end

def relevant?(_options = {})
host&.vmware_facet
end
Expand Down
65 changes: 18 additions & 47 deletions app/models/foreman_wreckingball/spectre_v2_status.rb
Original file line number Diff line number Diff line change
@@ -1,64 +1,35 @@
# frozen_string_literal: true

module ForemanWreckingball
class SpectreV2Status < ::HostStatus::Status
class SpectreV2Status < ::ForemanWreckingball::Status
NAME = N_('Spectre v2 Guest Mitigation Enabled').freeze
DESCRIPTION = N_('In order to use hardware based branch target injection mitigation within virtual machines, Hypervisor-Assisted Guest Mitigation must be enabled.').freeze
HOST_ASSOCIATION = :vmware_spectre_v2_status_object

ENABLED = 0
MISSING = 1

def self.status_name
N_('Spectre v2 Guest Mitigation Enabled')
end
OK_STATUSES = [ENABLED].freeze
WARN_STATUSES = [].freeze
ERROR_STATUSES = [MISSING].freeze

def self.host_association
:vmware_spectre_v2_status_object
end
LABELS = {
ENABLED => N_('Guest Mitigation Enabled'),
MISSING => N_('Guest Mitigation Missing')
}.freeze

def self.description
N_('In order to use hardware based branch target injection mitigation within virtual machines, Hypervisor-Assisted Guest Mitigation must be enabled.')
end
SEARCH_VALUES = {
enabled: ENABLED,
missing: MISSING
}.freeze

def self.supports_remediate?
true
end

def self.dangerous_remediate?
true
end

def self.remediate_action
::Actions::ForemanWreckingball::Host::RemediateSpectreV2
end
REMEDIATE_ACTION = ::Actions::ForemanWreckingball::Host::RemediateSpectreV2
DANGEROUS_REMEDIATE = true

def to_status(_options = {})
guest_mitigation_enabled? ? ENABLED : MISSING
end

def to_global(_options = {})
self.class.to_global(status)
end

def self.to_global(status)
case status
when MISSING
HostStatus::Global::ERROR
else
HostStatus::Global::OK
end
end

def self.global_ok_list
[ENABLED]
end

def to_label(_options = {})
case status
when MISSING
N_('Guest Mitigation Missing')
else
N_('Guest Mitigation Enabled')
end
end

def relevant?(_options = {})
host && host&.vmware_facet && host.vmware_facet.hardware_version.present? && host.vmware_facet.cpu_features.any?
end
Expand Down
Loading