facter 1.5.7 → 1.5.8
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 +105 -28
- data/Rakefile +23 -20
- data/bin/facter +3 -3
- data/conf/osx/createpackage.sh +12 -1
- data/conf/osx/preflight +4 -0
- data/install.rb +7 -14
- data/lib/facter.rb +14 -2
- data/lib/facter/architecture.rb +10 -2
- data/lib/facter/domain.rb +0 -3
- data/lib/facter/ipaddress.rb +18 -21
- data/lib/facter/kernel.rb +4 -2
- data/lib/facter/macaddress.rb +21 -8
- data/lib/facter/memory.rb +47 -6
- data/lib/facter/operatingsystem.rb +4 -0
- data/lib/facter/operatingsystemrelease.rb +15 -3
- data/lib/facter/processor.rb +16 -0
- data/lib/facter/uptime.rb +17 -14
- data/lib/facter/uptime_days.rb +7 -0
- data/lib/facter/uptime_hours.rb +7 -0
- data/lib/facter/uptime_seconds.rb +10 -0
- data/lib/facter/util/ip.rb +17 -5
- data/lib/facter/util/manufacturer.rb +13 -7
- data/lib/facter/util/resolution.rb +34 -11
- data/lib/facter/util/uptime.rb +45 -23
- data/lib/facter/util/virtual.rb +23 -1
- data/lib/facter/util/vlans.rb +24 -0
- data/lib/facter/virtual.rb +11 -3
- data/lib/facter/vlans.rb +8 -0
- data/spec/fixtures/uptime/sysctl_kern_boottime +0 -0
- data/spec/fixtures/uptime/ubuntu_proc_uptime +1 -0
- data/spec/fixtures/uptime/who_b_boottime +1 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/data/freebsd_dmidecode +42 -0
- data/spec/unit/data/hpux_ifconfig +3 -0
- data/spec/unit/data/hpux_ifconfig_single_interface +3 -0
- data/spec/unit/data/hpux_netscan +4 -0
- data/spec/unit/data/hpux_netstat_all_interfaces +6 -0
- data/spec/unit/data/linux_dmidecode_with_spaces +60 -0
- data/spec/unit/data/linux_vlan_config +6 -0
- data/spec/unit/data/opensolaris_smbios +33 -0
- data/spec/unit/facter.rb +73 -0
- data/spec/unit/operatingsystemrelease.rb +39 -0
- data/spec/unit/uptime.rb +112 -0
- data/spec/unit/util/ip.rb +59 -2
- data/spec/unit/util/manufacturer.rb +121 -0
- data/spec/unit/util/resolution.rb +44 -11
- data/spec/unit/util/uptime.rb +53 -0
- data/spec/unit/util/virtual.rb +24 -1
- data/spec/unit/util/vlans.rb +14 -0
- data/spec/unit/virtual.rb +20 -0
- metadata +115 -91
- data/ChangeLog +0 -1727
data/lib/facter/architecture.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Facter.add(:architecture) do
|
2
|
-
confine :kernel => :linux
|
2
|
+
confine :kernel => [:linux, :"gnu/kfreebsd"]
|
3
3
|
setcode do
|
4
4
|
model = Facter.value(:hardwaremodel)
|
5
5
|
case model
|
6
6
|
# most linuxen use "x86_64"
|
7
7
|
when "x86_64"
|
8
8
|
case Facter.value(:operatingsystem)
|
9
|
-
when "Debian", "Gentoo"
|
9
|
+
when "Debian", "Gentoo", "GNU/kFreeBSD"
|
10
10
|
"amd64"
|
11
11
|
else
|
12
12
|
model
|
@@ -23,3 +23,11 @@ Facter.add(:architecture) do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
Facter.add(:architecture) do
|
28
|
+
confine :kernel => :openbsd
|
29
|
+
setcode do
|
30
|
+
architecture = Facter.value(:hardwaremodel)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/facter/domain.rb
CHANGED
@@ -9,9 +9,6 @@ Facter.add(:domain) do
|
|
9
9
|
domain = Facter::Util::Resolution.exec('dnsdomainname')
|
10
10
|
next domain if domain =~ /.+\..+/
|
11
11
|
|
12
|
-
domain = Facter::Util::Resolution.exec('domainname')
|
13
|
-
next domain if domain =~ /.+\..+/
|
14
|
-
|
15
12
|
if FileTest.exists?("/etc/resolv.conf")
|
16
13
|
domain = nil
|
17
14
|
search = nil
|
data/lib/facter/ipaddress.rb
CHANGED
@@ -7,7 +7,7 @@ Facter.add(:ipaddress) do
|
|
7
7
|
output.split(/^\S/).each { |str|
|
8
8
|
if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
9
9
|
tmp = $1
|
10
|
-
unless tmp =~
|
10
|
+
unless tmp =~ /^127\./
|
11
11
|
ip = tmp
|
12
12
|
break
|
13
13
|
end
|
@@ -27,7 +27,7 @@ Facter.add(:ipaddress) do
|
|
27
27
|
output.split(/^\S/).each { |str|
|
28
28
|
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
29
29
|
tmp = $1
|
30
|
-
unless tmp =~
|
30
|
+
unless tmp =~ /^127\./
|
31
31
|
ip = tmp
|
32
32
|
break
|
33
33
|
end
|
@@ -47,7 +47,7 @@ Facter.add(:ipaddress) do
|
|
47
47
|
output.split(/^\S/).each { |str|
|
48
48
|
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
49
49
|
tmp = $1
|
50
|
-
unless tmp =~
|
50
|
+
unless tmp =~ /^127\./
|
51
51
|
ip = tmp
|
52
52
|
break
|
53
53
|
end
|
@@ -78,7 +78,7 @@ Facter.add(:ipaddress) do
|
|
78
78
|
output.split(/^\S/).each { |str|
|
79
79
|
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
80
80
|
tmp = $1
|
81
|
-
unless tmp =~
|
81
|
+
unless tmp =~ /^127\./
|
82
82
|
ip = tmp
|
83
83
|
break
|
84
84
|
end
|
@@ -98,7 +98,7 @@ Facter.add(:ipaddress) do
|
|
98
98
|
output.split(/^\S/).each { |str|
|
99
99
|
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
100
100
|
tmp = $1
|
101
|
-
unless tmp =~
|
101
|
+
unless tmp =~ /^127\./
|
102
102
|
ip = tmp
|
103
103
|
break
|
104
104
|
end
|
@@ -112,29 +112,26 @@ end
|
|
112
112
|
Facter.add(:ipaddress) do
|
113
113
|
confine :kernel => %w{windows}
|
114
114
|
setcode do
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
output.split(/^\S/).each { |str|
|
119
|
-
if str =~ /IP Address.*: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
120
|
-
tmp = $1
|
121
|
-
unless tmp =~ /127\./
|
122
|
-
ip = tmp
|
123
|
-
break
|
124
|
-
end
|
125
|
-
end
|
126
|
-
}
|
127
|
-
ip
|
115
|
+
require 'socket'
|
116
|
+
IPSocket.getaddress(Socket.gethostname)
|
128
117
|
end
|
129
118
|
end
|
130
119
|
|
131
120
|
Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
|
132
121
|
setcode do
|
133
|
-
|
134
|
-
|
122
|
+
if Facter.value(:kernel) == 'windows'
|
123
|
+
require 'win32/resolv'
|
124
|
+
else
|
125
|
+
require 'resolv'
|
126
|
+
end
|
127
|
+
|
135
128
|
begin
|
136
129
|
if hostname = Facter.value(:hostname)
|
137
|
-
|
130
|
+
if Facter.value(:kernel) == 'windows'
|
131
|
+
ip = Win32::Resolv.get_resolv_info.last[0]
|
132
|
+
else
|
133
|
+
ip = Resolv.getaddress(hostname)
|
134
|
+
end
|
138
135
|
unless ip == "127.0.0.1"
|
139
136
|
ip
|
140
137
|
end
|
data/lib/facter/kernel.rb
CHANGED
@@ -2,8 +2,10 @@ Facter.add(:kernel) do
|
|
2
2
|
setcode do
|
3
3
|
require 'rbconfig'
|
4
4
|
case Config::CONFIG['host_os']
|
5
|
-
when /mswin/i
|
6
|
-
|
5
|
+
when /mswin|win32|dos|cygwin|mingw/i
|
6
|
+
'windows'
|
7
|
+
else
|
8
|
+
Facter::Util::Resolution.exec("uname -s")
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
data/lib/facter/macaddress.rb
CHANGED
@@ -67,13 +67,26 @@ end
|
|
67
67
|
Facter.add(:macaddress) do
|
68
68
|
confine :kernel => %w(windows)
|
69
69
|
setcode do
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
70
|
+
require 'win32ole'
|
71
|
+
require 'socket'
|
72
|
+
|
73
|
+
ether = nil
|
74
|
+
host = Socket.gethostname
|
75
|
+
connect_string = "winmgmts://#{host}/root/cimv2"
|
76
|
+
|
77
|
+
wmi = WIN32OLE.connect(connect_string)
|
78
|
+
|
79
|
+
query = %Q{
|
80
|
+
select *
|
81
|
+
from Win32_NetworkAdapterConfiguration
|
82
|
+
where IPEnabled = True
|
83
|
+
}
|
84
|
+
|
85
|
+
wmi.ExecQuery(query).each{ |nic|
|
86
|
+
ether = nic.MacAddress
|
87
|
+
break
|
88
|
+
}
|
89
|
+
|
90
|
+
ether
|
78
91
|
end
|
79
92
|
end
|
data/lib/facter/memory.rb
CHANGED
@@ -20,27 +20,68 @@ require 'facter/util/memory'
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
if Facter.value(:kernel) == "AIX"
|
23
|
+
if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root"
|
24
24
|
swap = Facter::Util::Resolution.exec('swap -l')
|
25
25
|
swapfree, swaptotal = 0, 0
|
26
26
|
swap.each do |dev|
|
27
|
-
|
27
|
+
if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/
|
28
|
+
swaptotal += $1.to_i
|
29
|
+
swapfree += $2.to_i
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Facter.add("SwapSize") do
|
34
|
+
confine :kernel => :aix
|
35
|
+
setcode do
|
36
|
+
Facter::Memory.scale_number(swaptotal.to_f,"MB")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Facter.add("SwapFree") do
|
41
|
+
confine :kernel => :aix
|
42
|
+
setcode do
|
43
|
+
Facter::Memory.scale_number(swapfree.to_f,"MB")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
if Facter.value(:kernel) == "OpenBSD"
|
49
|
+
swap = Facter::Util::Resolution.exec('swapctl -l | sed 1d')
|
50
|
+
swapfree, swaptotal = 0, 0
|
51
|
+
swap.each do |dev|
|
52
|
+
if dev =~ /^\S+\s+(\S+)\s+\S+\s+(\S+)\s+.*$/
|
28
53
|
swaptotal += $1.to_i
|
29
54
|
swapfree += $2.to_i
|
30
55
|
end
|
31
56
|
end
|
32
57
|
|
33
58
|
Facter.add("SwapSize") do
|
34
|
-
confine :kernel => :
|
59
|
+
confine :kernel => :openbsd
|
35
60
|
setcode do
|
36
|
-
Facter::Memory.scale_number(swaptotal.to_f,"
|
61
|
+
Facter::Memory.scale_number(swaptotal.to_f,"kB")
|
37
62
|
end
|
38
63
|
end
|
39
64
|
|
40
65
|
Facter.add("SwapFree") do
|
41
|
-
confine :kernel => :
|
66
|
+
confine :kernel => :openbsd
|
42
67
|
setcode do
|
43
|
-
Facter::Memory.scale_number(swapfree.to_f,"
|
68
|
+
Facter::Memory.scale_number(swapfree.to_f,"kB")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Facter.add("MemoryFree") do
|
73
|
+
confine :kernel => :openbsd
|
74
|
+
memfree = Facter::Util::Resolution.exec("vmstat | tail -n 1 | awk '{ print $5 }'")
|
75
|
+
setcode do
|
76
|
+
Facter::Memory.scale_number(memfree.to_f,"kB")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
Facter.add("MemoryTotal") do
|
81
|
+
confine :kernel => :openbsd
|
82
|
+
memtotal = Facter::Util::Resolution.exec("sysctl hw.physmem | cut -d'=' -f2")
|
83
|
+
setcode do
|
84
|
+
Facter::Memory.scale_number(memtotal.to_f,"")
|
44
85
|
end
|
45
86
|
end
|
46
87
|
end
|
@@ -20,6 +20,8 @@ Facter.add(:operatingsystem) do
|
|
20
20
|
"Mandriva"
|
21
21
|
elsif FileTest.exists?("/etc/mandrake-release")
|
22
22
|
"Mandrake"
|
23
|
+
elsif FileTest.exists?("/etc/meego-release")
|
24
|
+
"MeeGo"
|
23
25
|
elsif FileTest.exists?("/etc/arch-release")
|
24
26
|
"Archlinux"
|
25
27
|
elsif FileTest.exists?("/etc/enterprise-release")
|
@@ -48,6 +50,8 @@ Facter.add(:operatingsystem) do
|
|
48
50
|
else
|
49
51
|
"SuSE"
|
50
52
|
end
|
53
|
+
elsif FileTest.exists?("/etc/slackware-version")
|
54
|
+
"Slackware"
|
51
55
|
end
|
52
56
|
end
|
53
57
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
Facter.add(:operatingsystemrelease) do
|
2
|
-
confine :operatingsystem => %w{CentOS Fedora oel ovs RedHat}
|
2
|
+
confine :operatingsystem => %w{CentOS Fedora oel ovs RedHat MeeGo}
|
3
3
|
setcode do
|
4
4
|
case Facter.value(:operatingsystem)
|
5
5
|
when "CentOS", "RedHat"
|
6
6
|
releasefile = "/etc/redhat-release"
|
7
7
|
when "Fedora"
|
8
8
|
releasefile = "/etc/fedora-release"
|
9
|
-
when "
|
9
|
+
when "MeeGo"
|
10
|
+
releasefile = "/etc/meego-release"
|
11
|
+
when "OEL", "oel"
|
10
12
|
releasefile = "/etc/enterprise-release"
|
11
|
-
when "ovs"
|
13
|
+
when "OVS", "ovs"
|
12
14
|
releasefile = "/etc/ovs-release"
|
13
15
|
end
|
14
16
|
File::open(releasefile, "r") do |f|
|
@@ -59,6 +61,16 @@ Facter.add(:operatingsystemrelease) do
|
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
64
|
+
Facter.add(:operatingsystemrelease) do
|
65
|
+
confine :operatingsystem => %w{Slackware}
|
66
|
+
setcode do
|
67
|
+
release = Facter::Util::Resolution.exec('cat /etc/slackware-version')
|
68
|
+
if release =~ /Slackware ([0-9.]+)/
|
69
|
+
$1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
62
74
|
Facter.add(:operatingsystemrelease) do
|
63
75
|
setcode do Facter[:kernelrelease].value end
|
64
76
|
end
|
data/lib/facter/processor.rb
CHANGED
@@ -72,3 +72,19 @@ if Facter.value(:kernel) == "AIX"
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
76
|
+
if Facter.value(:kernel) == "OpenBSD"
|
77
|
+
Facter.add("Processor") do
|
78
|
+
confine :kernel => :openbsd
|
79
|
+
setcode do
|
80
|
+
Facter::Util::Resolution.exec("uname -p")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
Facter.add("ProcessorCount") do
|
85
|
+
confine :kernel => :openbsd
|
86
|
+
setcode do
|
87
|
+
Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d'=' -f2")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/facter/uptime.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
require 'facter/util/uptime'
|
2
2
|
|
3
3
|
Facter.add(:uptime) do
|
4
|
-
|
5
|
-
|
6
|
-
Facter::Util::Uptime.get_uptime_simple
|
7
|
-
end
|
8
|
-
end
|
4
|
+
setcode do
|
5
|
+
seconds = Facter.fact(:uptime_seconds).value
|
9
6
|
|
10
|
-
|
11
|
-
|
7
|
+
unless seconds
|
8
|
+
"unknown"
|
9
|
+
else
|
10
|
+
days = seconds / (60 * 60 * 24)
|
11
|
+
hours = seconds / (60 * 60) % 24
|
12
|
+
minutes = seconds / 60 % 60
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
case days
|
15
|
+
when 0 then "#{hours}:#{"%02d" % minutes} hours"
|
16
|
+
when 1 then '1 day'
|
17
|
+
else "#{days} days"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
20
22
|
end
|
23
|
+
|
data/lib/facter/util/ip.rb
CHANGED
@@ -16,19 +16,24 @@ module Facter::Util::IP
|
|
16
16
|
:netmask => /netmask\s+0x(\w{8})/
|
17
17
|
},
|
18
18
|
:sunos => {
|
19
|
-
:ipaddress
|
19
|
+
:ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
|
20
20
|
:macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/,
|
21
21
|
:netmask => /netmask\s+(\w{8})/
|
22
|
+
},
|
23
|
+
:"hp-ux" => {
|
24
|
+
:ipaddress => /\s+inet (\S+)\s.*/,
|
25
|
+
:macaddress => /(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/,
|
26
|
+
:netmask => /.*\s+netmask (\S+)\s.*/
|
22
27
|
}
|
23
28
|
}
|
24
29
|
|
25
30
|
# Convert an interface name into purely alpha characters.
|
26
31
|
def self.alphafy(interface)
|
27
|
-
interface.gsub(/[
|
32
|
+
interface.gsub(/[-:.]/, '_')
|
28
33
|
end
|
29
34
|
|
30
35
|
def self.convert_from_hex?(kernel)
|
31
|
-
kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin]
|
36
|
+
kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux"]
|
32
37
|
kernels_to_convert.include?(kernel)
|
33
38
|
end
|
34
39
|
|
@@ -51,7 +56,7 @@ module Facter::Util::IP
|
|
51
56
|
# at the end of interfaces. So, we have to trim those trailing
|
52
57
|
# characters. I tried making the regex better but supporting all
|
53
58
|
# platforms with a single regex is probably a bit too much.
|
54
|
-
output.scan(
|
59
|
+
output.scan(/^[-\w]+[.:]?\d+[.:]?\d*[.:]?\w*/).collect { |i| i.sub(/:$/, '') }.uniq
|
55
60
|
end
|
56
61
|
|
57
62
|
def self.get_all_interface_output
|
@@ -60,6 +65,8 @@ module Facter::Util::IP
|
|
60
65
|
output = %x{/sbin/ifconfig -a}
|
61
66
|
when 'SunOS'
|
62
67
|
output = %x{/usr/sbin/ifconfig -a}
|
68
|
+
when 'HP-UX'
|
69
|
+
output = %x{/bin/netstat -i}
|
63
70
|
end
|
64
71
|
output
|
65
72
|
end
|
@@ -71,6 +78,12 @@ module Facter::Util::IP
|
|
71
78
|
output = %x{/sbin/ifconfig #{interface}}
|
72
79
|
when 'SunOS'
|
73
80
|
output = %x{/usr/sbin/ifconfig #{interface}}
|
81
|
+
when 'HP-UX'
|
82
|
+
mac = ""
|
83
|
+
ifc = %x{/usr/sbin/ifconfig #{interface}}
|
84
|
+
%x{/usr/sbin/lanscan}.scan(/(\dx\S+).*UP\s+(\w+\d+)/).each {|i| mac = i[0] if i.include?(interface) }
|
85
|
+
mac = mac.sub(/0x(\S+)/,'\1').scan(/../).join(":")
|
86
|
+
output = ifc + "\n" + mac
|
74
87
|
end
|
75
88
|
output
|
76
89
|
end
|
@@ -101,7 +114,6 @@ module Facter::Util::IP
|
|
101
114
|
device
|
102
115
|
end
|
103
116
|
|
104
|
-
|
105
117
|
def self.get_interface_value(interface, label)
|
106
118
|
tmp1 = []
|
107
119
|
|