Module: Facter::Manufacturer

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

Overview

mamufacturer.rb Support methods for manufacturer specific facts

Class Method Summary collapse

Class Method Details

.dmi_find_system_info(name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/facter/util/manufacturer.rb', line 30

def self.dmi_find_system_info(name)
    splitstr=  Facter.value(:kernel) ==  'SunOS' ? "ID    SIZE TYPE" : /^Handle/
    output = self.get_dmi_table()
    return if output.nil?
    name.each_pair do |key,v|
        v.each do |v2|
            v2.each_pair do |value,facterkey|
                output.split(splitstr).each do |line|
                    if line =~ /#{key}/ and line =~ /\n\s+#{value} (.+)\n/
                        result = $1.strip
                        Facter.add(facterkey) do
                            confine :kernel => [ :linux, :freebsd, :netbsd, :sunos, :gnu/kfreebsd" ]
                            setcode do
                                result
                            end
                        end
                    end
                end
            end
        end
    end
end

.get_dmi_tableObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/facter/util/manufacturer.rb', line 6

def self.get_dmi_table()
    case Facter.value(:kernel)
    when 'Linux', 'GNU/kFreeBSD'
        return nil unless FileTest.exists?("/usr/sbin/dmidecode")

        output=%x{/usr/sbin/dmidecode 2>/dev/null}
    when 'FreeBSD'
        return nil unless FileTest.exists?("/usr/local/sbin/dmidecode")

        output=%x{/usr/local/sbin/dmidecode 2>/dev/null}
    when 'NetBSD'
        return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode")

        output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
    when 'SunOS'
        return nil unless FileTest.exists?("/usr/sbin/smbios")

        output=%x{/usr/sbin/smbios 2>/dev/null}
    else
        output=nil
    end
    return output
end

.prtdiag_sparc_find_system_infoObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/facter/util/manufacturer.rb', line 64

def self.prtdiag_sparc_find_system_info()
    # Parses prtdiag for a SPARC architecture string, won't work with Solaris x86
    output = Facter::Util::Resolution.exec('/usr/sbin/prtdiag')

    # System Configuration:  Sun Microsystems  sun4u Sun SPARC Enterprise M3000 Server
    sysconfig = output.split("\n")[0]
    if sysconfig =~ /^System Configuration:\s+(.+?)\s+(sun\d+\S+)\s+(.+)/ then
        Facter.add('manufacturer') do
            setcode do
                $1
            end
        end
        Facter.add('productname') do
            setcode do
                $3
            end
        end
    end
end

.sysctl_find_system_info(name) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/facter/util/manufacturer.rb', line 53

def self.sysctl_find_system_info(name)
    name.each do |sysctlkey,facterkey|
        Facter.add(facterkey) do
            confine :kernel => :openbsd
            setcode do
                Facter::Util::Resolution.exec("sysctl -n " + sysctlkey)
            end
        end
    end
end

.win32_find_system_info(name) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/facter/util/manufacturer.rb', line 84

def self.win32_find_system_info(name)
    require 'facter/util/wmi'
    value = ""
    wmi = Facter::Util::WMI.connect()
    name.each do |facterkey, win32key|
        query = wmi.ExecQuery("select * from Win32_#{win32key.last}")
        Facter.add(facterkey) do
            confine :kernel => :windows
            setcode do
                query.each { |x| value = x.__send__( (win32key.first).to_sym) }
                value
            end
        end
    end
end