class Facter::Resolvers::Xen

Constants

XEN_COMMANDS
XEN_PATH
XEN_TOOLSTACK

Private Class Methods

detect_domains() click to toggle source
# File lib/facter/resolvers/xen.rb, line 38
def detect_domains
  domains = []
  xen_command = find_command
  return unless xen_command

  output = Facter::Core::Execution.execute("#{xen_command} list", logger: log)
  return if output.empty?

  output.each_line do |line|
    next if line =~ /Domain-0|Name/

    domain = line.match(/^([^\s]*)\s/)
    domain = domain&.captures&.first
    domains << domain if domain
  end

  domains
end
detect_xen(fact_name) click to toggle source
# File lib/facter/resolvers/xen.rb, line 18
def detect_xen(fact_name)
  @fact_list[:vm] = detect_xen_type
  @fact_list[:privileged] = privileged?(@fact_list[:vm])
  @fact_list[:domains] = detect_domains

  @fact_list[fact_name]
end
detect_xen_type() click to toggle source
# File lib/facter/resolvers/xen.rb, line 26
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
find_command() click to toggle source
# File lib/facter/resolvers/xen.rb, line 57
def find_command
  return XEN_TOOLSTACK if File.exist?(XEN_TOOLSTACK)

  XEN_COMMANDS.each { |command| return command if File.exist?(command) }
end
post_resolve(fact_name) click to toggle source
# File lib/facter/resolvers/xen.rb, line 14
def post_resolve(fact_name)
  @fact_list.fetch(fact_name) { detect_xen(fact_name) }
end
privileged?(xen_type) click to toggle source
# File lib/facter/resolvers/xen.rb, line 33
def privileged?(xen_type)
  content = Util::FileHelper.safe_read(XEN_PATH, nil)
  content&.strip == 'control_d' || xen_type == 'xen0'
end