~gandelman-a/ubuntu/precise/facter/merge922788

« back to all changes in this revision

Viewing changes to lib/facter/virtual.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-11-06 00:52:19 UTC
  • mfrom: (1.1.6 upstream) (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091106005219-6ccua0q7b885z2ad
Tags: 1.5.6-2ubuntu1
* Merge from debian testing, remaining changes:
  - Use bind9-host9 only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
    result = "physical"
5
5
 
6
6
    setcode do
7
 
        if FileTest.exists?("/proc/user_beancounters")
8
 
            # openvz. can be hardware node or virtual environment
9
 
            # read the init process' status file, it has laxer permissions
10
 
            # than /proc/user_beancounters (so this won't fail as non-root)
11
 
            txt = File.read("/proc/1/status")
12
 
            if txt =~ /^envID:[[:blank:]]+0$/mi
 
7
    require 'thread'
 
8
 
 
9
        if FileTest.exists?("/sbin/zonename")
 
10
            z = %x{"/sbin/zonename"}.chomp
 
11
            if z != 'global'
 
12
                result = 'zone' 
 
13
            end
 
14
        end
 
15
 
 
16
        if FileTest.exists?("/proc/vz/veinfo")
 
17
            if FileTest.exists?("/proc/vz/version")
13
18
                result = "openvzhn"
14
19
            else
15
20
                result = "openvzve"
16
21
            end
17
22
        end
18
23
 
19
 
        if FileTest.exists?("/proc/xen/capabilities") && FileTest.readable?("/proc/xen/capabilities")
 
24
        if FileTest.exists?("/proc/self/status")
 
25
            txt = File.read("/proc/self/status")
 
26
            if txt =~ /^(s_context|VxID):[[:blank:]]*[1-9]/
 
27
                result = "vserver"
 
28
            end
 
29
        end
 
30
 
 
31
        if FileTest.exists?("/proc/virtual")
 
32
            result = "vserver_host"
 
33
        end
 
34
 
 
35
        # new Xen domains have this in dom0 not domu :(
 
36
        if FileTest.exists?("/proc/sys/xen/independent_wallclock")
 
37
            result = "xenu" 
 
38
        end
 
39
        if FileTest.exists?("/sys/bus/xen")
 
40
            result = "xenu" 
 
41
        end
 
42
        
 
43
        if FileTest.exists?("/proc/xen/capabilities")
20
44
            txt = File.read("/proc/xen/capabilities")
21
45
            if txt =~ /control_d/i
22
 
                result = "xen0"
23
 
            else
24
 
                result = "xenu"
 
46
                result = "xen0" 
25
47
            end
26
48
        end
27
 
 
 
49
 
28
50
        if result == "physical"
29
 
            path = %x{which lspci 2> /dev/null}.chomp
30
 
            if path !~ /no lspci/
31
 
                output = %x{#{path}}
32
 
                output.each do |p|
 
51
            output = Facter::Util::Resolution.exec('lspci')
 
52
            if not output.nil?
 
53
                output.each_line do |p|
33
54
                    # --- look for the vmware video card to determine if it is virtual => vmware.
34
55
                    # ---     00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter
35
56
                    result = "vmware" if p =~ /VM[wW]are/
36
57
                end
37
58
            else
38
 
                path = %x{which dmidecode 2> /dev/null}.chomp
39
 
                if path !~ /no dmidecode/
40
 
                    output = %x{#{path}}
41
 
                    output.each do |pd|
 
59
                output = Facter::Util::Resolution.exec('dmidecode')
 
60
                if not output.nil?
 
61
                    output.each_line do |pd|
42
62
                        result = "vmware" if pd =~ /VMware|Parallels/
43
63
                    end
44
64
                else
45
 
                    path = %x{which prtdiag 2> /dev/null}.chomp
46
 
                    if path !~ /no prtdiag/
47
 
                        output = %x{#{path}}
48
 
                        output.each do |pd|
 
65
                    output = Facter::Util::Resolution.exec('prtdiag')
 
66
                    if not output.nil?
 
67
                        output.each_line do |pd|
49
68
                            result = "vmware" if pd =~ /VMware|Parallels/
50
69
                        end
51
70
                    end
58
77
            result = "vmware_server"
59
78
        end
60
79
 
61
 
        mountexists = system "which mount > /dev/null 2>&1"
62
 
        if $?.exitstatus == 0
63
 
            output = %x{mount}
64
 
            output.each do |p|
65
 
                result = "vserver" if p =~ /\/dev\/hdv1/
66
 
            end
67
 
        end
68
 
 
69
 
        if FileTest.directory?('/proc/virtual')
70
 
            result = "vserver_host"
71
 
        end
72
 
 
73
80
        result
74
81
    end
75
82
end
 
83
  
 
84
Facter.add("is_virtual") do
 
85
    confine :kernel => %w{Linux FreeBSD OpenBSD SunOS}
 
86
 
 
87
    setcode do
 
88
        case Facter.value(:virtual)
 
89
        when "xenu", "openvzve", "vmware" 
 
90
            true
 
91
        else 
 
92
            false
 
93
        end
 
94
    end
 
95
end