facter 1.5 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of facter might be problematic. Click here for more details.
- data/CHANGELOG +51 -1
- data/Rakefile +10 -1
- data/conf/osx/PackageInfo.plist +36 -0
- data/conf/osx/createpackage.sh +167 -0
- data/conf/osx/preflight +11 -0
- data/conf/redhat/facter.spec +120 -0
- data/conf/solaris/pkginfo +7 -0
- data/documentation/custom.page +22 -0
- data/documentation/index.page +19 -0
- data/install.rb +227 -92
- data/lib/facter.rb +1 -1
- data/lib/facter/domain.rb +14 -0
- data/lib/facter/hardwaremodel.rb +8 -0
- data/lib/facter/ipaddress.rb +21 -2
- data/lib/facter/ipmess.rb +8 -37
- data/lib/facter/kernel.rb +7 -1
- data/lib/facter/kernelrelease.rb +16 -1
- data/lib/facter/kernelversion.rb +5 -0
- data/lib/facter/lsb.rb +1 -0
- data/lib/facter/macaddress.rb +15 -1
- data/lib/facter/operatingsystem.rb +6 -1
- data/lib/facter/operatingsystemrelease.rb +34 -7
- data/lib/facter/puppetversion.rb +1 -1
- data/lib/facter/util/ip.rb +37 -47
- data/lib/facter/util/manufacturer.rb +2 -2
- data/lib/facter/util/resolution.rb +13 -3
- data/lib/facter/virtual.rb +62 -0
- data/spec/Rakefile +18 -0
- data/spec/integration/facter.rb +27 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/data/linux_ifconfig_all_with_single_interface +18 -0
- data/spec/unit/data/solaris_ifconfig_single_interface +3 -0
- data/spec/unit/facter.rb +134 -0
- data/spec/unit/util/collection.rb +255 -0
- data/spec/unit/util/confine.rb +75 -0
- data/spec/unit/util/fact.rb +129 -0
- data/spec/unit/util/ip.rb +40 -0
- data/spec/unit/util/loader.rb +219 -0
- data/spec/unit/util/resolution.rb +209 -0
- metadata +31 -2
data/lib/facter/domain.rb
CHANGED
@@ -62,3 +62,17 @@ Facter.add(:domain) do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
+
Facter.add(:domain) do
|
66
|
+
confine :kernel => :windows
|
67
|
+
setcode do
|
68
|
+
require 'win32ole'
|
69
|
+
domain = ""
|
70
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
71
|
+
query = "select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True"
|
72
|
+
wmi.ExecQuery(query).each { |nic|
|
73
|
+
domain = nic.DNSDomain
|
74
|
+
break
|
75
|
+
}
|
76
|
+
domain
|
77
|
+
end
|
78
|
+
end
|
data/lib/facter/hardwaremodel.rb
CHANGED
data/lib/facter/ipaddress.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Facter.add(:ipaddress, :ldapname => "iphostnumber") do
|
1
|
+
Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
|
2
2
|
setcode do
|
3
3
|
require 'resolv'
|
4
4
|
|
@@ -19,7 +19,7 @@ Facter.add(:ipaddress, :ldapname => "iphostnumber") do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
Facter.add(:ipaddress) do
|
22
|
+
Facter.add(:ipaddress, :timeout => 2) do
|
23
23
|
setcode do
|
24
24
|
if hostname = Facter.value(:hostname)
|
25
25
|
# we need Hostname to exist for this to work
|
@@ -149,3 +149,22 @@ Facter.add(:ipaddress) do
|
|
149
149
|
ip
|
150
150
|
end
|
151
151
|
end
|
152
|
+
|
153
|
+
Facter.add(:ipaddress) do
|
154
|
+
confine :kernel => %w{windows}
|
155
|
+
setcode do
|
156
|
+
ip = nil
|
157
|
+
output = %x{ipconfig}
|
158
|
+
|
159
|
+
output.split(/^\S/).each { |str|
|
160
|
+
if str =~ /IP Address.*: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
161
|
+
tmp = $1
|
162
|
+
unless tmp =~ /127\./
|
163
|
+
ip = tmp
|
164
|
+
break
|
165
|
+
end
|
166
|
+
end
|
167
|
+
}
|
168
|
+
ip
|
169
|
+
end
|
170
|
+
end
|
data/lib/facter/ipmess.rb
CHANGED
@@ -15,61 +15,32 @@ Facter.add(:interfaces) do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
case Facter.value(:kernel)
|
18
|
-
when 'SunOS', 'Linux'
|
18
|
+
when 'SunOS', 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
|
19
19
|
Facter::IPAddress.get_interfaces.each do |interface|
|
20
|
-
mi = interface.gsub('
|
20
|
+
mi = interface.gsub('/:|\./', '_')
|
21
21
|
|
22
22
|
Facter.add("ipaddress_" + mi) do
|
23
|
-
confine :kernel => [ :sunos, :linux ]
|
23
|
+
confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
|
24
24
|
setcode do
|
25
25
|
label = 'ipaddress'
|
26
|
-
Facter::IPAddress.
|
26
|
+
Facter::IPAddress.get_interface_value(interface, label)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
Facter.add("macaddress_" + mi) do
|
31
|
-
confine :kernel => [ :sunos, :linux ]
|
31
|
+
confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
|
32
32
|
setcode do
|
33
33
|
label = 'macaddress'
|
34
|
-
Facter::IPAddress.
|
34
|
+
Facter::IPAddress.get_interface_value(interface, label)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
Facter.add("netmask_" + mi) do
|
39
|
-
confine :kernel => [ :sunos, :linux ]
|
39
|
+
confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
|
40
40
|
setcode do
|
41
41
|
label = 'netmask'
|
42
|
-
Facter::IPAddress.
|
42
|
+
Facter::IPAddress.get_interface_value(interface, label)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
47
|
-
when 'OpenBSD', 'NetBSD', 'FreeBSD'
|
48
|
-
Facter::IPAddress.get_interfaces.each do |interface|
|
49
|
-
mi = interface.gsub(':', '_')
|
50
|
-
|
51
|
-
Facter.add("ipaddress_" + mi) do
|
52
|
-
confine :kernel => [ :openbsd, :freebsd, :netbsd ]
|
53
|
-
setcode do
|
54
|
-
label = 'ipaddress'
|
55
|
-
Facter::IPAddress.get_interface_value_bsd(interface, label)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
Facter.add("netmask_" + mi) do
|
60
|
-
confine :kernel => [ :openbsd, :freebsd, :netbsd ]
|
61
|
-
setcode do
|
62
|
-
label = 'netmask'
|
63
|
-
Facter::IPAddress.get_interface_value_bsd(interface, label)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
Facter.add("macaddress_" + mi) do
|
68
|
-
confine :kernel => [ :openbsd, :freebsd, :netbsd ]
|
69
|
-
setcode do
|
70
|
-
label = 'macaddress'
|
71
|
-
Facter::IPAddress.get_interface_value_bsd(interface, label)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
46
|
end
|
data/lib/facter/kernel.rb
CHANGED
data/lib/facter/kernelrelease.rb
CHANGED
@@ -2,7 +2,22 @@ Facter.add(:kernelrelease) do
|
|
2
2
|
setcode 'uname -r'
|
3
3
|
end
|
4
4
|
|
5
|
-
Facter.add(:kernelrelease
|
5
|
+
Facter.add(:kernelrelease) do
|
6
6
|
confine :kernel => :aix
|
7
7
|
setcode 'oslevel -s'
|
8
8
|
end
|
9
|
+
|
10
|
+
Facter.add(:kernelrelease) do
|
11
|
+
confine :kernel => %{windows}
|
12
|
+
setcode do
|
13
|
+
require 'win32ole'
|
14
|
+
version = ""
|
15
|
+
connection_string = "winmgmts://./root/cimv2"
|
16
|
+
wmi = WIN32OLE.connect(connection_string)
|
17
|
+
wmi.ExecQuery("SELECT Version from Win32_OperatingSystem").each { |ole|
|
18
|
+
version = "#{ole.Version}"
|
19
|
+
break
|
20
|
+
}
|
21
|
+
version
|
22
|
+
end
|
23
|
+
end
|
data/lib/facter/lsb.rb
CHANGED
data/lib/facter/macaddress.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Facter.add(:macaddress) do
|
2
|
-
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
|
2
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo Ubuntu}
|
3
3
|
setcode do
|
4
4
|
ether = []
|
5
5
|
output = %x{/sbin/ifconfig -a}
|
@@ -63,3 +63,17 @@ Facter.add(:macaddress) do
|
|
63
63
|
ether[0]
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
Facter.add(:macaddress) do
|
68
|
+
confine :kernel => %w(windows)
|
69
|
+
setcode do
|
70
|
+
ether = []
|
71
|
+
output = %x{ipconfig /all}
|
72
|
+
output.split(/\r\n/).each do |str|
|
73
|
+
if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/
|
74
|
+
ether.push($1.gsub(/-/, ":"))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
ether[0]
|
78
|
+
end
|
79
|
+
end
|
@@ -26,7 +26,12 @@ Facter.add(:operatingsystem) do
|
|
26
26
|
"RedHat"
|
27
27
|
end
|
28
28
|
elsif FileTest.exists?("/etc/SuSE-release")
|
29
|
-
"SuSE"
|
29
|
+
txt = File.read("/etc/SuSE-release")
|
30
|
+
if txt =~ /^SUSE LINUX Enterprise Server/i
|
31
|
+
"SLES"
|
32
|
+
else
|
33
|
+
"SuSE"
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
@@ -29,11 +29,11 @@ end
|
|
29
29
|
Facter.add(:operatingsystemrelease) do
|
30
30
|
confine :operatingsystem => %w{CentOS}
|
31
31
|
setcode do
|
32
|
-
|
33
|
-
if
|
32
|
+
centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/ \((Branch|Final)\)//' /etc/redhat-release")
|
33
|
+
if centos_release =~ /5/
|
34
34
|
release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2')
|
35
35
|
else
|
36
|
-
release =
|
36
|
+
release = centos_release
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -41,10 +41,7 @@ end
|
|
41
41
|
Facter.add(:operatingsystemrelease) do
|
42
42
|
confine :operatingsystem => %w{Debian}
|
43
43
|
setcode do
|
44
|
-
release = Facter::Util::Resolution.exec('cat /
|
45
|
-
if release =~ /\(Debian (\d+.\d+).\d+-\d+\)/
|
46
|
-
$1
|
47
|
-
end
|
44
|
+
release = Facter::Util::Resolution.exec('cat /etc/debian_version')
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
@@ -58,6 +55,36 @@ Facter.add(:operatingsystemrelease) do
|
|
58
55
|
end
|
59
56
|
end
|
60
57
|
|
58
|
+
Facter.add(:operatingsystemrelease) do
|
59
|
+
confine :operatingsystem => %w{SLES}
|
60
|
+
setcode do
|
61
|
+
releasefile = Facter::Util::Resolution.exec('cat /etc/SuSE-release')
|
62
|
+
if releasefile =~ /^VERSION\s*=\s*(\d+)/
|
63
|
+
releasemajor = $1
|
64
|
+
if releasefile =~ /^PATCHLEVEL\s*=\s*(\d+)/
|
65
|
+
releaseminor = $1
|
66
|
+
else
|
67
|
+
releaseminor = 0
|
68
|
+
end
|
69
|
+
releasemajor + "." + releaseminor
|
70
|
+
else
|
71
|
+
"unknown"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Facter.add(:operatingsystemrelease) do
|
77
|
+
confine :operatingsystem => %w{Solaris}
|
78
|
+
setcode do
|
79
|
+
full_release = File.readlines("/etc/release").to_s.match(/Solaris \w+ [\w\/]+ ([^_]+_[^_]+)/).to_a.last.chomp("wos")
|
80
|
+
if full_release =~ /^s(\d+)\w(_\w\d)+/
|
81
|
+
$1 + $2
|
82
|
+
else
|
83
|
+
full_release
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
61
88
|
Facter.add(:operatingsystemrelease) do
|
62
89
|
setcode do Facter[:kernelrelease].value end
|
63
90
|
end
|
data/lib/facter/puppetversion.rb
CHANGED
data/lib/facter/util/ip.rb
CHANGED
@@ -4,13 +4,8 @@ module Facter::IPAddress
|
|
4
4
|
|
5
5
|
int = nil
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
output = %x{/sbin/ifconfig -a}
|
10
|
-
when 'SunOS'
|
11
|
-
output = %x{/usr/sbin/ifconfig -a}
|
12
|
-
end
|
13
|
-
|
7
|
+
output = Facter::IPAddress.get_all_interface_output()
|
8
|
+
|
14
9
|
# We get lots of warnings on platforms that don't get an output
|
15
10
|
# made.
|
16
11
|
if output
|
@@ -20,24 +15,43 @@ module Facter::IPAddress
|
|
20
15
|
end
|
21
16
|
|
22
17
|
end
|
18
|
+
|
19
|
+
def self.get_all_interface_output
|
20
|
+
case Facter.value(:kernel)
|
21
|
+
when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
|
22
|
+
output = %x{/sbin/ifconfig -a}
|
23
|
+
when 'SunOS'
|
24
|
+
output = %x{/usr/sbin/ifconfig -a}
|
25
|
+
end
|
26
|
+
output
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get_single_interface_output(interface)
|
30
|
+
output = ""
|
31
|
+
case Facter.value(:kernel)
|
32
|
+
when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
|
33
|
+
output = %x{/sbin/ifconfig #{interface}}
|
34
|
+
when 'SunOS'
|
35
|
+
output = %x{/usr/sbin/ifconfig #{interface}}
|
36
|
+
end
|
37
|
+
output
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def self.get_interface_value(interface, label)
|
23
42
|
|
24
|
-
|
25
|
-
|
26
|
-
tmp1 = nil
|
43
|
+
tmp1 = []
|
27
44
|
|
28
45
|
case Facter.value(:kernel)
|
29
46
|
when 'Linux'
|
30
|
-
output_int = %x{/sbin/ifconfig #{interface}}
|
31
47
|
addr = /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
32
48
|
mac = /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
|
33
49
|
mask = /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
34
50
|
when 'OpenBSD', 'NetBSD', 'FreeBSD'
|
35
|
-
output_int = %x{/sbin/ifconfig #{interface}}
|
36
51
|
addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
37
52
|
mac = /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
|
38
53
|
mask = /netmask\s+(\w{10})/
|
39
54
|
when 'SunOS'
|
40
|
-
output_int = %x{/usr/sbin/ifconfig #{interface}}
|
41
55
|
addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
42
56
|
mac = /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/
|
43
57
|
mask = /netmask\s+(\w{8})/
|
@@ -51,48 +65,24 @@ module Facter::IPAddress
|
|
51
65
|
when 'netmask'
|
52
66
|
regex = mask
|
53
67
|
end
|
68
|
+
|
69
|
+
output_int = get_single_interface_output(interface)
|
54
70
|
|
55
71
|
if interface != "lo" && interface != "lo0"
|
56
72
|
output_int.each { |s|
|
57
|
-
|
73
|
+
if s =~ regex
|
74
|
+
value = $1
|
75
|
+
if label == 'netmask' && Facter.value(:kernel) == "SunOS"
|
76
|
+
value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.')
|
77
|
+
end
|
78
|
+
tmp1.push(value)
|
79
|
+
end
|
58
80
|
}
|
59
81
|
end
|
60
82
|
|
61
83
|
if tmp1
|
62
|
-
value = tmp1
|
84
|
+
value = tmp1.shift
|
63
85
|
end
|
64
86
|
|
65
87
|
end
|
66
|
-
|
67
|
-
def self.get_interface_value_bsd(interface, label)
|
68
|
-
|
69
|
-
tmp1 = []
|
70
|
-
|
71
|
-
int_hash = {}
|
72
|
-
output_int = %x{/sbin/ifconfig #{interface}}
|
73
|
-
addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
74
|
-
mac = /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
|
75
|
-
mask = /netmask\s+(\w{10})/
|
76
|
-
|
77
|
-
case label
|
78
|
-
when 'ipaddress'
|
79
|
-
regex = addr
|
80
|
-
when 'macaddress'
|
81
|
-
regex = mac
|
82
|
-
when 'netmask'
|
83
|
-
regex = mask
|
84
|
-
end
|
85
|
-
|
86
|
-
if interface != "lo" && interface != "lo0"
|
87
|
-
output_int.each { |s|
|
88
|
-
tmp1.push($1) if s =~ regex
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
if tmp1
|
93
|
-
value = tmp1.shift
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
88
|
end
|
98
|
-
|
@@ -22,8 +22,8 @@ module Facter::Manufacturer
|
|
22
22
|
name.each_pair do |key,v|
|
23
23
|
v.each do |value|
|
24
24
|
output.split("Handle").each do |line|
|
25
|
-
|
26
|
-
|
25
|
+
if line =~ /#{key}/ and line =~ /#{value} ([-\w].*)\n*./
|
26
|
+
result = $1
|
27
27
|
Facter.add(value.chomp(':').gsub(' ','')) do
|
28
28
|
confine :kernel => [ :linux, :freebsd, :netbsd, :openbsd ]
|
29
29
|
setcode do
|
@@ -6,14 +6,19 @@
|
|
6
6
|
require 'facter/util/confine'
|
7
7
|
|
8
8
|
require 'timeout'
|
9
|
+
require 'rbconfig'
|
9
10
|
|
10
11
|
class Facter::Util::Resolution
|
11
12
|
attr_accessor :interpreter, :code, :name, :timeout
|
12
13
|
|
13
14
|
def self.have_which
|
14
15
|
if ! defined?(@have_which) or @have_which.nil?
|
15
|
-
|
16
|
-
|
16
|
+
if Config::CONFIG['host_os'] =~ /mswin/
|
17
|
+
@have_which = false
|
18
|
+
else
|
19
|
+
%x{which which 2>/dev/null}
|
20
|
+
@have_which = ($? == 0)
|
21
|
+
end
|
17
22
|
end
|
18
23
|
@have_which
|
19
24
|
end
|
@@ -62,7 +67,7 @@ class Facter::Util::Resolution
|
|
62
67
|
@name = name
|
63
68
|
@confines = []
|
64
69
|
@value = nil
|
65
|
-
@timeout = 0
|
70
|
+
@timeout = 0
|
66
71
|
end
|
67
72
|
|
68
73
|
# Return the number of confines.
|
@@ -116,6 +121,11 @@ class Facter::Util::Resolution
|
|
116
121
|
end
|
117
122
|
rescue Timeout::Error => detail
|
118
123
|
warn "Timed out seeking value for %s" % self.name
|
124
|
+
|
125
|
+
# This call avoids zombies -- basically, create a thread that will
|
126
|
+
# dezombify all of the child processes that we're ignoring because
|
127
|
+
# of the timeout.
|
128
|
+
Thread.new { Process.waitall }
|
119
129
|
return nil
|
120
130
|
end
|
121
131
|
|