facter 2.3.0-universal-darwin → 2.4.0-universal-darwin

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.

@@ -187,7 +187,7 @@ OPTIONS
187
187
 
188
188
  def self.load_puppet
189
189
  require 'puppet'
190
- Puppet.parse_config
190
+ Puppet.initialize_settings
191
191
 
192
192
  # If you've set 'vardir' but not 'libdir' in your
193
193
  # puppet.conf, then the hook to add libdir to $:
@@ -21,6 +21,22 @@ module Facter::Core::Logging
21
21
  # @api private
22
22
  @@debug_messages = {}
23
23
 
24
+ # @api private
25
+ @@message_callback = nil
26
+
27
+ # Used to register a callback that is called when a message is logged.
28
+ # If a block is given, Facter will not log messages.
29
+ # If a block is not given, Facter will resume logging messages.
30
+ # @param block [Proc] the callback to call when a message is logged.
31
+ # The first argument to the callback will be a symbol representing a level. The supported
32
+ # levels are: :trace, :debug, :info, :warn, :error, and :fatal.
33
+ # The second argument to the callback will be a string containing the message
34
+ # that was logged.
35
+ # @api public
36
+ def on_message(&block)
37
+ @@message_callback = block
38
+ end
39
+
24
40
  # Prints a debug message if debugging is turned on
25
41
  #
26
42
  # @param msg [String] the debug message
@@ -30,6 +46,8 @@ module Facter::Core::Logging
30
46
  if msg.nil? or msg.empty?
31
47
  invoker = caller[0].slice(/.*:\d+/)
32
48
  self.warn "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}"
49
+ elsif @@message_callback
50
+ @@message_callback.call(:debug, msg)
33
51
  else
34
52
  puts GREEN + msg + RESET
35
53
  end
@@ -59,7 +77,10 @@ module Facter::Core::Logging
59
77
  def warn(msg)
60
78
  if msg.nil? or msg.empty?
61
79
  invoker = caller[0].slice(/.*:\d+/)
62
- Kernel.warn "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}"
80
+ msg = "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}"
81
+ end
82
+ if @@message_callback
83
+ @@message_callback.call(:warn, msg)
63
84
  else
64
85
  Kernel.warn msg
65
86
  end
@@ -111,7 +132,13 @@ module Facter::Core::Logging
111
132
  #
112
133
  # @api private
113
134
  def show_time(string)
114
- $stderr.puts "#{GREEN}#{string}#{RESET}" if string and self.timing?
135
+ return unless string && self.timing?
136
+
137
+ if @@message_callback
138
+ @@message_callback.call(:info, string)
139
+ else
140
+ $stderr.puts "#{GREEN}#{string}#{RESET}"
141
+ end
115
142
  end
116
143
 
117
144
  # Enable or disable logging of debug messages
@@ -158,12 +185,13 @@ module Facter::Core::Logging
158
185
  @@trace
159
186
  end
160
187
 
161
- # Clears the seen state of warning messages. See {warnonce}.
188
+ # Clears the seen state of debug and warning messages. See {debugonce} and {warnonce}.
162
189
  #
163
190
  # @return [void]
164
191
  #
165
192
  # @api private
166
193
  def clear_messages
194
+ @@debug_messages.clear
167
195
  @@warn_messages.clear
168
196
  end
169
197
  end
@@ -5,6 +5,8 @@
5
5
  # If the interface that is the default gateway is DHCP assigned, there
6
6
  # will also be a `"system"` entry in the hash.
7
7
  #
8
+ # This fact is structured. Values are returned as a group of key-value pairs.
9
+ #
8
10
  # Resolution:
9
11
  # Parses the output of `nmcli` to find the DHCP server for the interface if available.
10
12
  #
@@ -21,6 +23,9 @@ Facter.add(:dhcp_servers) do
21
23
  confine do
22
24
  Facter::Core::Execution.which('nmcli')
23
25
  end
26
+ confine do
27
+ Facter::Util::DHCPServers.network_manager_state != 'unknown'
28
+ end
24
29
 
25
30
  setcode do
26
31
  gwdev = Facter::Util::DHCPServers.gateway_device
@@ -1,9 +1,16 @@
1
1
  # Fact: interfaces
2
2
  #
3
3
  # Purpose:
4
- # Generates the following facts on supported platforms: `<interface>_ipaddress`,
5
- # `<interface>_ipaddress6`, `<interface>_macaddress`, `<interface>_netmask`,
6
- # and `<interface>_mtu`.
4
+ # Returns a comma-separated list of the system's network interfaces.
5
+ #
6
+ # In addition to the main `interfaces` fact, this code will generate the
7
+ # following facts for each interface:
8
+ #
9
+ # * `ipaddress_<INTERFACE>`
10
+ # * `ipaddress6_<INTERFACE>`
11
+ # * `macaddress_<INTERFACE>`
12
+ # * `netmask_<INTERFACE>`
13
+ # * `mtu_<INTERFACE>`
7
14
  #
8
15
  # Resolution:
9
16
  #
@@ -49,7 +49,7 @@ Facter.add(:ipaddress) do
49
49
  ip = nil
50
50
  output = Facter::Util::IP.exec_ifconfig
51
51
 
52
- output.split(/^\S/).each { |str|
52
+ output.split(/^\S/).each do |str|
53
53
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
54
54
  tmp = $1
55
55
  unless tmp =~ /^127\./
@@ -57,7 +57,7 @@ Facter.add(:ipaddress) do
57
57
  break
58
58
  end
59
59
  end
60
- }
60
+ end
61
61
 
62
62
  ip
63
63
  end
@@ -69,7 +69,7 @@ Facter.add(:ipaddress) do
69
69
  ip = nil
70
70
  output = Facter::Util::IP.exec_ifconfig(["-a"])
71
71
 
72
- output.split(/^\S/).each { |str|
72
+ output.split(/^\S/).each do |str|
73
73
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
74
74
  tmp = $1
75
75
  unless tmp =~ /^127\./ or tmp == "0.0.0.0"
@@ -77,7 +77,7 @@ Facter.add(:ipaddress) do
77
77
  break
78
78
  end
79
79
  end
80
- }
80
+ end
81
81
 
82
82
  ip
83
83
  end
@@ -87,17 +87,15 @@ Facter.add(:ipaddress) do
87
87
  confine :kernel => %w{AIX}
88
88
  setcode do
89
89
  ip = nil
90
- output = Facter::Util::IP.exec_ifconfig(["-a"])
91
90
 
92
- output.split(/^\S/).each { |str|
91
+ default_interface = Facter::Util::IP.exec_netstat(["-rn | grep default | awk '{ print $6 }'"])
92
+ output = Facter::Util::IP.exec_ifconfig([default_interface])
93
+
94
+ output.split(/^\S/).each do |str|
93
95
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
94
- tmp = $1
95
- unless tmp =~ /^127\./
96
- ip = tmp
97
- break
98
- end
96
+ ip = $1
99
97
  end
100
- }
98
+ end
101
99
 
102
100
  ip
103
101
  end
@@ -72,7 +72,8 @@ Facter.add(:macaddress) do
72
72
  setcode do
73
73
  ether = []
74
74
  ip = nil
75
- output = Facter::Util::IP.exec_ifconfig(["-a"])
75
+ default_interface = Facter::Util::IP.exec_netstat(["-rn | grep default | awk '{ print $6 }'"])
76
+ output = Facter::Util::IP.exec_ifconfig([default_interface])
76
77
  output.each_line do |str|
77
78
  if str =~ /([a-z]+\d+): flags=/
78
79
  devname = $1
@@ -3,11 +3,14 @@
3
3
  # Purpose: Returns the major release of the operating system.
4
4
  #
5
5
  # Resolution:
6
- # Uses the releasemajor key of the os structured fact, which itself
7
- # splits down its operatingsystemrelease key at decimal point for
8
- # osfamily RedHat derivatives and Debian.
9
- # Uses operatingsystemrelease key to the first non decimal
10
- # character for operatingsystem Solaris.
6
+ # Uses the release['major'] entry of the os structured fact, which itself
7
+ # attempts to use its own release['full'] entry to determine the major release value.
8
+ # In RedHat osfamily derivatives and Debian, splits down the release string for a decimal point
9
+ # and uses the first non-decimal character.
10
+ # In Solaris, uses the first non-decimal character of the release string.
11
+ # In Ubuntu, uses the characters before and after the first decimal point, as in '14.04'.
12
+ # In Windows, uses the full release string in the case of server releases, such as '2012 R2',
13
+ # and uses the first non-decimal character in the cases of releases such as '8.1'.
11
14
  #
12
15
  # This should be the same as lsbmajdistrelease, but on minimal systems there
13
16
  # are too many dependencies to use LSB
@@ -16,7 +19,7 @@
16
19
  # "Alpine" "Amazon" "Archlinux" "Ascendos" "Bluewhite64" "CentOS" "CloudLinux"
17
20
  # "Debian" "Fedora" "Gentoo" "Mandrake" "Mandriva" "MeeGo" "OEL" "OpenSuSE"
18
21
  # "OracleLinux" "OVS" "PSBM" "RedHat" "Scientific" "Slackware" "Slamd64" "SLC"
19
- # "SLED" "SLES" "SuSE" "Ubuntu" "VMWareESX"
22
+ # "SLED" "SLES" "Solaris" "SuSE" "Ubuntu" "VMWareESX"
20
23
  #
21
24
 
22
25
  Facter.add(:operatingsystemmajrelease) do
data/lib/facter/os.rb CHANGED
@@ -1,29 +1,58 @@
1
1
  # Fact: os
2
2
  #
3
3
  # Purpose:
4
- # Return various facts related to the machine's operating system.
4
+ # Return various facts related to the machine's operating system, including:
5
+ # Name: The name of the operating system.
6
+ # Family: A mapping of the operating system to an operating system family.
7
+ # Release: The release version of the operating system. Includes entries for the
8
+ # major and minor release versions, as well as the full release string.
9
+ # Lsb: Linux Standard Base information for the system.
10
+ #
11
+ # This fact is structured. These values are returned as a group of key-value pairs.
5
12
  #
6
13
  # Resolution:
7
- # For operatingsystem, if the kernel is a Linux kernel, check for the
8
- # existence of a selection of files in `/etc` to find the specific flavor.
14
+ # For the name entry, if the kernel is a Linux kernel, check for the existence of a
15
+ # selection of files in `/etc` to find the specific flavor.
9
16
  # On SunOS based kernels, attempt to determine the flavor, otherwise return Solaris.
10
17
  # On systems other than Linux, use the kernel value.
11
18
  #
12
- # For operatingsystemrelease, on RedHat derivatives, we return their `/etc/<varient>-release` file.
19
+ # For the family entry, map operating systems to operating system families, such
20
+ # as linux distribution derivatives. Adds mappings from specific operating systems
21
+ # to kernels in the case that it is relevant.
22
+ #
23
+ # For the release entry, on RedHat derivatives, returns `/etc/<variant>-release` file.
13
24
  # On Debian, returns `/etc/debian_version`.
14
25
  # On Ubuntu, parses `/etc/lsb-release` for the release version
15
- # On Suse and derivatives, parses `/etc/SuSE-release` for a selection of version information.
26
+ # On Suse and derivatives, parses `/etc/SuSE-release` for a selection of version
27
+ # information.
16
28
  # On Slackware, parses `/etc/slackware-version`.
17
29
  # On Amazon Linux, returns the lsbdistrelease fact's value.
18
30
  # On Mageia, parses `/etc/mageia-release` for the release version.
19
31
  # On all remaining systems, returns the kernelrelease fact's value.
20
32
  #
21
- # For the lsb facts, uses the `lsb_release` system command.
33
+ # For the major version, uses the value of the full release string to determine the major
34
+ # release version.
35
+ # In RedHat osfamily derivatives and Debian, splits down the release string for a decimal point
36
+ # and uses the first non-decimal character.
37
+ # In Solaris, uses the first non-decimal character of the release string.
38
+ # In Ubuntu, uses the characters before and after the first decimal point, as in '14.04'.
39
+ # In Windows, uses the full release string in the case of server releases, such as '2012 R2',
40
+ # and uses the first non-decimal character in the cases of releases such as '8.1'.
41
+ #
42
+ # For the minor version, attempts to split the full release version string and return
43
+ # the value of the character after the first decimal.
44
+ #
45
+ # For the lsb entries, uses the `lsb_release` system command.
22
46
  #
23
47
  # Caveats:
24
- # Lsb facts only work on Linux (and the kfreebsd derivative) systems.
25
- # Requires the `lsb_release` program, which may not be installed by default.
26
- # It is only as accurate as the ourput of lsb_release.
48
+ # The family entry is completely reliant on the name key, and no heuristics are used.
49
+ #
50
+ # The major and minor release sub-facts of the release entry are not currenty
51
+ # supported on all platforms.
52
+ #
53
+ # The lsb entries only work on Linux (and the kfreebsd derivative) systems. Requires
54
+ # the `lsb_release` program, which may not be installed by default. It is only as
55
+ # accurate as the output of `lsb_release`.
27
56
  #
28
57
 
29
58
  require 'facter/operatingsystem/implementation'
@@ -3,6 +3,8 @@
3
3
  # Purpose:
4
4
  # Return the details of the disk partitions.
5
5
  #
6
+ # This fact is structured. Values are returned as a group of key-value pairs.
7
+ #
6
8
  # Resolution:
7
9
  # Parse the contents of `/sys/block/<device>/size` to receive the size (multiplying by 512 to correct for blocks-to-bytes).
8
10
  #
@@ -27,6 +29,7 @@ Facter.add(:partitions) do
27
29
  details['uuid'] = Facter::Util::Partitions.uuid(part)
28
30
  details['size'] = Facter::Util::Partitions.size(part)
29
31
  details['mount'] = Facter::Util::Partitions.mount(part)
32
+ details['label'] = Facter::Util::Partitions.label(part)
30
33
  details['filesystem'] = Facter::Util::Partitions.filesystem(part)
31
34
  details.reject! {|k,v| v.nil? || v.to_s.empty? }
32
35
  partitions[part] = details
@@ -1,18 +1,24 @@
1
1
  # Fact: processors
2
2
  #
3
3
  # Purpose:
4
- # Additional facts about the machine's CPU's, including
5
- # processor lists, models, counts, and speeds.
4
+ # Provide additional facts about the machine's CPUs, including:
5
+ # Models: A list of processors present on the system.
6
+ # Count: The number of hardware threads.
7
+ # Physicalcount: The number of physical processors.
8
+ # Speed: The speed of the processors on the system.
9
+ #
10
+ # This fact is structured. These values are returned as a group of key-value pairs.
6
11
  #
7
12
  # Resolution:
8
- # Each kernel utilizes its own implementation object to collect
9
- # processor data. Linux and kFreeBSD parse `/proc/cpuinfo` for each
10
- # processor. AIX parses the output of `lsdev` for its processor section.
11
- # For Solaris, we parse the output of `kstat` for each processor. OpenBSD uses
12
- # the sysctl variables 'hw.model' and 'hw.ncpu' for the CPU model and
13
- # the CPU count respectively. Darwin utilizes the system profiler to collect
14
- # the physical CPU count and speed.
13
+ # Linux and kFreeBSD parse `/proc/cpuinfo` for each processor.
14
+ # AIX parses the output of `lsdev` for its processor section.
15
+ # Solaris parses the output of `kstat` for each processor.
16
+ # OpenBSD uses the sysctl variables `hw.model` and `hw.ncpu` for the CPU model
17
+ # and the CPU count respectively.
18
+ # Darwin utilizes the system profiler to collect the physical CPU count and speed.
15
19
  #
20
+ # Caveats:
21
+ # The 'speed' sub-fact is not currently supported on all platforms.
16
22
 
17
23
  require 'facter/processors/os'
18
24
 
@@ -12,7 +12,7 @@
12
12
  Facter.add(:system32) do
13
13
  confine :kernel => :windows
14
14
  setcode do
15
- if File.exists?("#{ENV['SYSTEMROOT']}\\sysnative")
15
+ if File.exist?("#{ENV['SYSTEMROOT']}\\sysnative")
16
16
  "#{ENV['SYSTEMROOT']}\\sysnative"
17
17
  else
18
18
  "#{ENV['SYSTEMROOT']}\\system32"
@@ -5,6 +5,8 @@
5
5
  # seconds, hours, days and a general, human
6
6
  # readable uptime.
7
7
  #
8
+ # This fact is structured. These values are returned as a group of key-value pairs.
9
+ #
8
10
  # Resolution:
9
11
  # Does basic math on the get_uptime_seconds utility
10
12
  # to calculate seconds, hours and days.
@@ -41,7 +41,11 @@ module Facter::Util::Config
41
41
  if Facter::Util::Root.root?
42
42
  windows_dir = windows_data_dir
43
43
  if windows_dir.nil? then
44
- @external_facts_dirs = ["/etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"]
44
+ # Note: Beginning with Facter 3, /opt/puppetlabs/agent/facts.d will be the only
45
+ # default external fact directory.
46
+ @external_facts_dirs = ["/opt/puppetlabs/agent/facts.d",
47
+ "/etc/facter/facts.d",
48
+ "/etc/puppetlabs/facter/facts.d"]
45
49
  else
46
50
  @external_facts_dirs = [File.join(windows_dir, 'PuppetLabs', 'facter', 'facts.d')]
47
51
  end
@@ -25,9 +25,8 @@ module Facter::Util::DHCPServers
25
25
 
26
26
  def self.device_dhcp_server(device)
27
27
  if Facter::Core::Execution.which('nmcli')
28
- version = self.nmcli_version
29
28
  # If the version is >= 0.9.9, use show instead of list
30
- if version && version[0] > 0 || version[1] > 9 || (version[1] == 9 && version[2] >= 9)
29
+ if is_newer_nmcli?
31
30
  Facter::Core::Execution.exec("nmcli -f all d show #{device}").scan(/dhcp_server_identifier.*?(\d+\.\d+\.\d+\.\d+)$/).flatten.first
32
31
  else
33
32
  Facter::Core::Execution.exec("nmcli -f all d list iface #{device}").scan(/dhcp_server_identifier.*?(\d+\.\d+\.\d+\.\d+)$/).flatten.first
@@ -35,9 +34,25 @@ module Facter::Util::DHCPServers
35
34
  end
36
35
  end
37
36
 
37
+ def self.network_manager_state
38
+ # If the version is >= 0.9.9, use g instead of nm
39
+ if is_newer_nmcli?
40
+ output = Facter::Core::Execution.exec('nmcli -t -f STATE g 2>/dev/null')
41
+ else
42
+ output = Facter::Core::Execution.exec('nmcli -t -f STATE nm 2>/dev/null')
43
+ end
44
+ return nil unless output
45
+ output.strip
46
+ end
47
+
38
48
  def self.nmcli_version
39
49
  if version = Facter::Core::Execution.exec("nmcli --version")
40
50
  version.scan(/version\s(\d+)\.?(\d+)?\.?(\d+)?\.?(\d+)?/).flatten.map(&:to_i)
41
51
  end
42
52
  end
53
+
54
+ def self.is_newer_nmcli?
55
+ version = nmcli_version
56
+ version && (version[0] > 0 || version[1] > 9 || (version[1] == 9 && version[2] >= 9))
57
+ end
43
58
  end
@@ -1,7 +1,10 @@
1
1
  # A Facter plugin that loads external facts.
2
2
  #
3
3
  # Default Unix Directories:
4
- # /etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"
4
+ # /opt/puppetlabs/agent/facts.d, /etc/facter/facts.d, /etc/puppetlabs/facter/facts.d
5
+ #
6
+ # Beginning with Facter 3, only /opt/puppetlabs/agent/facts.d will be a default external fact
7
+ # directory in Unix.
5
8
  #
6
9
  # Default Windows Direcotires:
7
10
  # C:\ProgramData\Puppetlabs\facter\facts.d (2008)
@@ -30,8 +33,9 @@ class Facter::Util::DirectoryLoader
30
33
  # Directory for fact loading
31
34
  attr_reader :directory
32
35
 
33
- def initialize(dir)
36
+ def initialize(dir, weight = nil)
34
37
  @directory = dir
38
+ @weight = weight || EXTERNAL_FACT_WEIGHT
35
39
  end
36
40
 
37
41
  def self.loader_for(dir)
@@ -52,6 +56,7 @@ class Facter::Util::DirectoryLoader
52
56
  # Load facts from files in fact directory using the relevant parser classes to
53
57
  # parse them.
54
58
  def load(collection)
59
+ weight = @weight
55
60
  entries.each do |file|
56
61
  parser = Facter::Util::Parser.parser_for(file)
57
62
  if parser == nil
@@ -64,7 +69,7 @@ class Facter::Util::DirectoryLoader
64
69
  elsif data == {} or data == nil
65
70
  Facter.warn "Fact file #{file} was parsed but returned an empty data set"
66
71
  else
67
- data.each { |p,v| collection.add(p, :value => v) { has_weight(EXTERNAL_FACT_WEIGHT) } }
72
+ data.each { |p,v| collection.add(p, :value => v) { has_weight(weight) } }
68
73
  end
69
74
  end
70
75
  end