facter 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of facter might be problematic. Click here for more details.
- data/CHANGELOG +75 -22
- data/COPYING +289 -623
- data/Rakefile +60 -55
- data/bin/facter +39 -26
- data/conf/osx/PackageInfo.plist +30 -30
- data/conf/osx/createpackage.sh +17 -17
- data/conf/osx/preflight +1 -1
- data/install.rb +226 -226
- data/lib/facter.rb +12 -12
- data/lib/facter/architecture.rb +14 -3
- data/lib/facter/ec2.rb +35 -0
- data/lib/facter/hardwareisa.rb +1 -1
- data/lib/facter/id.rb +1 -1
- data/lib/facter/ipaddress.rb +41 -41
- data/lib/facter/kernel.rb +2 -2
- data/lib/facter/kernelmajversion.rb +5 -0
- data/lib/facter/lsb.rb +5 -5
- data/lib/facter/lsbmajdistrelease.rb +1 -1
- data/lib/facter/macaddress.rb +6 -6
- data/lib/facter/manufacturer.rb +8 -8
- data/lib/facter/memory.rb +5 -4
- data/lib/facter/netmask.rb +4 -4
- data/lib/facter/network.rb +4 -5
- data/lib/facter/operatingsystem.rb +13 -7
- data/lib/facter/operatingsystemrelease.rb +5 -5
- data/lib/facter/selinux.rb +45 -0
- data/lib/facter/timezone.rb +1 -1
- data/lib/facter/uniqueid.rb +2 -2
- data/lib/facter/uptime.rb +3 -3
- data/lib/facter/util/confine.rb +12 -12
- data/lib/facter/util/ip.rb +18 -22
- data/lib/facter/util/macosx.rb +5 -0
- data/lib/facter/util/manufacturer.rb +37 -37
- data/lib/facter/util/plist/generator.rb +181 -179
- data/lib/facter/util/plist/parser.rb +162 -163
- data/lib/facter/util/resolution.rb +2 -2
- data/lib/facter/util/uptime.rb +10 -12
- data/lib/facter/util/values.rb +14 -0
- data/lib/facter/virtual.rb +54 -34
- data/spec/unit/data/darwin_ifconfig_all_with_multiple_interfaces +10 -0
- data/spec/unit/operatingsystem.rb +36 -0
- data/spec/unit/selinux.rb +48 -0
- data/spec/unit/util/confine.rb +70 -5
- data/spec/unit/util/ip.rb +29 -3
- metadata +89 -77
- data/documentation/custom.page +0 -22
- data/documentation/index.page +0 -19
data/lib/facter.rb
CHANGED
@@ -27,14 +27,14 @@ module Facter
|
|
27
27
|
include Comparable
|
28
28
|
include Enumerable
|
29
29
|
|
30
|
-
FACTERVERSION = '1.5.
|
31
|
-
|
30
|
+
FACTERVERSION = '1.5.5'
|
31
|
+
# = Facter
|
32
32
|
# Functions as a hash of 'facts' you might care about about your
|
33
33
|
# system, such as mac address, IP address, Video card, etc.
|
34
34
|
# returns them dynamically
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
# == Synopsis
|
37
|
+
#
|
38
38
|
# Generally, treat <tt>Facter</tt> as a hash:
|
39
39
|
# == Example
|
40
40
|
# require 'facter'
|
@@ -49,7 +49,7 @@ module Facter
|
|
49
49
|
RESET = "[0m"
|
50
50
|
@@debug = 0
|
51
51
|
|
52
|
-
|
52
|
+
# module methods
|
53
53
|
|
54
54
|
def self.collection
|
55
55
|
unless defined?(@collection) and @collection
|
@@ -147,9 +147,9 @@ module Facter
|
|
147
147
|
Facter.reset
|
148
148
|
end
|
149
149
|
|
150
|
-
|
151
|
-
|
152
|
-
|
150
|
+
# Set debugging on or off.
|
151
|
+
def self.debugging(bit)
|
152
|
+
if bit
|
153
153
|
case bit
|
154
154
|
when TrueClass; @@debug = 1
|
155
155
|
when FalseClass; @@debug = 0
|
@@ -168,10 +168,10 @@ module Facter
|
|
168
168
|
else
|
169
169
|
@@debug = 0
|
170
170
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
171
|
+
else
|
172
|
+
@@debug = 0
|
173
|
+
end
|
174
|
+
end
|
175
175
|
|
176
176
|
# Remove them all.
|
177
177
|
def self.reset
|
data/lib/facter/architecture.rb
CHANGED
@@ -4,9 +4,20 @@ Facter.add(:architecture) do
|
|
4
4
|
model = Facter.value(:hardwaremodel)
|
5
5
|
case model
|
6
6
|
# most linuxen use "x86_64"
|
7
|
-
when
|
8
|
-
Facter.value(:operatingsystem)
|
9
|
-
|
7
|
+
when "x86_64"
|
8
|
+
case Facter.value(:operatingsystem)
|
9
|
+
when "Debian", "Gentoo"
|
10
|
+
"amd64"
|
11
|
+
else
|
12
|
+
model
|
13
|
+
end
|
14
|
+
when /(i[3456]86|pentium)/
|
15
|
+
case Facter.value(:operatingsystem)
|
16
|
+
when "Gentoo"
|
17
|
+
"x86"
|
18
|
+
else
|
19
|
+
"i386"
|
20
|
+
end
|
10
21
|
else
|
11
22
|
model
|
12
23
|
end
|
data/lib/facter/ec2.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Changelog:
|
2
|
+
# Original facts - Tim Dysinger
|
3
|
+
# Updated and added can_connect? function - KurtBe
|
4
|
+
|
5
|
+
require 'open-uri'
|
6
|
+
require 'timeout'
|
7
|
+
|
8
|
+
def can_connect?(ip,port,wait_sec=2)
|
9
|
+
Timeout::timeout(wait_sec) {open(ip, port)}
|
10
|
+
return true
|
11
|
+
rescue
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def metadata(id = "")
|
17
|
+
open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read.
|
18
|
+
split("\n").each do |o|
|
19
|
+
key = "#{id}#{o.gsub(/\=.*$/, '/')}"
|
20
|
+
if key[-1..-1] != '/'
|
21
|
+
value = open("http://169.254.169.254/2008-02-01/meta-data/#{key}").read.
|
22
|
+
split("\n")
|
23
|
+
value = value.size>1 ? value : value.first
|
24
|
+
symbol = "ec2_#{key.gsub(/\-|\//, '_')}".to_sym
|
25
|
+
Facter.add(symbol) { setcode { value } }
|
26
|
+
else
|
27
|
+
metadata(key)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if can_connect?("169.254.169.254","80")
|
33
|
+
metadata
|
34
|
+
end
|
35
|
+
|
data/lib/facter/hardwareisa.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
Facter.add(:hardwareisa) do
|
2
2
|
setcode 'uname -p', '/bin/sh'
|
3
|
-
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD}
|
3
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS}
|
4
4
|
end
|
data/lib/facter/id.rb
CHANGED
data/lib/facter/ipaddress.rb
CHANGED
@@ -1,44 +1,3 @@
|
|
1
|
-
Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
|
2
|
-
setcode do
|
3
|
-
require 'resolv'
|
4
|
-
|
5
|
-
begin
|
6
|
-
if hostname = Facter.value(:hostname)
|
7
|
-
ip = Resolv.getaddress(hostname)
|
8
|
-
unless ip == "127.0.0.1"
|
9
|
-
ip
|
10
|
-
end
|
11
|
-
else
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
rescue Resolv::ResolvError
|
15
|
-
nil
|
16
|
-
rescue NoMethodError # i think this is a bug in resolv.rb?
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
Facter.add(:ipaddress, :timeout => 2) do
|
23
|
-
setcode do
|
24
|
-
if hostname = Facter.value(:hostname)
|
25
|
-
# we need Hostname to exist for this to work
|
26
|
-
host = nil
|
27
|
-
if host = Facter::Util::Resolution.exec("host #{hostname}")
|
28
|
-
list = host.chomp.split(/\s/)
|
29
|
-
if defined? list[-1] and
|
30
|
-
list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
|
31
|
-
list[-1]
|
32
|
-
end
|
33
|
-
else
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
else
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
1
|
Facter.add(:ipaddress) do
|
43
2
|
confine :kernel => :linux
|
44
3
|
setcode do
|
@@ -168,3 +127,44 @@ Facter.add(:ipaddress) do
|
|
168
127
|
ip
|
169
128
|
end
|
170
129
|
end
|
130
|
+
|
131
|
+
Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
|
132
|
+
setcode do
|
133
|
+
require 'resolv'
|
134
|
+
|
135
|
+
begin
|
136
|
+
if hostname = Facter.value(:hostname)
|
137
|
+
ip = Resolv.getaddress(hostname)
|
138
|
+
unless ip == "127.0.0.1"
|
139
|
+
ip
|
140
|
+
end
|
141
|
+
else
|
142
|
+
nil
|
143
|
+
end
|
144
|
+
rescue Resolv::ResolvError
|
145
|
+
nil
|
146
|
+
rescue NoMethodError # i think this is a bug in resolv.rb?
|
147
|
+
nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
Facter.add(:ipaddress, :timeout => 2) do
|
153
|
+
setcode do
|
154
|
+
if hostname = Facter.value(:hostname)
|
155
|
+
# we need Hostname to exist for this to work
|
156
|
+
host = nil
|
157
|
+
if host = Facter::Util::Resolution.exec("host #{hostname}")
|
158
|
+
list = host.chomp.split(/\s/)
|
159
|
+
if defined? list[-1] and
|
160
|
+
list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
|
161
|
+
list[-1]
|
162
|
+
end
|
163
|
+
else
|
164
|
+
nil
|
165
|
+
end
|
166
|
+
else
|
167
|
+
nil
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/lib/facter/kernel.rb
CHANGED
data/lib/facter/lsb.rb
CHANGED
@@ -13,11 +13,11 @@
|
|
13
13
|
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
|
14
14
|
##
|
15
15
|
|
16
|
-
{
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
{ "LSBRelease" => %r{^LSB Version:\t(.*)$},
|
17
|
+
"LSBDistId" => %r{^Distributor ID:\t(.*)$},
|
18
|
+
"LSBDistRelease" => %r{^Release:\t(.*)$},
|
19
|
+
"LSBDistDescription" => %r{^Description:\t(.*)$},
|
20
|
+
"LSBDistCodeName" => %r{^Codename:\t(.*)$}
|
21
21
|
}.each do |fact, pattern|
|
22
22
|
Facter.add(fact) do
|
23
23
|
confine :kernel => :linux
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'facter'
|
4
4
|
|
5
5
|
Facter.add("lsbmajdistrelease") do
|
6
|
-
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo}
|
6
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS}
|
7
7
|
setcode do
|
8
8
|
if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
|
9
9
|
result=$1
|
data/lib/facter/macaddress.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Facter.add(:macaddress) do
|
2
|
-
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu}
|
2
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS}
|
3
3
|
setcode do
|
4
4
|
ether = []
|
5
5
|
output = %x{/sbin/ifconfig -a}
|
6
|
-
output.
|
6
|
+
output.each_line do |s|
|
7
7
|
ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
|
8
8
|
end
|
9
9
|
ether[0]
|
@@ -15,7 +15,7 @@ Facter.add(:macaddress) do
|
|
15
15
|
setcode do
|
16
16
|
ether = []
|
17
17
|
output = %x{/sbin/ifconfig}
|
18
|
-
output.
|
18
|
+
output.each_line do |s|
|
19
19
|
if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
|
20
20
|
ether.push($1)
|
21
21
|
end
|
@@ -47,12 +47,12 @@ Facter.add(:macaddress) do
|
|
47
47
|
ether = []
|
48
48
|
ip = nil
|
49
49
|
output = %x{/usr/sbin/ifconfig -a}
|
50
|
-
output.
|
50
|
+
output.each_line do |str|
|
51
51
|
if str =~ /([a-z]+\d+): flags=/
|
52
52
|
devname = $1
|
53
53
|
unless devname =~ /lo0/
|
54
54
|
output2 = %x{/usr/bin/entstat #{devname}}
|
55
|
-
output2.
|
55
|
+
output2.each_line do |str2|
|
56
56
|
if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
|
57
57
|
ether.push($1)
|
58
58
|
end
|
@@ -69,7 +69,7 @@ Facter.add(:macaddress) do
|
|
69
69
|
setcode do
|
70
70
|
ether = []
|
71
71
|
output = %x{ipconfig /all}
|
72
|
-
output.split(/\r\n/).each
|
72
|
+
output.split(/\r\n/).each do |str|
|
73
73
|
if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/
|
74
74
|
ether.push($1.gsub(/-/, ":"))
|
75
75
|
end
|
data/lib/facter/manufacturer.rb
CHANGED
@@ -6,14 +6,14 @@
|
|
6
6
|
require 'facter/util/manufacturer'
|
7
7
|
|
8
8
|
query = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
'[Ss]ystem [Ii]nformation' => [
|
10
|
+
{ 'Manufacturer:' => 'manufacturer' },
|
11
|
+
{ 'Product(?: Name)?:' => 'productname' },
|
12
|
+
{ 'Serial Number:' => 'serialnumber' }
|
13
|
+
],
|
14
|
+
'(Chassis Information|system enclosure or chassis)' => [
|
15
|
+
{ '(?:Chassis )?Type:' => 'type' }
|
16
|
+
]
|
17
17
|
}
|
18
18
|
|
19
19
|
Facter::Manufacturer.dmi_find_system_info(query)
|
data/lib/facter/memory.rb
CHANGED
@@ -7,10 +7,11 @@
|
|
7
7
|
#
|
8
8
|
require 'facter/util/memory'
|
9
9
|
|
10
|
-
{:MemorySize => "MemTotal",
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
{ :MemorySize => "MemTotal",
|
11
|
+
:MemoryFree => "MemFree",
|
12
|
+
:SwapSize => "SwapTotal",
|
13
|
+
:SwapFree => "SwapFree"
|
14
|
+
}.each do |fact, name|
|
14
15
|
Facter.add(fact) do
|
15
16
|
confine :kernel => :linux
|
16
17
|
setcode do
|
data/lib/facter/netmask.rb
CHANGED
@@ -9,9 +9,9 @@
|
|
9
9
|
require 'facter/util/netmask'
|
10
10
|
|
11
11
|
Facter.add("netmask") do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
confine :kernel => [ :sunos, :linux ]
|
13
|
+
setcode do
|
14
|
+
Facter::NetMask.get_netmask
|
15
|
+
end
|
16
16
|
end
|
17
17
|
|
data/lib/facter/network.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'facter/util/ip'
|
2
2
|
|
3
3
|
Facter::Util::IP.get_interfaces.each do |interface|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Facter::Util::IP.get_network_value(interface)
|
8
|
-
end
|
4
|
+
Facter.add("network_" + Facter::Util::IP.alphafy(interface)) do
|
5
|
+
setcode do
|
6
|
+
Facter::Util::IP.get_network_value(interface)
|
9
7
|
end
|
8
|
+
end
|
10
9
|
end
|
@@ -20,12 +20,16 @@ Facter.add(:operatingsystem) do
|
|
20
20
|
"Mandriva"
|
21
21
|
elsif FileTest.exists?("/etc/mandrake-release")
|
22
22
|
"Mandrake"
|
23
|
-
|
24
|
-
|
23
|
+
elsif FileTest.exists?("/etc/arch-release")
|
24
|
+
"Archlinux"
|
25
25
|
elsif FileTest.exists?("/etc/enterprise-release")
|
26
|
-
"
|
27
|
-
|
28
|
-
|
26
|
+
if FileTest.exists?("/etc/ovs-release")
|
27
|
+
"OVS"
|
28
|
+
else
|
29
|
+
"OEL"
|
30
|
+
end
|
31
|
+
elsif FileTest.exists?("/etc/arch-release")
|
32
|
+
"Arch"
|
29
33
|
elsif FileTest.exists?("/etc/redhat-release")
|
30
34
|
txt = File.read("/etc/redhat-release")
|
31
35
|
if txt =~ /centos/i
|
@@ -37,8 +41,10 @@ Facter.add(:operatingsystem) do
|
|
37
41
|
txt = File.read("/etc/SuSE-release")
|
38
42
|
if txt =~ /^SUSE LINUX Enterprise Server/i
|
39
43
|
"SLES"
|
40
|
-
|
41
|
-
|
44
|
+
elsif txt =~ /^SUSE LINUX Enterprise Desktop/i
|
45
|
+
"SLED"
|
46
|
+
elsif txt =~ /^openSUSE/i
|
47
|
+
"OpenSuSE"
|
42
48
|
else
|
43
49
|
"SuSE"
|
44
50
|
end
|
@@ -53,8 +53,8 @@ end
|
|
53
53
|
Facter.add(:operatingsystemrelease) do
|
54
54
|
confine :operatingsystem => %w{CentOS}
|
55
55
|
setcode do
|
56
|
-
centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/
|
57
|
-
if centos_release =~
|
56
|
+
centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/ \\((Branch|Final)\\)//' /etc/redhat-release")
|
57
|
+
if centos_release =~ /^5/
|
58
58
|
release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2')
|
59
59
|
else
|
60
60
|
release = centos_release
|
@@ -80,15 +80,15 @@ Facter.add(:operatingsystemrelease) do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
Facter.add(:operatingsystemrelease) do
|
83
|
-
confine :operatingsystem => %w{SLES OpenSuSE}
|
83
|
+
confine :operatingsystem => %w{SLES SLED OpenSuSE}
|
84
84
|
setcode do
|
85
85
|
releasefile = Facter::Util::Resolution.exec('cat /etc/SuSE-release')
|
86
86
|
if releasefile =~ /^VERSION\s*=\s*(\d+)/
|
87
87
|
releasemajor = $1
|
88
88
|
if releasefile =~ /^PATCHLEVEL\s*=\s*(\d+)/
|
89
89
|
releaseminor = $1
|
90
|
-
|
91
|
-
|
90
|
+
elsif releasefile =~ /^VERSION\s=.*.(\d+)/
|
91
|
+
releaseminor = $1
|
92
92
|
else
|
93
93
|
releaseminor = "0"
|
94
94
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Fact for SElinux
|
2
|
+
# Written by immerda admin team (admin(at)immerda.ch)
|
3
|
+
|
4
|
+
Facter.add("selinux") do
|
5
|
+
confine :kernel => :linux
|
6
|
+
|
7
|
+
setcode do
|
8
|
+
result = "false"
|
9
|
+
if FileTest.exists?("/selinux/enforce")
|
10
|
+
if FileTest.exists?("/proc/self/attr/current")
|
11
|
+
if (File.read("/proc/self/attr/current") != "kernel\0")
|
12
|
+
result = "true"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Facter.add("selinux_enforced") do
|
21
|
+
confine :selinux => :true
|
22
|
+
|
23
|
+
setcode do
|
24
|
+
result = "false"
|
25
|
+
if FileTest.exists?("/selinux/enforce") and File.read("/selinux/enforce") =~ /1/i
|
26
|
+
result = "true"
|
27
|
+
end
|
28
|
+
result
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Facter.add("selinux_policyversion") do
|
33
|
+
confine :selinux => :true
|
34
|
+
setcode do
|
35
|
+
File.read("/selinux/policyvers")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Facter.add("selinux_mode") do
|
40
|
+
confine :selinux => :true
|
41
|
+
setcode do
|
42
|
+
%x{/usr/sbin/sestatus | /bin/grep "Policy from config file:" | awk '{print $5}'}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|