Sha256: d0cb27f912c37751a922e7562e130aee5f0d1063c75fdaf1c2ce6cbab156cfe8

Contents?: true

Size: 950 Bytes

Versions: 6

Compression:

Stored size: 950 Bytes

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class Xen < BaseResolver
      @semaphore = Mutex.new
      @fact_list ||= {}

      XEN_PATH = '/proc/xen/capabilities'

      class << self
        private

        def post_resolve(fact_name)
          @fact_list.fetch(fact_name) { detect_xen(fact_name) }
        end

        def detect_xen(fact_name)
          @fact_list[:vm] = detect_xen_type
          @fact_list[:privileged] = privileged?(@fact_list[:vm])

          @fact_list[fact_name]
        end

        def detect_xen_type
          xen_type = 'xen0' if File.exist?('/dev/xen/evtchn')
          xen_type = 'xenu' if !xen_type && (File.exist?('/proc/xen') || File.exist?('/dev/xvda1'))

          xen_type
        end

        def privileged?(xen_type)
          content = Util::FileHelper.safe_read(XEN_PATH, nil)
          content&.strip == 'control_d' || xen_type == 'xen0'
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facter-4.0.35 lib/facter/resolvers/xen.rb
facter-4.0.34 lib/facter/resolvers/xen.rb
facter-4.0.33 lib/facter/resolvers/xen.rb
facter-4.0.32 lib/facter/resolvers/xen.rb
facter-4.0.31 lib/facter/resolvers/xen.rb
facter-4.0.30 lib/facter/resolvers/xen.rb