facter 1.5.8 → 1.5.9
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 +94 -0
- data/INSTALL +1 -1
- data/README +1 -1
- data/README.rst +3 -3
- data/Rakefile +9 -6
- data/bin/facter +18 -123
- data/conf/redhat/facter.spec +21 -3
- data/conf/solaris/pkginfo +2 -2
- data/install.rb +18 -10
- data/lib/facter.rb +27 -1
- data/lib/facter/application.rb +123 -0
- data/lib/facter/arp.rb +28 -0
- data/lib/facter/ec2.rb +32 -11
- data/lib/facter/hardwareisa.rb +1 -1
- data/lib/facter/id.rb +2 -9
- data/lib/facter/interfaces.rb +1 -1
- data/lib/facter/ipaddress.rb +2 -33
- data/lib/facter/ipaddress6.rb +68 -0
- data/lib/facter/lsb.rb +5 -5
- data/lib/facter/lsbmajdistrelease.rb +1 -1
- data/lib/facter/macaddress.rb +4 -14
- data/lib/facter/manufacturer.rb +9 -0
- data/lib/facter/memory.rb +110 -6
- data/lib/facter/netmask.rb +1 -1
- data/lib/facter/operatingsystem.rb +17 -2
- data/lib/facter/operatingsystemrelease.rb +34 -0
- data/lib/facter/processor.rb +8 -5
- data/lib/facter/selinux.rb +37 -4
- data/lib/facter/uniqueid.rb +1 -1
- data/lib/facter/util/#uptime.rb# +64 -0
- data/lib/facter/util/ip.rb +23 -15
- data/lib/facter/util/loader.rb +2 -2
- data/lib/facter/util/macaddress.rb +28 -0
- data/lib/facter/util/manufacturer.rb +39 -2
- data/lib/facter/util/memory.rb +43 -0
- data/lib/facter/util/netmask.rb +1 -1
- data/lib/facter/util/resolution.rb +7 -0
- data/lib/facter/util/uptime.rb +11 -1
- data/lib/facter/util/virtual.rb +13 -2
- data/lib/facter/util/vlans.rb +2 -2
- data/lib/facter/util/xendomains.rb +10 -0
- data/lib/facter/virtual.rb +45 -13
- data/lib/facter/xendomains.rb +10 -0
- data/spec/fixtures/ifconfig/bsd_ifconfig_all_with_multiple_interfaces +18 -0
- data/spec/fixtures/ifconfig/centos_5_5 +17 -0
- data/spec/fixtures/ifconfig/centos_5_5_eth0 +8 -0
- data/spec/fixtures/ifconfig/darwin_10_3_0 +26 -0
- data/spec/fixtures/ifconfig/darwin_10_3_0_en0 +6 -0
- data/spec/fixtures/ifconfig/darwin_10_6_4 +28 -0
- data/spec/fixtures/ifconfig/darwin_10_6_4_en1 +6 -0
- data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack +8 -0
- data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack_en1 +7 -0
- data/spec/fixtures/ifconfig/darwin_9_8_0 +26 -0
- data/spec/fixtures/ifconfig/darwin_9_8_0_en0 +6 -0
- data/spec/fixtures/ifconfig/darwin_ifconfig_all_with_multiple_interfaces +23 -0
- data/spec/fixtures/ifconfig/fedora_10 +36 -0
- data/spec/fixtures/ifconfig/fedora_10_eth0 +9 -0
- data/spec/fixtures/ifconfig/fedora_13 +18 -0
- data/spec/fixtures/ifconfig/fedora_13_eth0 +9 -0
- data/spec/fixtures/ifconfig/fedora_8 +38 -0
- data/spec/fixtures/ifconfig/fedora_8_eth0 +9 -0
- data/spec/fixtures/ifconfig/freebsd_6_0 +12 -0
- data/spec/fixtures/ifconfig/linux_ifconfig_all_with_multiple_interfaces +19 -0
- data/spec/fixtures/ifconfig/open_solaris_10 +12 -0
- data/spec/fixtures/ifconfig/open_solaris_b132 +20 -0
- data/spec/fixtures/ifconfig/sunos_ifconfig_all_with_multiple_interfaces +10 -0
- data/spec/fixtures/ifconfig/ubuntu_7_04 +38 -0
- data/spec/fixtures/ifconfig/ubuntu_7_04_eth0 +9 -0
- data/spec/fixtures/netstat/centos_5_5 +5 -0
- data/spec/fixtures/netstat/darwin_10_3_0 +35 -0
- data/spec/fixtures/netstat/darwin_10_6_4 +29 -0
- data/spec/fixtures/netstat/darwin_10_6_6_dualstack +34 -0
- data/spec/fixtures/netstat/darwin_9_8_0 +28 -0
- data/spec/fixtures/netstat/fedora_10 +7 -0
- data/spec/fixtures/netstat/open_solaris_10 +16 -0
- data/spec/fixtures/netstat/open_solaris_b132 +17 -0
- data/spec/fixtures/netstat/ubuntu_7_04 +7 -0
- data/spec/fixtures/uptime/kstat_boot_time +1 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_1/guest +37 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_1/host +36 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_3/guest +39 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_3/host +39 -0
- data/spec/integration/{facter.rb → facter_spec.rb} +1 -1
- data/spec/spec_helper.rb +8 -3
- data/spec/unit/data/debian_kfreebsd_ifconfig +40 -0
- data/spec/unit/data/hpux_netstat_all_interfaces +3 -6
- data/spec/unit/data/selinux_sestatus +6 -0
- data/spec/unit/data/xendomains +4 -0
- data/spec/unit/{facter.rb → facter_spec.rb} +28 -1
- data/spec/unit/id_spec.rb +27 -0
- data/spec/unit/{interfaces.rb → interfaces_spec.rb} +1 -1
- data/spec/unit/ipaddress6_spec.rb +36 -0
- data/spec/unit/memory_spec.rb +45 -0
- data/spec/unit/{operatingsystem.rb → operatingsystem_spec.rb} +22 -8
- data/spec/unit/operatingsystemrelease_spec.rb +49 -0
- data/spec/unit/selinux_spec.rb +89 -0
- data/spec/unit/{uptime.rb → uptime_spec.rb} +4 -4
- data/spec/unit/util/{collection.rb → collection_spec.rb} +1 -1
- data/spec/unit/util/{confine.rb → confine_spec.rb} +1 -1
- data/spec/unit/util/{fact.rb → fact_spec.rb} +1 -1
- data/spec/unit/util/{ip.rb → ip_spec.rb} +47 -12
- data/spec/unit/util/{loader.rb → loader_spec.rb} +51 -1
- data/spec/unit/util/macaddress_spec.rb +68 -0
- data/spec/unit/util/{macosx.rb → macosx_spec.rb} +1 -1
- data/spec/unit/util/{manufacturer.rb → manufacturer_spec.rb} +15 -4
- data/spec/unit/util/{resolution.rb → resolution_spec.rb} +1 -1
- data/spec/unit/util/uptime_spec.rb +73 -0
- data/spec/unit/util/{virtual.rb → virtual_spec.rb} +37 -3
- data/spec/unit/util/{vlans.rb → vlans_spec.rb} +1 -1
- data/spec/unit/util/xendomains_spec.rb +23 -0
- data/spec/unit/virtual_spec.rb +196 -0
- metadata +149 -98
- data/spec/Rakefile +0 -18
- data/spec/unit/data/hpux_ifconfig +0 -3
- data/spec/unit/data/hpux_netscan +0 -4
- data/spec/unit/operatingsystemrelease.rb +0 -39
- data/spec/unit/selinux.rb +0 -48
- data/spec/unit/util/uptime.rb +0 -53
- data/spec/unit/virtual.rb +0 -71
data/lib/facter/netmask.rb
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
require 'facter/util/netmask'
|
10
10
|
|
11
11
|
Facter.add("netmask") do
|
12
|
-
confine :kernel => [ :sunos, :linux, :freebsd, :openbsd, :netbsd, :darwin ]
|
12
|
+
confine :kernel => [ :sunos, :linux, :freebsd, :openbsd, :netbsd, :darwin, :"gnu/kfreebsd" ]
|
13
13
|
setcode do
|
14
14
|
Facter::NetMask.get_netmask
|
15
15
|
end
|
@@ -32,10 +32,14 @@ Facter.add(:operatingsystem) do
|
|
32
32
|
end
|
33
33
|
elsif FileTest.exists?("/etc/arch-release")
|
34
34
|
"Arch"
|
35
|
+
elsif FileTest.exists?("/etc/vmware-release")
|
36
|
+
"VMWareESX"
|
35
37
|
elsif FileTest.exists?("/etc/redhat-release")
|
36
38
|
txt = File.read("/etc/redhat-release")
|
37
39
|
if txt =~ /centos/i
|
38
40
|
"CentOS"
|
41
|
+
elsif txt =~ /scientific/i
|
42
|
+
"Scientific"
|
39
43
|
else
|
40
44
|
"RedHat"
|
41
45
|
end
|
@@ -50,12 +54,23 @@ Facter.add(:operatingsystem) do
|
|
50
54
|
else
|
51
55
|
"SuSE"
|
52
56
|
end
|
53
|
-
|
54
|
-
|
57
|
+
elsif FileTest.exists?("/etc/bluewhite64-version")
|
58
|
+
"Bluewhite64"
|
59
|
+
elsif FileTest.exists?("/etc/slamd64-version")
|
60
|
+
"Slamd64"
|
61
|
+
elsif FileTest.exists?("/etc/slackware-version")
|
62
|
+
"Slackware"
|
55
63
|
end
|
56
64
|
end
|
57
65
|
end
|
58
66
|
|
67
|
+
Facter.add(:operatingsystem) do
|
68
|
+
confine :kernel => "VMkernel"
|
69
|
+
setcode do
|
70
|
+
"ESXi"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
59
74
|
Facter.add(:operatingsystem) do
|
60
75
|
# Default to just returning the kernel as the operating system
|
61
76
|
setcode do Facter[:kernel].value end
|
@@ -71,6 +71,40 @@ Facter.add(:operatingsystemrelease) do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
Facter.add(:operatingsystemrelease) do
|
75
|
+
confine :operatingsystem => %w{Bluewhite64}
|
76
|
+
setcode do
|
77
|
+
releasefile = Facter::Util::Resolution.exec('cat /etc/bluewhite64-version')
|
78
|
+
if releasefile =~ /^\s*\w+\s+(\d+)\.(\d+)/
|
79
|
+
$1 + "." + $2
|
80
|
+
else
|
81
|
+
"unknown"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
Facter.add(:operatingsystemrelease) do
|
87
|
+
confine :operatingsystem => %w{VMwareESX}
|
88
|
+
setcode do
|
89
|
+
release = Facter::Util::Resolution.exec('vmware -v')
|
90
|
+
if release =~ /VMware ESX .*?(\d.*)/
|
91
|
+
$1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
Facter.add(:operatingsystemrelease) do
|
97
|
+
confine :operatingsystem => %w{Slamd64}
|
98
|
+
setcode do
|
99
|
+
releasefile = Facter::Util::Resolution.exec('cat /etc/slamd64-version')
|
100
|
+
if releasefile =~ /^\s*\w+\s+(\d+)\.(\d+)/
|
101
|
+
$1 + "." + $2
|
102
|
+
else
|
103
|
+
"unknown"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
74
108
|
Facter.add(:operatingsystemrelease) do
|
75
109
|
setcode do Facter[:kernelrelease].value end
|
76
110
|
end
|
data/lib/facter/processor.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
require 'thread'
|
9
9
|
|
10
|
-
if Facter.value(:kernel)
|
10
|
+
if ["Linux", "GNU/kFreeBSD"].include? Facter.value(:kernel)
|
11
11
|
processor_num = -1
|
12
12
|
processor_list = []
|
13
13
|
Thread::exclusive do
|
@@ -17,12 +17,15 @@ if Facter.value(:kernel) == "Linux"
|
|
17
17
|
elsif l =~ /model name\s+:\s+(.*)\s*$/
|
18
18
|
processor_list[processor_num] = $1 unless processor_num == -1
|
19
19
|
processor_num = -1
|
20
|
+
elsif l =~ /processor\s+(\d+):\s+(.*)/
|
21
|
+
processor_num = $1.to_i
|
22
|
+
processor_list[processor_num] = $2 unless processor_num == -1
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
27
|
Facter.add("ProcessorCount") do
|
25
|
-
confine :kernel => :linux
|
28
|
+
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
26
29
|
setcode do
|
27
30
|
processor_list.length.to_s
|
28
31
|
end
|
@@ -30,7 +33,7 @@ if Facter.value(:kernel) == "Linux"
|
|
30
33
|
|
31
34
|
processor_list.each_with_index do |desc, i|
|
32
35
|
Facter.add("Processor#{i}") do
|
33
|
-
confine :kernel => :linux
|
36
|
+
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
34
37
|
setcode do
|
35
38
|
desc
|
36
39
|
end
|
@@ -80,9 +83,9 @@ if Facter.value(:kernel) == "OpenBSD"
|
|
80
83
|
Facter::Util::Resolution.exec("uname -p")
|
81
84
|
end
|
82
85
|
end
|
83
|
-
|
86
|
+
|
84
87
|
Facter.add("ProcessorCount") do
|
85
|
-
confine :kernel => :openbsd
|
88
|
+
confine :kernel => :openbsd
|
86
89
|
setcode do
|
87
90
|
Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d'=' -f2")
|
88
91
|
end
|
data/lib/facter/selinux.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
Facter.add("selinux") do
|
5
5
|
confine :kernel => :linux
|
6
6
|
|
7
|
-
setcode do
|
7
|
+
setcode do
|
8
8
|
result = "false"
|
9
9
|
if FileTest.exists?("/selinux/enforce")
|
10
10
|
if FileTest.exists?("/proc/self/attr/current")
|
@@ -31,15 +31,48 @@ end
|
|
31
31
|
|
32
32
|
Facter.add("selinux_policyversion") do
|
33
33
|
confine :selinux => :true
|
34
|
-
setcode do
|
34
|
+
setcode do
|
35
35
|
File.read("/selinux/policyvers")
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
Facter.add("
|
39
|
+
Facter.add("selinux_current_mode") do
|
40
|
+
confine :selinux => :true
|
41
|
+
setcode do
|
42
|
+
result = 'unknown'
|
43
|
+
mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus')
|
44
|
+
mode.each_line { |l| result = $1 if l =~ /^Current mode\:\s+(\w+)$/i }
|
45
|
+
result.chomp
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Facter.add("selinux_config_mode") do
|
40
50
|
confine :selinux => :true
|
41
51
|
setcode do
|
42
|
-
|
52
|
+
result = 'unknown'
|
53
|
+
mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus')
|
54
|
+
mode.each_line { |l| result = $1 if l =~ /^Mode from config file\:\s+(\w+)$/i }
|
55
|
+
result.chomp
|
43
56
|
end
|
44
57
|
end
|
45
58
|
|
59
|
+
Facter.add("selinux_config_policy") do
|
60
|
+
confine :selinux => :true
|
61
|
+
setcode do
|
62
|
+
result = 'unknown'
|
63
|
+
mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus')
|
64
|
+
mode.each_line { |l| result = $1 if l =~ /^Policy from config file\:\s+(\w+)$/i }
|
65
|
+
result.chomp
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# This is a legacy fact which returns the old selinux_mode fact value to prevent
|
70
|
+
# breakages of existing manifests. It should be removed at the next major release.
|
71
|
+
# See ticket #6677.
|
72
|
+
|
73
|
+
Facter.add("selinux_mode") do
|
74
|
+
confine :selinux => :true
|
75
|
+
setcode do
|
76
|
+
Facter.value(:selinux_config_policy)
|
77
|
+
end
|
78
|
+
end
|
data/lib/facter/uniqueid.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
Facter.add(:uniqueid) do
|
2
2
|
setcode 'hostid', '/bin/sh'
|
3
|
-
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS}
|
3
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS GNU/kFreeBSD}
|
4
4
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
# A module to gather uptime facts
|
4
|
+
#
|
5
|
+
module Facter::Util::Uptime
|
6
|
+
def self.get_uptime_seconds_unix
|
7
|
+
uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get_uptime_seconds_win
|
11
|
+
require 'win32ole'
|
12
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
13
|
+
query = wmi.ExecQuery("select * from Win32_OperatingSystem")
|
14
|
+
last_boot = ""
|
15
|
+
query.each { |x| last_boot = x.LastBootupTime}
|
16
|
+
self.compute_uptime(Time.parse(last_boot.split('.').first))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.uptime_proc_uptime
|
22
|
+
if output = Facter::Util::Resolution.exec("/bin/cat #{uptime_file} 2>/dev/null")
|
23
|
+
output.chomp.split(" ").first.to_i
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.uptime_sysctl
|
28
|
+
if output = Facter::Util::Resolution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
|
29
|
+
compute_uptime(Time.at(output.unpack('L').first))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.uptime_kstat
|
34
|
+
if output = Facter::Util::Resolution.exec("#{uptime_kstat_cmd} 2>/dev/null")
|
35
|
+
compute_uptime(Time.at(output.chomp.split(/\s/).last.to_i))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.uptime_who_dash_b
|
40
|
+
if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null")
|
41
|
+
compute_uptime(Time.parse(output))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.compute_uptime(time)
|
46
|
+
(Time.now - time).to_i
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.uptime_file
|
50
|
+
"/proc/uptime"
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.uptime_sysctl_cmd
|
54
|
+
'sysctl -b kern.boottime'
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.uptime_kstat_cmd
|
58
|
+
'kstat -p unix:::boot_time'
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.uptime_who_cmd
|
62
|
+
'who -b'
|
63
|
+
end
|
64
|
+
end
|
data/lib/facter/util/ip.rb
CHANGED
@@ -6,17 +6,20 @@ module Facter::Util::IP
|
|
6
6
|
REGEX_MAP = {
|
7
7
|
:linux => {
|
8
8
|
:ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
|
9
|
+
:ipaddress6 => /inet6 addr: ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/,
|
9
10
|
:macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/,
|
10
11
|
:netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
11
12
|
},
|
12
13
|
:bsd => {
|
13
|
-
:aliases => [:openbsd, :netbsd, :freebsd, :darwin],
|
14
|
+
:aliases => [:openbsd, :netbsd, :freebsd, :darwin, :"gnu/kfreebsd"],
|
14
15
|
:ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
|
15
|
-
:
|
16
|
+
:ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/,
|
17
|
+
:macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/,
|
16
18
|
:netmask => /netmask\s+0x(\w{8})/
|
17
19
|
},
|
18
20
|
:sunos => {
|
19
21
|
:ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
|
22
|
+
:ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/,
|
20
23
|
:macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/,
|
21
24
|
:netmask => /netmask\s+(\w{8})/
|
22
25
|
},
|
@@ -33,7 +36,7 @@ module Facter::Util::IP
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def self.convert_from_hex?(kernel)
|
36
|
-
kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux"]
|
39
|
+
kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux", :"gnu/kfreebsd"]
|
37
40
|
kernels_to_convert.include?(kernel)
|
38
41
|
end
|
39
42
|
|
@@ -56,17 +59,17 @@ module Facter::Util::IP
|
|
56
59
|
# at the end of interfaces. So, we have to trim those trailing
|
57
60
|
# characters. I tried making the regex better but supporting all
|
58
61
|
# platforms with a single regex is probably a bit too much.
|
59
|
-
output.scan(
|
62
|
+
output.scan(/^\S+/).collect { |i| i.sub(/:$/, '') }.uniq
|
60
63
|
end
|
61
64
|
|
62
65
|
def self.get_all_interface_output
|
63
66
|
case Facter.value(:kernel)
|
64
|
-
when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin'
|
67
|
+
when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD'
|
65
68
|
output = %x{/sbin/ifconfig -a}
|
66
69
|
when 'SunOS'
|
67
70
|
output = %x{/usr/sbin/ifconfig -a}
|
68
71
|
when 'HP-UX'
|
69
|
-
output = %x{/bin/netstat -
|
72
|
+
output = %x{/bin/netstat -in | sed -e 1d}
|
70
73
|
end
|
71
74
|
output
|
72
75
|
end
|
@@ -74,7 +77,7 @@ module Facter::Util::IP
|
|
74
77
|
def self.get_single_interface_output(interface)
|
75
78
|
output = ""
|
76
79
|
case Facter.value(:kernel)
|
77
|
-
when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin'
|
80
|
+
when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD'
|
78
81
|
output = %x{/sbin/ifconfig #{interface}}
|
79
82
|
when 'SunOS'
|
80
83
|
output = %x{/usr/sbin/ifconfig #{interface}}
|
@@ -138,15 +141,13 @@ module Facter::Util::IP
|
|
138
141
|
else
|
139
142
|
output_int = get_single_interface_output(interface)
|
140
143
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
value = $1
|
144
|
+
output_int.each_line do |s|
|
145
|
+
if s =~ regex
|
146
|
+
value = $1
|
145
147
|
if label == 'netmask' && convert_from_hex?(kernel)
|
146
148
|
value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.')
|
147
149
|
end
|
148
|
-
|
149
|
-
end
|
150
|
+
tmp1.push(value)
|
150
151
|
end
|
151
152
|
end
|
152
153
|
|
@@ -155,17 +156,24 @@ module Facter::Util::IP
|
|
155
156
|
end
|
156
157
|
end
|
157
158
|
end
|
158
|
-
|
159
|
+
|
159
160
|
def self.get_network_value(interface)
|
160
161
|
require 'ipaddr'
|
161
162
|
|
162
163
|
ipaddress = get_interface_value(interface, "ipaddress")
|
163
164
|
netmask = get_interface_value(interface, "netmask")
|
164
|
-
|
165
|
+
|
165
166
|
if ipaddress && netmask
|
166
167
|
ip = IPAddr.new(ipaddress, Socket::AF_INET)
|
167
168
|
subnet = IPAddr.new(netmask, Socket::AF_INET)
|
168
169
|
network = ip.mask(subnet.to_s).to_s
|
169
170
|
end
|
170
171
|
end
|
172
|
+
|
173
|
+
def self.get_arp_value(interface)
|
174
|
+
arp = Facter::Util::Resolution.exec("arp -en -i #{interface} | sed -e 1d")
|
175
|
+
if arp =~ /^\S+\s+\w+\s+(\S+)\s+\w\s+\S+$/
|
176
|
+
return $1
|
177
|
+
end
|
178
|
+
end
|
171
179
|
end
|
data/lib/facter/util/loader.rb
CHANGED
@@ -30,7 +30,7 @@ class Facter::Util::Loader
|
|
30
30
|
search_path.each do |dir|
|
31
31
|
next unless FileTest.directory?(dir)
|
32
32
|
|
33
|
-
Dir.entries(dir).each do |file|
|
33
|
+
Dir.entries(dir).sort.each do |file|
|
34
34
|
path = File.join(dir, file)
|
35
35
|
if File.directory?(path)
|
36
36
|
load_dir(path)
|
@@ -62,7 +62,7 @@ class Facter::Util::Loader
|
|
62
62
|
def load_dir(dir)
|
63
63
|
return if dir =~ /\/\.+$/ or dir =~ /\/util$/ or dir =~ /\/lib$/
|
64
64
|
|
65
|
-
Dir.entries(dir).find_all { |f| f =~ /\.rb$/ }.each do |file|
|
65
|
+
Dir.entries(dir).find_all { |f| f =~ /\.rb$/ }.sort.each do |file|
|
66
66
|
load_file(File.join(dir, file))
|
67
67
|
end
|
68
68
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# A module to gather macaddress facts
|
2
|
+
#
|
3
|
+
module Facter::Util::Macaddress
|
4
|
+
|
5
|
+
module Darwin
|
6
|
+
def self.macaddress
|
7
|
+
iface = default_interface
|
8
|
+
Facter.warn "Could not find a default route. Using first non-loopback interface" if iface.empty?
|
9
|
+
|
10
|
+
macaddress = `#{ifconfig_command} #{iface} | /usr/bin/awk '/ether/{print $2;exit}'`.chomp
|
11
|
+
macaddress.empty? ? nil : macaddress
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.default_interface
|
15
|
+
`#{netstat_command} | /usr/bin/awk '/^default/{print $6;exit}'`.chomp
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self.netstat_command
|
21
|
+
'/usr/sbin/netstat -rn'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.ifconfig_command
|
25
|
+
'/sbin/ifconfig'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -5,7 +5,7 @@ module Facter::Manufacturer
|
|
5
5
|
|
6
6
|
def self.get_dmi_table()
|
7
7
|
case Facter.value(:kernel)
|
8
|
-
when 'Linux'
|
8
|
+
when 'Linux', 'GNU/kFreeBSD'
|
9
9
|
return nil unless FileTest.exists?("/usr/sbin/dmidecode")
|
10
10
|
|
11
11
|
output=%x{/usr/sbin/dmidecode 2>/dev/null}
|
@@ -38,7 +38,7 @@ module Facter::Manufacturer
|
|
38
38
|
if line =~ /#{key}/ and line =~ /\n\s+#{value} (.+)\n/
|
39
39
|
result = $1.strip
|
40
40
|
Facter.add(facterkey) do
|
41
|
-
confine :kernel => [ :linux, :freebsd, :netbsd, :sunos ]
|
41
|
+
confine :kernel => [ :linux, :freebsd, :netbsd, :sunos, :"gnu/kfreebsd" ]
|
42
42
|
setcode do
|
43
43
|
result
|
44
44
|
end
|
@@ -60,4 +60,41 @@ module Facter::Manufacturer
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
def self.prtdiag_sparc_find_system_info()
|
65
|
+
# Parses prtdiag for a SPARC architecture string, won't work with Solaris x86
|
66
|
+
output = Facter::Util::Resolution.exec('/usr/sbin/prtdiag')
|
67
|
+
|
68
|
+
# System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server
|
69
|
+
sysconfig = output.split("\n")[0]
|
70
|
+
if sysconfig =~ /^System Configuration:\s+(.+?)\s+(sun\d+\S+)\s+(.+)/ then
|
71
|
+
Facter.add('manufacturer') do
|
72
|
+
setcode do
|
73
|
+
$1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
Facter.add('productname') do
|
77
|
+
setcode do
|
78
|
+
$3
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.win32_find_system_info(name)
|
85
|
+
require 'win32ole'
|
86
|
+
value = ""
|
87
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
88
|
+
name.each do |facterkey, win32key|
|
89
|
+
query = wmi.ExecQuery("select * from Win32_#{win32key.last}")
|
90
|
+
Facter.add(facterkey) do
|
91
|
+
confine :kernel => :windows
|
92
|
+
setcode do
|
93
|
+
query.each { |x| value = x.__send__( (win32key.first).to_sym) }
|
94
|
+
value
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
63
100
|
end
|