facter 1.6.0 → 1.6.1

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 (63) hide show
  1. data/CHANGELOG +53 -0
  2. data/CONTRIBUTING.md +299 -0
  3. data/Rakefile +3 -3
  4. data/conf/redhat/facter.spec +1 -1
  5. data/install.rb +25 -10
  6. data/lib/facter.rb +16 -1
  7. data/lib/facter/arp.rb +1 -1
  8. data/lib/facter/augeasversion.rb +29 -0
  9. data/lib/facter/domain.rb +9 -10
  10. data/lib/facter/hardwareisa.rb +2 -2
  11. data/lib/facter/hostname.rb +4 -9
  12. data/lib/facter/ipaddress6.rb +9 -0
  13. data/lib/facter/kernel.rb +3 -3
  14. data/lib/facter/kernelrelease.rb +2 -4
  15. data/lib/facter/lsbmajdistrelease.rb +1 -1
  16. data/lib/facter/macaddress.rb +11 -31
  17. data/lib/facter/manufacturer.rb +5 -0
  18. data/lib/facter/memory.rb +32 -4
  19. data/lib/facter/operatingsystem.rb +6 -0
  20. data/lib/facter/operatingsystemrelease.rb +11 -2
  21. data/lib/facter/physicalprocessorcount.rb +8 -0
  22. data/lib/facter/processor.rb +38 -0
  23. data/lib/facter/ps.rb +5 -0
  24. data/lib/facter/selinux.rb +63 -48
  25. data/lib/facter/uniqueid.rb +2 -2
  26. data/lib/facter/util/config.rb +9 -0
  27. data/lib/facter/util/ip.rb +26 -3
  28. data/lib/facter/util/loader.rb +11 -0
  29. data/lib/facter/util/macaddress.rb +20 -0
  30. data/lib/facter/util/manufacturer.rb +10 -5
  31. data/lib/facter/util/resolution.rb +18 -9
  32. data/lib/facter/util/uptime.rb +6 -5
  33. data/lib/facter/util/wmi.rb +16 -0
  34. data/lib/facter/virtual.rb +15 -8
  35. data/spec/fixtures/netsh/windows_netsh_addresses_with_multiple_interfaces +35 -0
  36. data/spec/fixtures/unit/util/loader/nosuchfact.rb +1 -0
  37. data/spec/spec_helper.rb +1 -0
  38. data/spec/unit/data/windows_netsh_all_interfaces +12 -0
  39. data/spec/unit/data/windows_netsh_single_interface +7 -0
  40. data/spec/unit/data/windows_netsh_single_interface6 +18 -0
  41. data/spec/unit/domain_spec.rb +91 -0
  42. data/spec/unit/facter_spec.rb +21 -0
  43. data/spec/unit/hostname_spec.rb +38 -0
  44. data/spec/unit/id_spec.rb +6 -5
  45. data/spec/unit/interfaces_spec.rb +7 -0
  46. data/spec/unit/ipaddress6_spec.rb +19 -0
  47. data/spec/unit/macaddress_spec.rb +38 -0
  48. data/spec/unit/memory_spec.rb +26 -0
  49. data/spec/unit/operatingsystem_spec.rb +28 -0
  50. data/spec/unit/operatingsystemrelease_spec.rb +19 -8
  51. data/spec/unit/physicalprocessorcount_spec.rb +11 -0
  52. data/spec/unit/processor_spec.rb +66 -0
  53. data/spec/unit/selinux_spec.rb +1 -0
  54. data/spec/unit/util/ip_spec.rb +83 -21
  55. data/spec/unit/util/loader_spec.rb +8 -0
  56. data/spec/unit/util/macaddress_spec.rb +28 -1
  57. data/spec/unit/util/manufacturer_spec.rb +21 -0
  58. data/spec/unit/util/resolution_spec.rb +26 -14
  59. data/spec/unit/util/uptime_spec.rb +7 -1
  60. data/spec/unit/util/wmi_spec.rb +20 -0
  61. data/spec/unit/virtual_spec.rb +41 -5
  62. metadata +19 -8
  63. data/spec/spec.opts +0 -5
@@ -24,7 +24,7 @@ module Facter
24
24
  include Comparable
25
25
  include Enumerable
26
26
 
27
- FACTERVERSION = '1.6.0'
27
+ FACTERVERSION = '1.6.1'
28
28
  # = Facter
29
29
  # Functions as a hash of 'facts' you might care about about your
30
30
  # system, such as mac address, IP address, Video card, etc.
@@ -46,6 +46,7 @@ module Facter
46
46
  RESET = ""
47
47
  @@debug = 0
48
48
  @@timing = 0
49
+ @@messages = {}
49
50
 
50
51
  # module methods
51
52
 
@@ -158,6 +159,12 @@ module Facter
158
159
  Facter.reset
159
160
  end
160
161
 
162
+ # Clear all messages. Used only in testing. Can't add to self.clear
163
+ # because we don't want to warn multiple times for items that are warnonce'd
164
+ def self.clear_messages
165
+ @@messages.clear
166
+ end
167
+
161
168
  # Set debugging on or off.
162
169
  def self.debugging(bit)
163
170
  if bit
@@ -208,6 +215,14 @@ module Facter
208
215
  end
209
216
  end
210
217
 
218
+ # Warn once.
219
+ def self.warnonce(msg)
220
+ if msg and not msg.empty? and @@messages[msg].nil?
221
+ @@messages[msg] = true
222
+ Kernel.warn(msg)
223
+ end
224
+ end
225
+
211
226
  # Remove them all.
212
227
  def self.reset
213
228
  @collection = nil
@@ -3,7 +3,7 @@ require 'facter/util/ip'
3
3
  Facter.add(:arp) do
4
4
  confine :kernel => :linux
5
5
  setcode do
6
- output = Facter::Util::Resolution.exec('arp -a')
6
+ output = Facter::Util::Resolution.exec('arp -an')
7
7
  if not output.nil?
8
8
  arp = ""
9
9
  output.each_line do |s|
@@ -0,0 +1,29 @@
1
+ # Fact: augeasversion
2
+ #
3
+ # Purpose: Report the version of the Augeas library
4
+ #
5
+ # Resolution:
6
+ # Loads ruby-augeas and reports the value of /augeas/version, the version of
7
+ # the underlying Augeas library.
8
+ #
9
+ # Caveats:
10
+ # The library version may not indicate the presence of certain lenses,
11
+ # depending on the system packages updated, nor the version of ruby-augeas
12
+ # which may affect support for the Puppet Augeas provider.
13
+ # Versions prior to 0.3.6 cannot be interrogated for their version.
14
+ #
15
+
16
+ Facter.add(:augeasversion) do
17
+ setcode do
18
+ begin
19
+ require 'augeas'
20
+ aug = Augeas::open('/', nil, Augeas::NO_MODL_AUTOLOAD)
21
+ ver = aug.get('/augeas/version')
22
+ aug.close
23
+ ver
24
+ rescue Exception
25
+ Facter.debug('ruby-augeas not available')
26
+ end
27
+ end
28
+ end
29
+
@@ -23,13 +23,15 @@ Facter.add(:domain) do
23
23
  # Get the domain from various sources; the order of these
24
24
  # steps is important
25
25
 
26
- Facter.value(:hostname)
27
- next $domain if defined? $domain and ! $domain.nil?
26
+ if name = Facter::Util::Resolution.exec('hostname') and
27
+ name =~ /.*?\.(.+$)/
28
28
 
29
- domain = Facter::Util::Resolution.exec('dnsdomainname')
30
- next domain if domain =~ /.+\..+/
29
+ $1
30
+ elsif domain = Facter::Util::Resolution.exec('dnsdomainname') and
31
+ domain =~ /.+\..+/
31
32
 
32
- if FileTest.exists?("/etc/resolv.conf")
33
+ domain
34
+ elsif FileTest.exists?("/etc/resolv.conf")
33
35
  domain = nil
34
36
  search = nil
35
37
  File.open("/etc/resolv.conf") { |file|
@@ -44,18 +46,15 @@ Facter.add(:domain) do
44
46
  next domain if domain
45
47
  next search if search
46
48
  end
47
- nil
48
49
  end
49
50
  end
50
51
 
51
52
  Facter.add(:domain) do
52
53
  confine :kernel => :windows
53
54
  setcode do
54
- require 'win32ole'
55
+ require 'facter/util/wmi'
55
56
  domain = ""
56
- wmi = WIN32OLE.connect("winmgmts://")
57
- query = "select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True"
58
- wmi.ExecQuery(query).each { |nic|
57
+ Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
59
58
  domain = nic.DNSDomain
60
59
  break
61
60
  }
@@ -11,6 +11,6 @@
11
11
  #
12
12
 
13
13
  Facter.add(:hardwareisa) do
14
- setcode 'uname -p', '/bin/sh'
15
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS GNU/kFreeBSD}
14
+ setcode 'uname -p'
15
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OracleLinux OVS GNU/kFreeBSD}
16
16
  end
@@ -14,25 +14,20 @@
14
14
  Facter.add(:hostname, :ldapname => "cn") do
15
15
  setcode do
16
16
  hostname = nil
17
- name = Facter::Util::Resolution.exec('hostname') or nil
18
- if name
19
- if name =~ /^([\w-]+)\.(.+)$/
17
+ if name = Facter::Util::Resolution.exec('hostname')
18
+ if name =~ /(.*?)\./
20
19
  hostname = $1
21
- # the Domain class uses this
22
- $domain = $2
23
20
  else
24
21
  hostname = name
25
22
  end
26
- hostname
27
- else
28
- nil
29
23
  end
24
+ hostname
30
25
  end
31
26
  end
32
27
 
33
28
  Facter.add(:hostname) do
34
29
  confine :kernel => :darwin, :kernelrelease => "R7"
35
30
  setcode do
36
- %x{/usr/sbin/scutil --get LocalHostName}
31
+ Facter::Util::Resolution.exec('/usr/sbin/scutil --get LocalHostName')
37
32
  end
38
33
  end
@@ -61,3 +61,12 @@ Facter.add(:ipaddress6) do
61
61
  get_address_after_token(output, 'inet6', true)
62
62
  end
63
63
  end
64
+
65
+ Facter.add(:ipaddress6) do
66
+ confine :kernel => :windows
67
+ setcode do
68
+ output = Facter::Util::Resolution.exec("#{ENV['SYSTEMROOT']}/system32/netsh interface ipv6 show address level=verbose")
69
+
70
+ get_address_after_token(output, 'Address', true)
71
+ end
72
+ end
@@ -11,9 +11,9 @@
11
11
 
12
12
  Facter.add(:kernel) do
13
13
  setcode do
14
- require 'rbconfig'
15
- case Config::CONFIG['host_os']
16
- when /mswin|win32|dos|cygwin|mingw/i
14
+ require 'facter/util/config'
15
+
16
+ if Facter::Util::Config.is_windows?
17
17
  'windows'
18
18
  else
19
19
  Facter::Util::Resolution.exec("uname -s")
@@ -23,11 +23,9 @@ end
23
23
  Facter.add(:kernelrelease) do
24
24
  confine :kernel => %{windows}
25
25
  setcode do
26
- require 'win32ole'
26
+ require 'facter/util/wmi'
27
27
  version = ""
28
- connection_string = "winmgmts://./root/cimv2"
29
- wmi = WIN32OLE.connect(connection_string)
30
- wmi.ExecQuery("SELECT Version from Win32_OperatingSystem").each do |ole|
28
+ Facter::Util::WMI.execquery("SELECT Version from Win32_OperatingSystem").each do |ole|
31
29
  version = "#{ole.Version}"
32
30
  break
33
31
  end
@@ -15,7 +15,7 @@
15
15
  require 'facter'
16
16
 
17
17
  Facter.add("lsbmajdistrelease") do
18
- confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS GNU/kFreeBSD}
18
+ confine :operatingsystem => %w{Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo OEL OracleLinux OVS GNU/kFreeBSD}
19
19
  setcode do
20
20
  if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
21
21
  result=$1
@@ -10,14 +10,14 @@
10
10
  require 'facter/util/macaddress'
11
11
 
12
12
  Facter.add(:macaddress) do
13
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS GNU/kFreeBSD}
13
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Gentoo Ubuntu OEL OracleLinux OVS GNU/kFreeBSD}
14
14
  setcode do
15
15
  ether = []
16
- output = %x{/sbin/ifconfig -a}
16
+ output = Facter::Util::Resolution.exec("/sbin/ifconfig -a")
17
17
  output.each_line do |s|
18
18
  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})/
19
19
  end
20
- ether[0]
20
+ Facter::Util::Macaddress.standardize(ether[0])
21
21
  end
22
22
  end
23
23
 
@@ -29,7 +29,7 @@ Facter.add(:macaddress) do
29
29
  output.each_line do |s|
30
30
  ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/
31
31
  end
32
- ether[0]
32
+ Facter::Util::Macaddress.standardize(ether[0])
33
33
  end
34
34
  end
35
35
 
@@ -37,13 +37,13 @@ Facter.add(:macaddress) do
37
37
  confine :operatingsystem => %w{FreeBSD OpenBSD}
38
38
  setcode do
39
39
  ether = []
40
- output = %x{/sbin/ifconfig}
40
+ output = Facter::Util::Resolution.exec("/sbin/ifconfig")
41
41
  output.each_line do |s|
42
42
  if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
43
43
  ether.push($1)
44
44
  end
45
45
  end
46
- ether[0]
46
+ Facter::Util::Macaddress.standardize(ether[0])
47
47
  end
48
48
  end
49
49
 
@@ -71,33 +71,13 @@ Facter.add(:macaddress) do
71
71
  end
72
72
  end
73
73
  end
74
- ether[0]
74
+ Facter::Util::Macaddress.standardize(ether[0])
75
75
  end
76
76
  end
77
77
 
78
78
  Facter.add(:macaddress) do
79
- confine :kernel => %w(windows)
80
- setcode do
81
- require 'win32ole'
82
- require 'socket'
83
-
84
- ether = nil
85
- host = Socket.gethostname
86
- connect_string = "winmgmts://#{host}/root/cimv2"
87
-
88
- wmi = WIN32OLE.connect(connect_string)
89
-
90
- query = %Q{
91
- select *
92
- from Win32_NetworkAdapterConfiguration
93
- where IPEnabled = True
94
- }
95
-
96
- wmi.ExecQuery(query).each{ |nic|
97
- ether = nic.MacAddress
98
- break
99
- }
100
-
101
- ether
102
- end
79
+ confine :kernel => %w(windows)
80
+ setcode do
81
+ Facter::Util::Macaddress::Windows.macaddress
82
+ end
103
83
  end
@@ -25,6 +25,11 @@ if Facter.value(:kernel) == "OpenBSD"
25
25
  'hw.serialno' => 'serialnumber'
26
26
  }
27
27
 
28
+ Facter::Manufacturer.sysctl_find_system_info(mfg_keys)
29
+ elsif Facter.value(:kernel) == "Darwin"
30
+ mfg_keys = {
31
+ 'hw.model' => 'productname'
32
+ }
28
33
  Facter::Manufacturer.sysctl_find_system_info(mfg_keys)
29
34
  elsif Facter.value(:kernel) == "SunOS" and Facter.value(:hardwareisa) == "sparc"
30
35
  Facter::Manufacturer.prtdiag_sparc_find_system_info()
@@ -70,7 +70,7 @@ end
70
70
  if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root"
71
71
  swap = Facter::Util::Resolution.exec('swap -l')
72
72
  swapfree, swaptotal = 0, 0
73
- swap.each do |dev|
73
+ swap.each_line do |dev|
74
74
  if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/
75
75
  swaptotal += $1.to_i
76
76
  swapfree += $2.to_i
@@ -95,7 +95,7 @@ end
95
95
  if Facter.value(:kernel) == "OpenBSD"
96
96
  swap = Facter::Util::Resolution.exec('swapctl -l | sed 1d')
97
97
  swapfree, swaptotal = 0, 0
98
- swap.each do |dev|
98
+ swap.each_line do |dev|
99
99
  if dev =~ /^\S+\s+(\S+)\s+\S+\s+(\S+)\s+.*$/
100
100
  swaptotal += $1.to_i
101
101
  swapfree += $2.to_i
@@ -167,7 +167,7 @@ end
167
167
  if Facter.value(:kernel) == "SunOS"
168
168
  swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l')
169
169
  swapfree, swaptotal = 0, 0
170
- swap.each do |dev|
170
+ swap.each_line do |dev|
171
171
  if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/
172
172
  swaptotal += $1.to_i / 2
173
173
  swapfree += $2.to_i / 2
@@ -191,7 +191,7 @@ if Facter.value(:kernel) == "SunOS"
191
191
  # Total memory size available from prtconf
192
192
  pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf')
193
193
  phymem = ""
194
- pconf.each do |line|
194
+ pconf.each_line do |line|
195
195
  if line =~ /^Memory size:\s+(\d+) Megabytes/
196
196
  phymem = $1
197
197
  end
@@ -206,3 +206,31 @@ if Facter.value(:kernel) == "SunOS"
206
206
 
207
207
  Facter::Memory.vmstat_find_free_memory()
208
208
  end
209
+
210
+ if Facter.value(:kernel) == "windows"
211
+ require 'facter/util/wmi'
212
+
213
+ Facter.add("MemoryFree") do
214
+ confine :kernel => :windows
215
+ setcode do
216
+ mem = 0
217
+ Facter::Util::WMI.execquery("select FreePhysicalMemory from Win32_OperatingSystem").each do |os|
218
+ mem = os.FreePhysicalMemory
219
+ break
220
+ end
221
+ Facter::Memory.scale_number(mem.to_f, "kB")
222
+ end
223
+ end
224
+
225
+ Facter.add("MemoryTotal") do
226
+ confine :kernel => :windows
227
+ setcode do
228
+ mem = 0
229
+ Facter::Util::WMI.execquery("select TotalPhysicalMemory from Win32_ComputerSystem").each do |comp|
230
+ mem = comp.TotalPhysicalMemory
231
+ break
232
+ end
233
+ Facter::Memory.scale_number(mem.to_f, "")
234
+ end
235
+ end
236
+ end
@@ -37,6 +37,8 @@ Facter.add(:operatingsystem) do
37
37
  "MeeGo"
38
38
  elsif FileTest.exists?("/etc/arch-release")
39
39
  "Archlinux"
40
+ elsif FileTest.exists?("/etc/oracle-release")
41
+ "OracleLinux"
40
42
  elsif FileTest.exists?("/etc/enterprise-release")
41
43
  if FileTest.exists?("/etc/ovs-release")
42
44
  "OVS"
@@ -51,6 +53,8 @@ Facter.add(:operatingsystem) do
51
53
  txt = File.read("/etc/redhat-release")
52
54
  if txt =~ /centos/i
53
55
  "CentOS"
56
+ elsif txt =~ /CERN/
57
+ "SLC"
54
58
  elsif txt =~ /scientific/i
55
59
  "Scientific"
56
60
  else
@@ -73,6 +77,8 @@ Facter.add(:operatingsystem) do
73
77
  "Slamd64"
74
78
  elsif FileTest.exists?("/etc/slackware-version")
75
79
  "Slackware"
80
+ elsif FileTest.exists?("/etc/alpine-release")
81
+ "Alpine"
76
82
  end
77
83
  end
78
84
  end
@@ -16,15 +16,17 @@
16
16
  #
17
17
 
18
18
  Facter.add(:operatingsystemrelease) do
19
- confine :operatingsystem => %w{CentOS Fedora oel ovs RedHat MeeGo}
19
+ confine :operatingsystem => %w{CentOS Fedora oel ovs OracleLinux RedHat MeeGo Scientific SLC}
20
20
  setcode do
21
21
  case Facter.value(:operatingsystem)
22
- when "CentOS", "RedHat"
22
+ when "CentOS", "RedHat", "Scientific", "SLC"
23
23
  releasefile = "/etc/redhat-release"
24
24
  when "Fedora"
25
25
  releasefile = "/etc/fedora-release"
26
26
  when "MeeGo"
27
27
  releasefile = "/etc/meego-release"
28
+ when "OracleLinux"
29
+ releasefile = "/etc/oracle-release"
28
30
  when "OEL", "oel"
29
31
  releasefile = "/etc/enterprise-release"
30
32
  when "OVS", "ovs"
@@ -122,6 +124,13 @@ Facter.add(:operatingsystemrelease) do
122
124
  end
123
125
  end
124
126
 
127
+ Facter.add(:operatingsystemrelease) do
128
+ confine :operatingsystem => :Alpine
129
+ setcode do
130
+ File.read('/etc/alpine-release')
131
+ end
132
+ end
133
+
125
134
  Facter.add(:operatingsystemrelease) do
126
135
  setcode do Facter[:kernelrelease].value end
127
136
  end
@@ -54,3 +54,11 @@ Facter.add('physicalprocessorcount') do
54
54
  end
55
55
  end
56
56
  end
57
+
58
+ Facter.add('physicalprocessorcount') do
59
+ confine :kernel => :windows
60
+ setcode do
61
+ require 'facter/util/wmi'
62
+ Facter::Util::WMI.execquery("select Name from Win32_Processor").Count
63
+ end
64
+ end