facter 1.3.8 → 1.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.

Files changed (46) hide show
  1. data/CHANGELOG +68 -0
  2. data/README +1 -1
  3. data/Rakefile +2 -1
  4. data/bin/facter +16 -11
  5. data/lib/facter.rb +55 -1001
  6. data/lib/facter/Cfkey.rb +42 -0
  7. data/lib/facter/architecture.rb +14 -0
  8. data/lib/facter/domain.rb +64 -0
  9. data/lib/facter/facterversion.rb +3 -0
  10. data/lib/facter/fqdn.rb +10 -0
  11. data/lib/facter/hardwareisa.rb +4 -0
  12. data/lib/facter/hardwaremodel.rb +13 -0
  13. data/lib/facter/hostname.rb +25 -0
  14. data/lib/facter/id.rb +4 -0
  15. data/lib/facter/ipaddress.rb +151 -0
  16. data/lib/facter/iphostnumber.rb +18 -0
  17. data/lib/facter/ipmess.rb +64 -74
  18. data/lib/facter/kernel.rb +3 -0
  19. data/lib/facter/kernelrelease.rb +8 -0
  20. data/lib/facter/lsb.rb +37 -0
  21. data/lib/facter/lsbmajdistrelease.rb +15 -0
  22. data/lib/facter/macaddress.rb +65 -0
  23. data/lib/facter/macosx.rb +25 -55
  24. data/lib/facter/manufacturer.rb +7 -45
  25. data/lib/facter/memory.rb +26 -49
  26. data/lib/facter/netmask.rb +17 -0
  27. data/lib/facter/operatingsystem.rb +37 -0
  28. data/lib/facter/operatingsystemrelease.rb +63 -0
  29. data/lib/facter/processor.rb +36 -14
  30. data/lib/facter/ps.rb +8 -0
  31. data/lib/facter/puppetversion.rb +10 -0
  32. data/lib/facter/rubysitedir.rb +8 -0
  33. data/lib/facter/rubyversion.rb +3 -0
  34. data/lib/facter/ssh.rb +33 -0
  35. data/lib/facter/uniqueid.rb +4 -0
  36. data/lib/facter/util/collection.rb +126 -0
  37. data/lib/facter/util/confine.rb +41 -0
  38. data/lib/facter/util/fact.rb +122 -0
  39. data/lib/facter/util/ip.rb +98 -0
  40. data/lib/facter/util/loader.rb +96 -0
  41. data/lib/facter/util/macosx.rb +50 -0
  42. data/lib/facter/util/manufacturer.rb +39 -0
  43. data/lib/facter/util/memory.rb +54 -0
  44. data/lib/facter/util/netmask.rb +36 -0
  45. data/lib/facter/util/resolution.rb +125 -0
  46. metadata +76 -34
@@ -0,0 +1,42 @@
1
+ ## Cfkey.rb
2
+ ## Facts related to cfengine
3
+ ##
4
+ ## This program is free software; you can redistribute it and/or
5
+ ## modify it under the terms of the GNU General Public License
6
+ ## as published by the Free Software Foundation (version 2 of the License)
7
+ ## This program is distributed in the hope that it will be useful,
8
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ ## GNU General Public License for more details.
11
+ ## You should have received a copy of the GNU General Public License
12
+ ## along with this program; if not, write to the Free Software
13
+ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
14
+ ##
15
+
16
+ Facter.add(:Cfkey) do
17
+ setcode do
18
+ value = nil
19
+ ["/usr/local/etc/cfkey.pub",
20
+ "/etc/cfkey.pub",
21
+ "/var/cfng/keys/localhost.pub",
22
+ "/var/cfengine/ppkeys/localhost.pub",
23
+ "/var/lib/cfengine/ppkeys/localhost.pub",
24
+ "/var/lib/cfengine2/ppkeys/localhost.pub"
25
+ ].each { |file|
26
+ if FileTest.file?(file)
27
+ File.open(file) { |openfile|
28
+ value = openfile.readlines.reject { |line|
29
+ line =~ /PUBLIC KEY/
30
+ }.collect { |line|
31
+ line.chomp
32
+ }.join("")
33
+ }
34
+ end
35
+ if value
36
+ break
37
+ end
38
+ }
39
+
40
+ value
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ Facter.add(:architecture) do
2
+ confine :kernel => :linux
3
+ setcode do
4
+ model = Facter.value(:hardwaremodel)
5
+ case model
6
+ # most linuxen use "x86_64"
7
+ when 'x86_64':
8
+ Facter.value(:operatingsystem) == "Debian" ? "amd64" : model;
9
+ when /(i[3456]86|pentium)/: "i386"
10
+ else
11
+ model
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,64 @@
1
+ Facter.add(:domain) do
2
+ setcode do
3
+ # First force the hostname to be checked
4
+ Facter.value(:hostname)
5
+
6
+ # Now check to see if it set the domain
7
+ if defined? $domain and ! $domain.nil?
8
+ $domain
9
+ else
10
+ nil
11
+ end
12
+ end
13
+ end
14
+ # Look for the DNS domain name command first.
15
+ Facter.add(:domain) do
16
+ setcode do
17
+ domain = Facter::Util::Resolution.exec('dnsdomainname') or nil
18
+ # make sure it's a real domain
19
+ if domain and domain =~ /.+\..+/
20
+ domain
21
+ else
22
+ nil
23
+ end
24
+ end
25
+ end
26
+ Facter.add(:domain) do
27
+ setcode do
28
+ domain = Facter::Util::Resolution.exec('domainname') or nil
29
+ # make sure it's a real domain
30
+ if domain and domain =~ /.+\..+/
31
+ domain
32
+ else
33
+ nil
34
+ end
35
+ end
36
+ end
37
+ Facter.add(:domain) do
38
+ setcode do
39
+ value = nil
40
+ if FileTest.exists?("/etc/resolv.conf")
41
+ File.open("/etc/resolv.conf") { |file|
42
+ # is the domain set?
43
+ file.each { |line|
44
+ if line =~ /domain\s+(\S+)/
45
+ value = $1
46
+ break
47
+ end
48
+ }
49
+ }
50
+ ! value and File.open("/etc/resolv.conf") { |file|
51
+ # is the search path set?
52
+ file.each { |line|
53
+ if line =~ /search\s+(\S+)/
54
+ value = $1
55
+ break
56
+ end
57
+ }
58
+ }
59
+ value
60
+ else
61
+ nil
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ Facter.add(:facterversion) do
2
+ setcode { Facter::FACTERVERSION.to_s }
3
+ end
@@ -0,0 +1,10 @@
1
+ Facter.add(:fqdn) do setcode do
2
+ host = Facter.value(:hostname)
3
+ domain = Facter.value(:domain)
4
+ if host and domain
5
+ [host, domain].join(".")
6
+ else
7
+ nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ Facter.add(:hardwareisa) do
2
+ setcode 'uname -p', '/bin/sh'
3
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo FreeBSD OpenBSD NetBSD}
4
+ end
@@ -0,0 +1,13 @@
1
+ Facter.add(:hardwaremodel) do
2
+ setcode 'uname -m'
3
+ end
4
+
5
+ Facter.add(:hardwaremodel) do
6
+ confine :operatingsystem => :aix
7
+ setcode do
8
+ model = Facter::Util::Resolution.exec('lsattr -El sys0 -a modelname')
9
+ if model =~ /modelname\s(\S+)\s/
10
+ $1
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ Facter.add(:hostname, :ldapname => "cn") do
2
+ setcode do
3
+ hostname = nil
4
+ name = Facter::Util::Resolution.exec('hostname') or nil
5
+ if name
6
+ if name =~ /^([\w-]+)\.(.+)$/
7
+ hostname = $1
8
+ # the Domain class uses this
9
+ $domain = $2
10
+ else
11
+ hostname = name
12
+ end
13
+ hostname
14
+ else
15
+ nil
16
+ end
17
+ end
18
+ end
19
+
20
+ Facter.add(:hostname) do
21
+ confine :kernel => :darwin, :kernelrelease => "R7"
22
+ setcode do
23
+ %x{/usr/sbin/scutil --get LocalHostName}
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ Facter.add(:id) do
2
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo AIX}
3
+ setcode "whoami"
4
+ end
@@ -0,0 +1,151 @@
1
+ Facter.add(:ipaddress, :ldapname => "iphostnumber") 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) 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
+ host = 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
+ Facter.add(:ipaddress) do
43
+ confine :kernel => :linux
44
+ setcode do
45
+ ip = nil
46
+ output = %x{/sbin/ifconfig}
47
+
48
+ output.split(/^\S/).each { |str|
49
+ if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
50
+ tmp = $1
51
+ unless tmp =~ /127\./
52
+ ip = tmp
53
+ break
54
+ end
55
+ end
56
+ }
57
+
58
+ ip
59
+ end
60
+ end
61
+
62
+ Facter.add(:ipaddress) do
63
+ confine :kernel => %w{FreeBSD OpenBSD solaris}
64
+ setcode do
65
+ ip = nil
66
+ output = %x{/sbin/ifconfig}
67
+
68
+ output.split(/^\S/).each { |str|
69
+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
70
+ tmp = $1
71
+ unless tmp =~ /127\./
72
+ ip = tmp
73
+ break
74
+ end
75
+ end
76
+ }
77
+
78
+ ip
79
+ end
80
+ end
81
+
82
+ Facter.add(:ipaddress) do
83
+ confine :kernel => %w{NetBSD}
84
+ setcode do
85
+ ip = nil
86
+ output = %x{/sbin/ifconfig -a}
87
+
88
+ output.split(/^\S/).each { |str|
89
+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
90
+ tmp = $1
91
+ unless tmp =~ /127\./
92
+ ip = tmp
93
+ break
94
+ end
95
+ end
96
+ }
97
+
98
+ ip
99
+ end
100
+ end
101
+
102
+ Facter.add(:ipaddress) do
103
+ confine :kernel => %w{darwin}
104
+ setcode do
105
+ ip = nil
106
+ iface = ""
107
+ output = %x{/usr/sbin/netstat -rn}
108
+ if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/
109
+ iface = $1
110
+ else
111
+ warn "Could not find a default route. Using first non-loopback interface"
112
+ end
113
+ if(iface != "")
114
+ output = %x{/sbin/ifconfig #{iface}}
115
+ else
116
+ output = %x{/sbin/ifconfig}
117
+ end
118
+
119
+ output.split(/^\S/).each { |str|
120
+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
121
+ tmp = $1
122
+ unless tmp =~ /127\./
123
+ ip = tmp
124
+ break
125
+ end
126
+ end
127
+ }
128
+
129
+ ip
130
+ end
131
+ end
132
+
133
+ Facter.add(:ipaddress) do
134
+ confine :kernel => %w{AIX}
135
+ setcode do
136
+ ip = nil
137
+ output = %x{/usr/sbin/ifconfig -a}
138
+
139
+ output.split(/^\S/).each { |str|
140
+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
141
+ tmp = $1
142
+ unless tmp =~ /127\./
143
+ ip = tmp
144
+ break
145
+ end
146
+ end
147
+ }
148
+
149
+ ip
150
+ end
151
+ end
@@ -0,0 +1,18 @@
1
+ Facter.add(:iphostnumber) do
2
+ confine :kernel => :darwin, :kernelrelease => "R6"
3
+ setcode do
4
+ %x{/usr/sbin/scutil --get LocalHostName}
5
+ end
6
+ end
7
+ Facter.add(:iphostnumber) do
8
+ confine :kernel => :darwin, :kernelrelease => "R6"
9
+ setcode do
10
+ ether = nil
11
+ output = %x{/sbin/ifconfig}
12
+
13
+ output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
14
+ ether = $1
15
+
16
+ ether
17
+ end
18
+ end
@@ -1,85 +1,75 @@
1
- #
2
1
  # ipmess.rb
3
- # Try to get additional Facts about the machine's network interfaces on Linux
2
+ # Try to get additional Facts about the machine's network interfaces
4
3
  #
5
4
  # Original concept Copyright (C) 2007 psychedelys <psychedelys@gmail.com>
6
5
  # Update and *BSD support (C) 2007 James Turnbull <james@lovedthanlost.net>
7
6
  #
8
- # This program is free software; you can redistribute it and/or
9
- # modify it under the terms of the GNU General Public License
10
- # as published by the Free Software Foundation (version 2 of the License)
11
- # This program is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
18
- #
19
7
 
20
- if Facter.kernel == "Linux"
8
+ require 'facter/util/ip'
21
9
 
22
- output = %x{/sbin/ifconfig -a}
23
- int = nil
24
- output.scan(/^(\w+)(\d+)/) { |str|
25
- output_int = %x{/sbin/ifconfig #{str}}
26
- int = "#{str}"
27
- tmp1 = nil
28
- tmp2 = nil
29
- test = {}
30
- output_int.each { |s|
31
- int = "#{str}"
32
- tmp1 = $1 if s =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
33
- tmp2 = $1 if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
34
- if tmp1 != nil && tmp2 != nil && int != "lo"
35
- test["ipaddress_" + int] = tmp1
36
- test["macaddress_" + int] = tmp2
37
- int = nil
38
- tmp1 = nil
39
- tmp2 = nil
40
- end
41
- }
42
- test.each{|name,fact|
43
- Facter.add(name) do
44
- confine :kernel => :linux
45
- setcode do
46
- fact
47
- end
48
- end
49
- }
50
- }
10
+ Facter.add(:interfaces) do
11
+ confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
12
+ setcode do
13
+ Facter::IPAddress.get_interfaces.join(",")
14
+ end
51
15
  end
52
16
 
53
- if Facter.kernel == "FreeBSD" || Facter.kernel == "OpenBSD" || Facter.kernel == "NetBSD"
17
+ case Facter.value(:kernel)
18
+ when 'SunOS', 'Linux'
19
+ Facter::IPAddress.get_interfaces.each do |interface|
20
+ mi = interface.gsub(':', '_')
54
21
 
55
- output = %x{/sbin/ifconfig -a}
56
- int = nil
57
- output.scan(/^(\w+)(\d+):/) { |str|
58
- output_int = %x{/sbin/ifconfig #{str}}
59
- int = "#{str}"
60
- tmp1 = nil
61
- tmp2 = nil
62
- test = {}
63
- output_int.each { |s|
64
- int = "#{str}"
65
- tmp1 = $1 if s =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
66
- tmp2 = $1 if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
67
- if tmp1 != nil && tmp2 != nil && int != "lo"
68
- test["ipaddress_" + int] = tmp1
69
- test["macaddress_" + int] = tmp2
70
- int = nil
71
- tmp1 = nil
72
- tmp2 = nil
73
- end
74
- }
75
- test.each{|name,fact|
76
- Facter.add(name) do
77
- confine :kernel => :linux
78
- setcode do
79
- fact
80
- end
81
- end
82
- }
83
- }
84
- end
22
+ Facter.add("ipaddress_" + mi) do
23
+ confine :kernel => [ :sunos, :linux ]
24
+ setcode do
25
+ label = 'ipaddress'
26
+ Facter::IPAddress.get_interface_value_nonbsd(interface, label)
27
+ end
28
+ end
29
+
30
+ Facter.add("macaddress_" + mi) do
31
+ confine :kernel => [ :sunos, :linux ]
32
+ setcode do
33
+ label = 'macaddress'
34
+ Facter::IPAddress.get_interface_value_nonbsd(interface, label)
35
+ end
36
+ end
85
37
 
38
+ Facter.add("netmask_" + mi) do
39
+ confine :kernel => [ :sunos, :linux ]
40
+ setcode do
41
+ label = 'netmask'
42
+ Facter::IPAddress.get_interface_value_nonbsd(interface, label)
43
+ end
44
+ end
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
+ end