diff options
author | James Turnbull <james@lovedthanlost.net> | 2008-08-04 07:53:36 +1000 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-08-04 07:53:36 +1000 |
commit | 91ca4abba2fdf100c83790408d4fefa38dddc6f9 (patch) | |
tree | 86e469f6e41a40fcedf4235640d00dfb797b93e1 /lib/facter/virtual.rb | |
parent | ff45c8639dae54e48890ab780653d4f039b02afc (diff) | |
download | facter-91ca4abba2fdf100c83790408d4fefa38dddc6f9.tar.gz facter-91ca4abba2fdf100c83790408d4fefa38dddc6f9.tar.xz facter-91ca4abba2fdf100c83790408d4fefa38dddc6f9.zip |
Fixed #1490 - Added virtual fact
Diffstat (limited to 'lib/facter/virtual.rb')
-rw-r--r-- | lib/facter/virtual.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb new file mode 100644 index 0000000..d84397d --- /dev/null +++ b/lib/facter/virtual.rb @@ -0,0 +1,62 @@ +Facter.add("virtual") do + confine :kernel => %w{Linux FreeBSD OpenBSD} + + ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin" + + result = "physical" + + setcode do + + if FileTest.exists?("/proc/user_beancounters") + result = "openvz" + end + + if FileTest.exists?("/proc/sys/xen/independent_wallclock") + result = "xenu" + elsif FileTest.exists?("/proc/xen/capabilities") + txt = File.read("/proc/xen/capabilities") + if txt =~ /control_d/i + result = "xen0" + end + end + + if result == "physical" + lspciexists = system "which lspci > /dev/null 2>&1" + if $?.exitstatus == 0 + output = %x{lspci} + output.each {|p| + # --- look for the vmware video card to determine if it is virtual => vmware. + # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter + result = "vmware" if p =~ /VM[wW]are/ + } + else + dmidecodeexists = system "which dmidecode > /dev/null 2>&1" + if $?.exitstatus == 0 + outputd = %x{dmidecode} + outputd.each {|pd| + result = "vmware" if pd =~ /VMware|Parallels/ + } + end + end + end + + # VMware server 1.0.3 rpm places vmware-vmx in this place, other versions or platforms may not. + if FileTest.exists?("/usr/lib/vmware/bin/vmware-vmx") + result = "vmware_server" + end + + mountexists = system "which mount > /dev/null 2>&1" + if $?.exitstatus == 0 + output = %x{mount} + output.each {|p| + result = "vserver" if p =~ /\/dev\/hdv1/ + } + end + + if FileTest.directory?('/proc/virtual') + result = "vserver_host" + end + + result + end +end |