Sha256: 30e520d65a415f53f5bfb7f549093bf0fbe44bc8f2bfa6037e5e698a142c9bf8

Contents?: true

Size: 1.45 KB

Versions: 64

Compression:

Stored size: 1.45 KB

Contents

module Katello
  class PurposeStatus < HostStatus::Status
    UNKNOWN = 0
    MISMATCHED = 1
    MATCHED = 2
    NOT_SPECIFIED = 3

    def self.status_map
      map = {
        mismatched: MISMATCHED,
        matched: MATCHED,
        not_specified: NOT_SPECIFIED
      }

      map.default = UNKNOWN
      map
    end

    def self.status_name
      N_('System Purpose')
    end

    def self.humanized_name
      'purpose'
    end

    def self.to_label(status)
      case status
      when MATCHED
        N_('Matched')
      when MISMATCHED
        N_('Mismatched')
      when NOT_SPECIFIED
        N_('Not Specified')
      else
        N_('Unknown')
      end
    end

    def self.to_status(status, purpose_method, options)
      return UNKNOWN unless status.relevant?

      if options.key?(:status_override)
        return self.status_map[options[:status_override]]
      end

      consumer = status.host.subscription_facet.candlepin_consumer
      self.status_map[consumer.system_purpose.send(purpose_method)]
    end

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

    def to_global(_options = {})
      if [MATCHED, UNKNOWN, NOT_SPECIFIED].include?(status)
        ::HostStatus::Global::OK
      else
        ::HostStatus::Global::WARN
      end
    end

    def to_status(options = {})
      self.class.to_status(self, :overall_status, options)
    end

    def relevant?(_options = {})
      host.subscription_facet.try(:uuid)
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
katello-3.18.0.rc1 app/models/katello/purpose_status.rb
katello-3.17.0.rc2.2 app/models/katello/purpose_status.rb
katello-3.17.0.rc2.1 app/models/katello/purpose_status.rb
katello-3.17.0.rc2 app/models/katello/purpose_status.rb