Module: Facter::Util::Virtual

Defined in:
lib/facter/util/virtual.rb

Class Method Summary (collapse)

Class Method Details

+ (Boolean) hpvm?



69
70
71
# File 'lib/facter/util/virtual.rb', line 69

def self.hpvm?
    Facter::Util::Resolution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/
end

+ (Boolean) jail?



61
62
63
64
65
66
67
# File 'lib/facter/util/virtual.rb', line 61

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

+ (Boolean) kvm?



45
46
47
48
49
50
51
52
# File 'lib/facter/util/virtual.rb', line 45

def self.kvm?
   txt = if FileTest.exists?("/proc/cpuinfo")
       File.read("/proc/cpuinfo")
   elsif Facter.value(:kernel)=="FreeBSD"
       Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model")
   end
   (txt =~ /QEMU Virtual CPU/) ? true : false
end

+ (Object) kvm_type



54
55
56
57
58
59
# File 'lib/facter/util/virtual.rb', line 54

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

+ (Boolean) openvz?



2
3
4
# File 'lib/facter/util/virtual.rb', line 2

def self.openvz?
    FileTest.directory?("/proc/vz") and FileTest.exists?( '/proc/vz/veinfo' )
end

+ (Object) openvz_type



6
7
8
9
10
11
12
13
# File 'lib/facter/util/virtual.rb', line 6

def self.openvz_type
    return nil unless self.openvz?
    if FileTest.exists?("/proc/vz/version")
        result = "openvzhn"
    else
        result = "openvzve"
    end
end

+ (Boolean) vserver?



22
23
24
25
26
27
# File 'lib/facter/util/virtual.rb', line 22

def self.vserver?
    return false unless FileTest.exists?("/proc/self/status")
    txt = File.read("/proc/self/status")
    return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/
    return false
end

+ (Object) vserver_type



29
30
31
32
33
34
35
36
37
# File 'lib/facter/util/virtual.rb', line 29

def self.vserver_type
    if self.vserver?
        if FileTest.exists?("/proc/virtual")
            "vserver_host"
        else
            "vserver"
        end
    end
end

+ (Boolean) xen?



39
40
41
42
43
# File 'lib/facter/util/virtual.rb', line 39

def self.xen?
    ["/proc/sys/xen", "/sys/bus/xen", "/proc/xen" ].detect do |f|
        FileTest.exists?(f)
    end
end

+ (Boolean) zlinux?



73
74
75
# File 'lib/facter/util/virtual.rb', line 73

def self.zlinux?
     "zlinux"
end

+ (Boolean) zone?



15
16
17
18
19
20
# File 'lib/facter/util/virtual.rb', line 15

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