Facter::Util::Virtual

Public Class Methods

hpvm?() click to toggle source
# File lib/facter/util/virtual.rb, line 94
def self.hpvm?
  Facter::Util::Resolution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/
end
jail?() click to toggle source
# File lib/facter/util/virtual.rb, line 86
def self.jail?
  path = case Facter.value(:kernel)
    when "FreeBSD" then "/sbin"
    when "GNU/kFreeBSD" then "/bin"
  end
  Facter::Util::Resolution.exec("#{path}/sysctl -n security.jail.jailed") == "1"
end
kvm?() click to toggle source
# File lib/facter/util/virtual.rb, line 70
def self.kvm?
   txt = if FileTest.exists?("/proc/cpuinfo")
     File.read("/proc/cpuinfo")
   elsif ["FreeBSD", "OpenBSD"].include? Facter.value(:kernel)
     Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model")
   end
   (txt =~ /QEMU Virtual CPU/) ? true : false
end
kvm_type() click to toggle source
# File lib/facter/util/virtual.rb, line 79
def self.kvm_type
  # TODO Tell the difference between kvm and qemu
  # Can't work out a way to do this at the moment that doesn't
  # require a special binary
  "kvm"
end
lspci(command = "lspci 2>/dev/null") click to toggle source

lspci is a delegating helper method intended to make it easier to stub the system call without affecting other calls to Facter::Util::Resolution.exec

# File lib/facter/util/virtual.rb, line 13
def self.lspci(command = "lspci 2>/dev/null")
  Facter::Util::Resolution.exec command
end
openvz?() click to toggle source
# File lib/facter/util/virtual.rb, line 17
def self.openvz?
  FileTest.directory?("/proc/vz") and not self.openvz_cloudlinux?
end
openvz_cloudlinux?() click to toggle source

Cloudlinux uses OpenVZ to a degree, but always has an empty /proc/vz/ and has /proc/lve/list present

# File lib/facter/util/virtual.rb, line 36
def self.openvz_cloudlinux?
  FileTest.file?("/proc/lve/list") or Dir.glob('/proc/vz/*').empty?
end
openvz_type() click to toggle source

So one can either have #6728 work on OpenVZ or Cloudlinux. Whoo.

# File lib/facter/util/virtual.rb, line 22
def self.openvz_type
  return false unless self.openvz?
  return false unless FileTest.exists?( '/proc/self/status' )

  envid = Facter::Util::Resolution.exec( 'grep "envID" /proc/self/status' )
  if envid =~ /^envID:\s+0$/
  return 'openvzhn'
  elsif envid =~ /^envID:\s+(\d+)$/
  return 'openvzve'
  end
end
virt_what(command = "virt-what") click to toggle source

virt_what is a delegating helper method intended to make it easier to stub the system call without affecting other calls to Facter::Util::Resolution.exec

# File lib/facter/util/virtual.rb, line 6
def self.virt_what(command = "virt-what")
  Facter::Util::Resolution.exec command
end
vserver?() click to toggle source
# File lib/facter/util/virtual.rb, line 47
def self.vserver?
  return false unless FileTest.exists?("/proc/self/status")
  txt = File.open("/proc/self/status", "rb").read
  return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/
  return false
end
vserver_type() click to toggle source
# File lib/facter/util/virtual.rb, line 54
def self.vserver_type
  if self.vserver?
    if FileTest.exists?("/proc/virtual")
      "vserver_host"
    else
      "vserver"
    end
  end
end
xen?() click to toggle source
# File lib/facter/util/virtual.rb, line 64
def self.xen?
  ["/proc/sys/xen", "/sys/bus/xen", "/proc/xen" ].detect do |f|
    FileTest.exists?(f)
  end
end
zlinux?() click to toggle source
# File lib/facter/util/virtual.rb, line 98
def self.zlinux?
 "zlinux"
end
zone?() click to toggle source
# File lib/facter/util/virtual.rb, line 40
def self.zone?
  return true if FileTest.directory?("/.SUNWnative")
  z = Facter::Util::Resolution.exec("/sbin/zonename")
  return false unless z
  return z.chomp != 'global'
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.