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,3 @@
1
+ Facter.add(:kernel) do
2
+ setcode 'uname -s'
3
+ end
@@ -0,0 +1,8 @@
1
+ Facter.add(:kernelrelease) do
2
+ setcode 'uname -r'
3
+ end
4
+
5
+ Facter.add(:kernelrelease, :timeout => 5) do
6
+ confine :kernel => :aix
7
+ setcode 'oslevel -s'
8
+ end
@@ -0,0 +1,37 @@
1
+ ## lsb.rb
2
+ ## Facts related to Linux Standard Base (LSB)
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
+ { "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
+ }.each do |fact, pattern|
22
+ Facter.add(fact) do
23
+ setcode do
24
+ unless defined?(@@lsbdata) and defined?(@@lsbtime) and (Time.now.to_i - @@lsbtime.to_i < 5)
25
+ type = nil
26
+ @@lsbtime = Time.now
27
+ @@lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
28
+ end
29
+
30
+ if pattern.match(@@lsbdata)
31
+ $1
32
+ else
33
+ nil
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ # lsbmajdistrelease.rb
2
+ #
3
+ require 'facter'
4
+
5
+ Facter.add("lsbmajdistrelease") do
6
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
7
+ setcode do
8
+ if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
9
+ result=$1
10
+ else
11
+ result=Facter.value(:lsbdistrelease)
12
+ end
13
+ result
14
+ end
15
+ end
@@ -0,0 +1,65 @@
1
+ Facter.add(:macaddress) do
2
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
3
+ setcode do
4
+ ether = []
5
+ output = %x{/sbin/ifconfig -a}
6
+ output.each {|s|
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
+ }
9
+ ether[0]
10
+ end
11
+ end
12
+
13
+ Facter.add(:macaddress) do
14
+ confine :operatingsystem => %w{FreeBSD OpenBSD}
15
+ setcode do
16
+ ether = []
17
+ output = %x{/sbin/ifconfig}
18
+ output.each {|s|
19
+ if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
20
+ ether.push($1)
21
+ end
22
+ }
23
+ ether[0]
24
+ end
25
+ end
26
+
27
+ Facter.add(:macaddress) do
28
+ confine :kernel => :darwin
29
+ setcode do
30
+ ether = nil
31
+ output = %x{/sbin/ifconfig}
32
+
33
+ output.split(/^\S/).each { |str|
34
+ if str =~ /10baseT/ # we're wired
35
+ str =~ /ether (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
36
+ ether = $1
37
+ end
38
+ }
39
+
40
+ ether
41
+ end
42
+ end
43
+
44
+ Facter.add(:macaddress) do
45
+ confine :kernel => %w{AIX}
46
+ setcode do
47
+ ether = []
48
+ ip = nil
49
+ output = %x{/usr/sbin/ifconfig -a}
50
+ output.each { |str|
51
+ if str =~ /([a-z]+\d+): flags=/
52
+ devname = $1
53
+ unless devname =~ /lo0/
54
+ output2 = %x{/usr/bin/entstat #{devname}}
55
+ output2.each { |str2|
56
+ if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
57
+ ether.push($1)
58
+ end
59
+ }
60
+ end
61
+ end
62
+ }
63
+ ether[0]
64
+ end
65
+ end
@@ -10,11 +10,11 @@
10
10
  # as published by the Free Software Foundation (version 2 of the License)
11
11
  # This program is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  # You should have received a copy of the GNU General Public License
16
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
17
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
18
18
 
19
19
  # Jeff McCune
20
20
  # There's a lot more information coming out of system_profiler -xml
@@ -22,63 +22,33 @@
22
22
  # at this point in time.
23
23
  # In particular, Installed Software might be an interesting addition.
24
24
 
25
- module Facter::Macosx
26
- require 'thread'
27
- require 'facter/util/plist'
28
-
29
- # JJM I'd really like to dynamically generate these methods
30
- # by looking at the _name key of the _items dict for each _dataType
31
-
32
- def self.hardware_overview
33
- # JJM Perhaps we should cache the XML data in a "class" level object.
34
- top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPHardwareDataType}
35
- system_hardware = top_level_plist[0]['_items'][0]
36
- system_hardware.delete '_name'
37
- system_hardware
38
- end
39
-
40
- # SPSoftwareDataType
41
- def self.os_overview
42
- top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPSoftwareDataType}
43
- os_stuff = top_level_plist[0]['_items'][0]
44
- os_stuff.delete '_name'
45
- os_stuff
46
- end
47
-
48
- def self.sw_vers
49
- ver = Hash.new
50
- [ "productName", "productVersion", "buildVersion" ].each do |option|
51
- ver["macosx_#{option}"] = %x{sw_vers -#{option}}.strip
52
- end
53
- ver
54
- end
55
- end
25
+ require 'facter/util/macosx'
56
26
 
57
- if Facter.kernel == "Darwin"
58
- Facter::Macosx.hardware_overview.each do |fact, value|
59
- Facter.add("sp_#{fact}") do
60
- confine :kernel => :darwin
61
- setcode do
62
- value
63
- end
27
+ if Facter.value(:kernel) == "Darwin"
28
+ Facter::Macosx.hardware_overview.each do |fact, value|
29
+ Facter.add("sp_#{fact}") do
30
+ confine :kernel => :darwin
31
+ setcode do
32
+ value.to_s
33
+ end
34
+ end
64
35
  end
65
- end
66
36
 
67
- Facter::Macosx.os_overview.each do |fact, value|
68
- Facter.add("sp_#{fact}") do
69
- confine :kernel => :darwin
70
- setcode do
71
- value
72
- end
37
+ Facter::Macosx.os_overview.each do |fact, value|
38
+ Facter.add("sp_#{fact}") do
39
+ confine :kernel => :darwin
40
+ setcode do
41
+ value.to_s
42
+ end
43
+ end
73
44
  end
74
- end
75
45
 
76
- Facter::Macosx.sw_vers.each do |fact, value|
77
- Facter.add(fact) do
78
- confine :kernel => :darwin
79
- setcode do
80
- value
81
- end
46
+ Facter::Macosx.sw_vers.each do |fact, value|
47
+ Facter.add(fact) do
48
+ confine :kernel => :darwin
49
+ setcode do
50
+ value
51
+ end
52
+ end
82
53
  end
83
- end
84
54
  end
@@ -1,48 +1,10 @@
1
- # Info about the manufacturer
2
- #
3
-
4
- module Facter::Manufacturer
5
- def self.dmi_find_system_info(name)
6
- return nil unless FileTest.exists?("/usr/sbin/dmidecode")
1
+ # manufacturer.rb
2
+ # Facts related to hardware manufacturer
3
+ #
4
+ #
7
5
 
8
- # Do not run the command more than every five seconds.
9
- unless defined?(@data) and defined?(@time) and (Time.now.to_i - @time.to_i < 5)
10
- @data = {}
11
- type = nil
12
- @time = Time.now
13
- # It's *much* easier to just parse the whole darn file than
14
- # to just match a chunk of it.
15
- %x{/usr/sbin/dmidecode 2>/dev/null}.split("\n").each do |line|
16
- case line
17
- when /^(\S.+)$/
18
- type = $1.chomp
19
- @data[type] ||= {}
20
- when /^\s+(\S.+): (\S.*)$/
21
- unless type
22
- next
23
- end
24
- @data[type][$1] = $2
25
- end
26
- end
27
- end
6
+ require 'facter/util/manufacturer'
28
7
 
29
- if data = @data["System Information"]
30
- data[name]
31
- else
32
- nil
33
- end
34
- end
35
- end
36
-
37
- # Add the facts to Facter
8
+ query = { 'System Information' => [ 'Manufacturer:', 'Product Name:' , 'Serial Number:'], 'Chassis Information' => 'Type:'}
38
9
 
39
- {:SerialNumber => "Serial Number",
40
- :Manufacturer => "Manufacturer",
41
- :ProductName=> "Product Name"}.each do |fact, name|
42
- Facter.add(fact) do
43
- confine :kernel => :linux
44
- setcode do
45
- Facter::Manufacturer.dmi_find_system_info(name)
46
- end
47
- end
48
- end
10
+ Facter::Manufacturer.dmi_find_system_info(query)
@@ -1,68 +1,45 @@
1
- #
2
1
  # memory.rb
3
2
  # Additional Facts for memory/swap usage
4
3
  #
5
4
  # Copyright (C) 2006 Mooter Media Ltd
6
5
  # Author: Matthew Palmer <matt@solutionsfirst.com.au>
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
- module Facter::Memory
20
- require 'thread'
7
+ #
8
+ require 'facter/util/memory'
21
9
 
22
- def self.meminfo_number(tag)
23
- memsize = ""
24
- Thread::exclusive do
25
- size, scale = [0, ""]
26
- File.readlines("/proc/meminfo").each do |l|
27
- size, scale = [$1.to_f, $2] if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/
28
- # MemoryFree == memfree + cached + buffers
29
- # (assume scales are all the same as memfree)
30
- if tag == "MemFree" &&
31
- l =~ /^(?:Buffers|Cached):\s+(\d+)\s+(?:\S+)/
32
- size += $1.to_f
33
- end
34
- end
35
- memsize = scale_number(size, scale)
10
+ {:MemorySize => "MemTotal",
11
+ :MemoryFree => "MemFree",
12
+ :SwapSize => "SwapTotal",
13
+ :SwapFree => "SwapFree"}.each do |fact, name|
14
+ Facter.add(fact) do
15
+ confine :kernel => :linux
16
+ setcode do
17
+ Facter::Memory.meminfo_number(name)
36
18
  end
37
-
38
- memsize
39
19
  end
20
+ end
40
21
 
41
- def self.scale_number(size, multiplier)
42
- suffixes = ['', 'kB', 'MB', 'GB', 'TB']
43
-
44
- s = suffixes.shift
45
- while s != multiplier
46
- s = suffixes.shift
22
+ if Facter.value(:kernel) == "AIX"
23
+ swap = Facter::Util::Resolution.exec('swap -l')
24
+ swapfree, swaptotal = 0, 0
25
+ swap.each do |dev|
26
+ if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/
27
+ swaptotal += $1.to_i
28
+ swapfree += $2.to_i
47
29
  end
30
+ end
48
31
 
49
- while size > 1024.0
50
- size /= 1024.0
51
- s = suffixes.shift
32
+ Facter.add("SwapSize") do
33
+ confine :kernel => :aix
34
+ setcode do
35
+ Facter::Memory.scale_number(swaptotal.to_f,"MB")
52
36
  end
53
-
54
- return "%.2f %s" % [size, s]
55
37
  end
56
- end
57
38
 
58
- {:MemorySize => "MemTotal",
59
- :MemoryFree => "MemFree",
60
- :SwapSize => "SwapTotal",
61
- :SwapFree => "SwapFree"}.each do |fact, name|
62
- Facter.add(fact) do
63
- confine :kernel => :linux
39
+ Facter.add("SwapFree") do
40
+ confine :kernel => :aix
64
41
  setcode do
65
- Facter::Memory.meminfo_number(name)
42
+ Facter::Memory.scale_number(swapfree.to_f,"MB")
66
43
  end
67
44
  end
68
45
  end
@@ -0,0 +1,17 @@
1
+ # netmask.rb
2
+ # Find the netmask of the primary ipaddress
3
+ # Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
4
+ # Copyright (C) 2007 Mark 'phips' Phillips
5
+ #
6
+ # idea and originial source by Mark 'phips' Phillips
7
+ #
8
+
9
+ require 'facter/util/netmask'
10
+
11
+ Facter.add("netmask") do
12
+ confine :kernel => [ :sunos, :linux ]
13
+ setcode do
14
+ Facter::NetMask.get_netmask
15
+ end
16
+ end
17
+
@@ -0,0 +1,37 @@
1
+ Facter.add(:operatingsystem) do
2
+ confine :kernel => :sunos
3
+ setcode do "Solaris" end
4
+ end
5
+
6
+ Facter.add(:operatingsystem) do
7
+ confine :kernel => :linux
8
+ setcode do
9
+ if Facter.value(:lsbdistid) == "Ubuntu"
10
+ "Ubuntu"
11
+ elsif FileTest.exists?("/etc/debian_version")
12
+ "Debian"
13
+ elsif FileTest.exists?("/etc/gentoo-release")
14
+ "Gentoo"
15
+ elsif FileTest.exists?("/etc/fedora-release")
16
+ "Fedora"
17
+ elsif FileTest.exists?("/etc/mandriva-release")
18
+ "Mandriva"
19
+ elsif FileTest.exists?("/etc/mandrake-release")
20
+ "Mandrake"
21
+ elsif FileTest.exists?("/etc/redhat-release")
22
+ txt = File.read("/etc/redhat-release")
23
+ if txt =~ /centos/i
24
+ "CentOS"
25
+ else
26
+ "RedHat"
27
+ end
28
+ elsif FileTest.exists?("/etc/SuSE-release")
29
+ "SuSE"
30
+ end
31
+ end
32
+ end
33
+
34
+ Facter.add(:operatingsystem) do
35
+ # Default to just returning the kernel as the operating system
36
+ setcode do Facter[:kernel].value end
37
+ end
@@ -0,0 +1,63 @@
1
+ Facter.add(:operatingsystemrelease) do
2
+ confine :operatingsystem => :fedora
3
+ setcode do
4
+ File::open("/etc/fedora-release", "r") do |f|
5
+ line = f.readline.chomp
6
+ if line =~ /\(Rawhide\)$/
7
+ "Rawhide"
8
+ elsif line =~ /release (\d+)/
9
+ $1
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Facter.add(:operatingsystemrelease) do
16
+ confine :operatingsystem => %w{RedHat}
17
+ setcode do
18
+ File::open("/etc/redhat-release", "r") do |f|
19
+ line = f.readline.chomp
20
+ if line =~ /\(Rawhide\)$/
21
+ "Rawhide"
22
+ elsif line =~ /release (\d+)/
23
+ $1
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ Facter.add(:operatingsystemrelease) do
30
+ confine :operatingsystem => %w{CentOS}
31
+ setcode do
32
+ centosrelease = Facter::Util::Resolution.exec('cat /etc/redhat-release | sed -e \'s/CentOS release//g\' -e \'s/(Final)//g\'')
33
+ if centosrelease =~ /^5^/
34
+ release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2')
35
+ else
36
+ release = Facter::Util::Resolution.exec('cat /etc/redhat-release | sed -e \'s/CentOS release//g\' -e \'s/(Final)//g\'')
37
+ end
38
+ end
39
+ end
40
+
41
+ Facter.add(:operatingsystemrelease) do
42
+ confine :operatingsystem => %w{Debian}
43
+ setcode do
44
+ release = Facter::Util::Resolution.exec('cat /proc/version')
45
+ if release =~ /\(Debian (\d+.\d+).\d+-\d+\)/
46
+ $1
47
+ end
48
+ end
49
+ end
50
+
51
+ Facter.add(:operatingsystemrelease) do
52
+ confine :operatingsystem => %w{Ubuntu}
53
+ setcode do
54
+ release = Facter::Util::Resolution.exec('cat /etc/issue')
55
+ if release =~ /Ubuntu (\d+.\d+)/
56
+ $1
57
+ end
58
+ end
59
+ end
60
+
61
+ Facter.add(:operatingsystemrelease) do
62
+ setcode do Facter[:kernelrelease].value end
63
+ end