Skip to content

Commit

Permalink
Add statuses to the host statuses page
Browse files Browse the repository at this point in the history
  • Loading branch information
kamils-iRonin committed Sep 17, 2021
1 parent cbad387 commit ebe30dc
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 241 deletions.
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
64 changes: 21 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,39 @@
# frozen_string_literal: true

module ForemanWreckingball
class CpuHotAddStatus < ::HostStatus::Status
OK = 0
PERFORMANCE_DEGRATION = 1
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

def self.status_name
N_('CPU Hot Plug')
end
OK = 0
PERFORMANCE_DEGRADATION = 1

def self.host_association
:vmware_cpu_hot_add_status_object
end
OK_STATUSES = [OK].freeze
WARN_STATUSES = [].freeze
ERROR_STATUSES = [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
LABELS = {
OK => N_('No Impact'),
PERFORMANCE_DEGRADATION => N_('Possible performance degradation')
}.freeze

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?
private

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
67 changes: 20 additions & 47 deletions app/models/foreman_wreckingball/operatingsystem_status.rb
Original file line number Diff line number Diff line change
@@ -1,68 +1,41 @@
# 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

def self.host_association
:vmware_operatingsystem_status_object
end

def self.description
N_('The VM operatingsystem should match the operatingsystem installed.')
end
OK_STATUSES = [OK].freeze
WARN_STATUSES = [MISMATCH].freeze
ERROR_STATUSES = [].freeze

def self.supports_remediate?
true
end
LABELS = {
OK => N_('OK'),
MISMATCH => N_('VM OS is incorrect')
}.freeze

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

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

private

def os_matches_identifier?
guest_id = host.vmware_facet.guest_id
vsphere_os = VsphereOsIdentifiers.lookup(guest_id)
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

0 comments on commit ebe30dc

Please sign in to comment.