facter 1.7.6 → 2.0.1.rc1
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.
- checksums.yaml +7 -0
- data/COMMITTERS.md +194 -0
- data/CONTRIBUTING.md +63 -235
- data/Gemfile +12 -8
- data/README.md +1 -2
- data/Rakefile +1 -1
- data/bin/facter +0 -4
- data/ext/build_defaults.yaml +2 -2
- data/ext/project_data.yaml +18 -0
- data/install.rb +1 -16
- data/lib/facter.rb +171 -171
- data/lib/facter/application.rb +65 -54
- data/lib/facter/core/aggregate.rb +220 -0
- data/lib/facter/core/directed_graph.rb +46 -0
- data/lib/facter/core/execution.rb +100 -0
- data/lib/facter/core/execution/base.rb +73 -0
- data/lib/facter/core/execution/posix.rb +50 -0
- data/lib/facter/core/execution/windows.rb +57 -0
- data/lib/facter/core/logging.rb +169 -0
- data/lib/facter/core/resolvable.rb +94 -0
- data/lib/facter/core/suitable.rb +117 -0
- data/lib/facter/domain.rb +15 -9
- data/lib/facter/filesystems.rb +1 -1
- data/lib/facter/hardwaremodel.rb +1 -1
- data/lib/facter/hostname.rb +3 -3
- data/lib/facter/interfaces.rb +6 -1
- data/lib/facter/ipaddress.rb +2 -2
- data/lib/facter/kernel.rb +1 -1
- data/lib/facter/kernelrelease.rb +1 -1
- data/lib/facter/ldom.rb +1 -1
- data/lib/facter/lsbdistcodename.rb +1 -1
- data/lib/facter/lsbdistdescription.rb +1 -1
- data/lib/facter/lsbdistid.rb +1 -1
- data/lib/facter/lsbdistrelease.rb +1 -1
- data/lib/facter/lsbrelease.rb +1 -1
- data/lib/facter/macaddress.rb +1 -14
- data/lib/facter/macosx.rb +2 -2
- data/lib/facter/memory.rb +8 -19
- data/lib/facter/operatingsystem.rb +1 -1
- data/lib/facter/operatingsystemrelease.rb +34 -1
- data/lib/facter/physicalprocessorcount.rb +6 -6
- data/lib/facter/processor.rb +11 -10
- data/lib/facter/selinux.rb +4 -15
- data/lib/facter/ssh.rb +5 -2
- data/lib/facter/util/architecture.rb +2 -2
- data/lib/facter/util/collection.rb +42 -38
- data/lib/facter/util/config.rb +19 -9
- data/lib/facter/util/confine.rb +34 -4
- data/lib/facter/util/ec2.rb +1 -1
- data/lib/facter/util/fact.rb +108 -36
- data/lib/facter/util/file_read.rb +7 -6
- data/lib/facter/util/formatter.rb +38 -0
- data/lib/facter/util/ip.rb +3 -3
- data/lib/facter/util/loader.rb +62 -42
- data/lib/facter/util/macosx.rb +7 -8
- data/lib/facter/util/manufacturer.rb +3 -3
- data/lib/facter/util/memory.rb +13 -13
- data/lib/facter/util/monkey_patches.rb +0 -31
- data/lib/facter/util/netmask.rb +3 -3
- data/lib/facter/util/normalization.rb +94 -0
- data/lib/facter/util/nothing_loader.rb +3 -6
- data/lib/facter/util/parser.rb +3 -5
- data/lib/facter/util/plist/generator.rb +1 -1
- data/lib/facter/util/processor.rb +15 -15
- data/lib/facter/util/resolution.rb +112 -289
- data/lib/facter/util/solaris_zones.rb +4 -4
- data/lib/facter/util/uptime.rb +8 -3
- data/lib/facter/util/values.rb +67 -1
- data/lib/facter/util/virtual.rb +10 -10
- data/lib/facter/util/xendomains.rb +1 -1
- data/lib/facter/version.rb +42 -39
- data/lib/facter/virtual.rb +6 -7
- data/lib/facter/zfs_version.rb +3 -3
- data/lib/facter/zpool_version.rb +3 -3
- data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
- data/spec/unit/application_spec.rb +46 -1
- data/spec/unit/core/aggregate_spec.rb +125 -0
- data/spec/unit/core/directed_graph_spec.rb +79 -0
- data/spec/unit/core/execution/base_spec.rb +119 -0
- data/spec/unit/core/execution/posix_spec.rb +86 -0
- data/spec/unit/core/execution/windows_spec.rb +106 -0
- data/spec/unit/core/execution_spec.rb +37 -0
- data/spec/unit/core/logging_spec.rb +104 -0
- data/spec/unit/core/resolvable_spec.rb +81 -0
- data/spec/unit/core/suitable_spec.rb +96 -0
- data/spec/unit/domain_spec.rb +5 -5
- data/spec/unit/facter_spec.rb +61 -222
- data/spec/unit/filesystems_spec.rb +2 -2
- data/spec/unit/hardwareisa_spec.rb +5 -5
- data/spec/unit/hardwaremodel_spec.rb +1 -1
- data/spec/unit/hostname_spec.rb +4 -4
- data/spec/unit/id_spec.rb +3 -3
- data/spec/unit/interfaces_spec.rb +10 -0
- data/spec/unit/ipaddress6_spec.rb +4 -4
- data/spec/unit/ipaddress_spec.rb +1 -1
- data/spec/unit/kernel_spec.rb +2 -2
- data/spec/unit/kernelmajversion_spec.rb +1 -1
- data/spec/unit/kernelrelease_spec.rb +4 -4
- data/spec/unit/kernelversion_spec.rb +2 -2
- data/spec/unit/ldom_spec.rb +2 -2
- data/spec/unit/lsbdistcodename_spec.rb +2 -2
- data/spec/unit/lsbdistdescription_spec.rb +2 -2
- data/spec/unit/lsbdistid_spec.rb +2 -2
- data/spec/unit/lsbdistrelease_spec.rb +2 -2
- data/spec/unit/lsbrelease_spec.rb +2 -2
- data/spec/unit/manufacturer_spec.rb +1 -1
- data/spec/unit/memory_spec.rb +24 -31
- data/spec/unit/netmask_spec.rb +9 -0
- data/spec/unit/operatingsystem_spec.rb +1 -1
- data/spec/unit/operatingsystemrelease_spec.rb +62 -4
- data/spec/unit/physicalprocessorcount_spec.rb +10 -10
- data/spec/unit/processor_spec.rb +11 -11
- data/spec/unit/selinux_spec.rb +2 -8
- data/spec/unit/ssh_spec.rb +3 -2
- data/spec/unit/uniqueid_spec.rb +3 -3
- data/spec/unit/util/collection_spec.rb +37 -35
- data/spec/unit/util/config_spec.rb +20 -0
- data/spec/unit/util/confine_spec.rb +21 -0
- data/spec/unit/util/directory_loader_spec.rb +1 -0
- data/spec/unit/util/ec2_spec.rb +6 -6
- data/spec/unit/util/fact_spec.rb +92 -90
- data/spec/unit/util/ip_spec.rb +2 -2
- data/spec/unit/util/loader_spec.rb +127 -186
- data/spec/unit/util/macaddress_spec.rb +2 -2
- data/spec/unit/util/macosx_spec.rb +8 -8
- data/spec/unit/util/manufacturer_spec.rb +3 -3
- data/spec/unit/util/normalization_spec.rb +113 -0
- data/spec/unit/util/parser_spec.rb +25 -3
- data/spec/unit/util/processor_spec.rb +2 -2
- data/spec/unit/util/resolution_spec.rb +60 -631
- data/spec/unit/util/solaris_zones_spec.rb +5 -5
- data/spec/unit/util/uptime_spec.rb +1 -1
- data/spec/unit/util/values_spec.rb +131 -0
- data/spec/unit/util/virtual_spec.rb +16 -16
- data/spec/unit/util/xendomains_spec.rb +2 -2
- data/spec/unit/virtual_spec.rb +39 -39
- data/spec/unit/zfs_version_spec.rb +11 -11
- data/spec/unit/zonename_spec.rb +2 -2
- data/spec/unit/zones_spec.rb +1 -1
- data/spec/unit/zpool_version_spec.rb +11 -11
- metadata +466 -447
- data/lib/facter/util/cfpropertylist.rb +0 -6
- data/lib/facter/util/cfpropertylist/LICENSE +0 -19
- data/lib/facter/util/cfpropertylist/README +0 -44
- data/lib/facter/util/cfpropertylist/Rakefile +0 -44
- data/lib/facter/util/cfpropertylist/THANKS +0 -7
- data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
- data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
- data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
- data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
- data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
- data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
- data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
- data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
- data/spec/unit/util/monkey_patches_spec.rb +0 -42
@@ -93,7 +93,7 @@ module Util
|
|
93
93
|
#
|
94
94
|
# @return [Hash] the parsed output of the zoneadm command
|
95
95
|
def refresh
|
96
|
-
@zoneadm_output = Facter::
|
96
|
+
@zoneadm_output = Facter::Core::Execution.exec(zoneadm_cmd)
|
97
97
|
parse!
|
98
98
|
end
|
99
99
|
|
@@ -103,11 +103,11 @@ module Util
|
|
103
103
|
#
|
104
104
|
# @api private
|
105
105
|
def parse!
|
106
|
-
if @zoneadm_output
|
107
|
-
rows = @zoneadm_output.split("\n").collect { |line| line.split(':') }
|
108
|
-
else
|
106
|
+
if @zoneadm_output.empty?
|
109
107
|
Facter.debug "Cannot parse zone facts, #{zoneadm_cmd} returned no output"
|
110
108
|
rows = []
|
109
|
+
else
|
110
|
+
rows = @zoneadm_output.split("\n").collect { |line| line.split(':') }
|
111
111
|
end
|
112
112
|
|
113
113
|
@zone_hash = rows.inject({}) do |memo, fields|
|
data/lib/facter/util/uptime.rb
CHANGED
@@ -20,19 +20,24 @@ module Facter::Util::Uptime
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def self.uptime_proc_uptime
|
23
|
-
|
23
|
+
output = Facter::Core::Execution.exec("/bin/cat #{uptime_file} 2>/dev/null")
|
24
|
+
|
25
|
+
if not output.empty?
|
24
26
|
output.chomp.split(" ").first.to_i
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
def self.uptime_sysctl
|
29
|
-
|
31
|
+
output = Facter::Core::Execution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
|
32
|
+
if not output.empty?
|
30
33
|
compute_uptime(Time.at(output.match(/\d+/)[0].to_i))
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
34
37
|
def self.uptime_executable
|
35
|
-
|
38
|
+
output = Facter::Core::Execution.exec("#{uptime_executable_cmd} 2>/dev/null")
|
39
|
+
|
40
|
+
if not output.empty?
|
36
41
|
up=0
|
37
42
|
if output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+):(\d+)/
|
38
43
|
# Regexp handles Solaris, AIX, HP-UX, and Tru64.
|
data/lib/facter/util/values.rb
CHANGED
@@ -1,9 +1,75 @@
|
|
1
|
-
# A util module for facter containing helper methods
|
2
1
|
module Facter
|
3
2
|
module Util
|
3
|
+
# A util module for facter containing helper methods
|
4
4
|
module Values
|
5
5
|
module_function
|
6
6
|
|
7
|
+
class DeepFreezeError < StandardError; end
|
8
|
+
|
9
|
+
# Duplicate and deeply freeze a given data structure
|
10
|
+
#
|
11
|
+
# @param value [Object] The structure to freeze
|
12
|
+
# @return [void]
|
13
|
+
def deep_freeze(value)
|
14
|
+
case value
|
15
|
+
when Numeric, Symbol, TrueClass, FalseClass, NilClass
|
16
|
+
# These are immutable values, we can safely ignore them
|
17
|
+
value
|
18
|
+
when String
|
19
|
+
value.dup.freeze
|
20
|
+
when Array
|
21
|
+
value.map do |entry|
|
22
|
+
deep_freeze(entry)
|
23
|
+
end.freeze
|
24
|
+
when Hash
|
25
|
+
value.inject({}) do |hash, (key, value)|
|
26
|
+
hash[deep_freeze(key)] = deep_freeze(value)
|
27
|
+
hash
|
28
|
+
end.freeze
|
29
|
+
else
|
30
|
+
raise DeepFreezeError, "Cannot deep freeze #{value}:#{value.class}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class DeepMergeError < StandardError; end
|
35
|
+
|
36
|
+
# Perform a deep merge of two nested data structures.
|
37
|
+
#
|
38
|
+
# @param left [Object]
|
39
|
+
# @param right [Object]
|
40
|
+
# @param path [Array<String>] The traversal path followed when merging nested hashes
|
41
|
+
#
|
42
|
+
# @return [Object] The merged data structure.
|
43
|
+
def deep_merge(left, right, path = [], &block)
|
44
|
+
ret = nil
|
45
|
+
|
46
|
+
if left.is_a? Hash and right.is_a? Hash
|
47
|
+
ret = left.merge(right) do |key, left_val, right_val|
|
48
|
+
path.push(key)
|
49
|
+
merged = deep_merge(left_val, right_val, path)
|
50
|
+
path.pop
|
51
|
+
merged
|
52
|
+
end
|
53
|
+
elsif left.is_a? Array and right.is_a? Array
|
54
|
+
ret = left.dup.concat(right)
|
55
|
+
elsif right.nil?
|
56
|
+
ret = left
|
57
|
+
elsif left.nil?
|
58
|
+
ret = right
|
59
|
+
elsif left.nil? and right.nil?
|
60
|
+
ret = nil
|
61
|
+
else
|
62
|
+
msg = "Cannot merge #{left.inspect}:#{left.class} and #{right.inspect}:#{right.class}"
|
63
|
+
if not path.empty?
|
64
|
+
msg << " at root"
|
65
|
+
msg << path.map { |part| "[#{part.inspect}]" }.join
|
66
|
+
end
|
67
|
+
raise DeepMergeError, msg
|
68
|
+
end
|
69
|
+
|
70
|
+
ret
|
71
|
+
end
|
72
|
+
|
7
73
|
def convert(value)
|
8
74
|
value = value.to_s if value.is_a?(Symbol)
|
9
75
|
value = value.downcase if value.is_a?(String)
|
data/lib/facter/util/virtual.rb
CHANGED
@@ -4,7 +4,7 @@ module Facter::Util::Virtual
|
|
4
4
|
##
|
5
5
|
# virt_what is a delegating helper method intended to make it easier to stub
|
6
6
|
# the system call without affecting other calls to
|
7
|
-
# Facter::
|
7
|
+
# Facter::Core::Execution.exec
|
8
8
|
#
|
9
9
|
# Per https://bugzilla.redhat.com/show_bug.cgi?id=719611 when run as a
|
10
10
|
# non-root user the virt-what command may emit an error message on stdout,
|
@@ -12,7 +12,7 @@ module Facter::Util::Virtual
|
|
12
12
|
# method ensures stderr is redirected and that error messages are stripped
|
13
13
|
# from stdout.
|
14
14
|
def self.virt_what(command = "virt-what")
|
15
|
-
command = Facter::
|
15
|
+
command = Facter::Core::Execution.which(command)
|
16
16
|
return unless command
|
17
17
|
|
18
18
|
if Facter.value(:kernel) == 'windows'
|
@@ -20,15 +20,15 @@ module Facter::Util::Virtual
|
|
20
20
|
else
|
21
21
|
redirected_cmd = "#{command} 2>/dev/null"
|
22
22
|
end
|
23
|
-
output = Facter::
|
23
|
+
output = Facter::Core::Execution.exec redirected_cmd
|
24
24
|
output.gsub(/^virt-what: .*$/, '') if output
|
25
25
|
end
|
26
26
|
|
27
27
|
##
|
28
28
|
# lspci is a delegating helper method intended to make it easier to stub the
|
29
|
-
# system call without affecting other calls to Facter::
|
29
|
+
# system call without affecting other calls to Facter::Core::Execution.exec
|
30
30
|
def self.lspci(command = "lspci 2>/dev/null")
|
31
|
-
Facter::
|
31
|
+
Facter::Core::Execution.exec command
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.openvz?
|
@@ -40,7 +40,7 @@ module Facter::Util::Virtual
|
|
40
40
|
return false unless self.openvz?
|
41
41
|
return false unless FileTest.exists?( '/proc/self/status' )
|
42
42
|
|
43
|
-
envid = Facter::
|
43
|
+
envid = Facter::Core::Execution.exec( 'grep "envID" /proc/self/status' )
|
44
44
|
if envid =~ /^envID:\s+0$/i
|
45
45
|
return 'openvzhn'
|
46
46
|
elsif envid =~ /^envID:\s+(\d+)$/i
|
@@ -56,7 +56,7 @@ module Facter::Util::Virtual
|
|
56
56
|
|
57
57
|
def self.zone?
|
58
58
|
return true if FileTest.directory?("/.SUNWnative")
|
59
|
-
z = Facter::
|
59
|
+
z = Facter::Core::Execution.exec("/sbin/zonename")
|
60
60
|
return false unless z
|
61
61
|
return z.chomp != 'global'
|
62
62
|
end
|
@@ -92,7 +92,7 @@ module Facter::Util::Virtual
|
|
92
92
|
txt = if FileTest.exists?("/proc/cpuinfo")
|
93
93
|
File.read("/proc/cpuinfo")
|
94
94
|
elsif ["FreeBSD", "OpenBSD"].include? Facter.value(:kernel)
|
95
|
-
Facter::
|
95
|
+
Facter::Core::Execution.exec("/sbin/sysctl -n hw.model")
|
96
96
|
end
|
97
97
|
(txt =~ /QEMU Virtual CPU/) ? true : false
|
98
98
|
end
|
@@ -123,11 +123,11 @@ module Facter::Util::Virtual
|
|
123
123
|
when "FreeBSD" then "/sbin"
|
124
124
|
when "GNU/kFreeBSD" then "/bin"
|
125
125
|
end
|
126
|
-
Facter::
|
126
|
+
Facter::Core::Execution.exec("#{path}/sysctl -n security.jail.jailed") == "1"
|
127
127
|
end
|
128
128
|
|
129
129
|
def self.hpvm?
|
130
|
-
Facter::
|
130
|
+
Facter::Core::Execution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/
|
131
131
|
end
|
132
132
|
|
133
133
|
def self.zlinux?
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
module Facter::Util::Xendomains
|
4
4
|
def self.get_domains
|
5
|
-
if xm_list = Facter::
|
5
|
+
if xm_list = Facter::Core::Execution.exec('/usr/sbin/xm list 2>/dev/null')
|
6
6
|
domains = xm_list.split("\n").reject { |line| line =~ /^(Name|Domain-0)/ }
|
7
7
|
domains.map { |line| line.split(/\s/)[0] }.join(',')
|
8
8
|
end
|
data/lib/facter/version.rb
CHANGED
@@ -1,54 +1,53 @@
|
|
1
1
|
module Facter
|
2
2
|
if not defined? FACTERVERSION then
|
3
|
-
FACTERVERSION = '
|
3
|
+
FACTERVERSION = '2.0.1-rc1'
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
# version is a public API method intended to always provide a fast and
|
8
|
-
# lightweight way to determine the version of Facter.
|
6
|
+
# Returns the running version of Facter.
|
9
7
|
#
|
10
|
-
# The intent is that software external to Facter be able to
|
11
|
-
# Facter version with no side-effects. The expected
|
8
|
+
# @comment The intent is that software external to Facter be able to
|
9
|
+
# determine the Facter version with no side-effects. The expected
|
10
|
+
# use is:
|
12
11
|
#
|
13
12
|
# require 'facter/version'
|
14
13
|
# version = Facter.version
|
15
14
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
15
|
+
# This function has the following ordering precedence. This precedence list
|
16
|
+
# is designed to facilitate automated packaging tasks by simply writing to
|
17
|
+
# the VERSION file in the same directory as this source file.
|
19
18
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
19
|
+
# 1. If a version has been explicitly assigned using the Facter.version=
|
20
|
+
# method, return that version.
|
21
|
+
# 2. If there is a VERSION file, read the contents, trim any
|
22
|
+
# trailing whitespace, and return that version string.
|
23
|
+
# 3. Return the value of the Facter::FACTERVERSION constant hard-coded into
|
24
|
+
# the source code.
|
26
25
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
26
|
+
# If there is no VERSION file, the method must return the version string of
|
27
|
+
# the nearest parent version that is an officially released version. That is
|
28
|
+
# to say, if a branch named 3.1.x contains 25 patches on top of the most
|
29
|
+
# recent official release of 3.1.1, then the version method must return the
|
30
|
+
# string "3.1.1" if no "VERSION" file is present.
|
32
31
|
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
32
|
+
# By design the version identifier is _not_ intended to vary during the life of
|
33
|
+
# a process. There is no guarantee provided that writing to the VERSION file
|
34
|
+
# while a Puppet process is running will cause the version string to be
|
35
|
+
# updated. On the contrary, the contents of the VERSION are cached to reduce
|
36
|
+
# filesystem accesses.
|
38
37
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
38
|
+
# The VERSION file is intended to be used by package maintainers who may be
|
39
|
+
# applying patches or otherwise changing the software version in a manner
|
40
|
+
# that warrants a different software version identifier. The VERSION file is
|
41
|
+
# intended to be managed and owned by the release process and packaging
|
42
|
+
# related tasks, and as such should not reside in version control. The
|
43
|
+
# FACTERVERSION constant is intended to be version controlled in history.
|
45
44
|
#
|
46
|
-
#
|
47
|
-
#
|
45
|
+
# Ideally, this behavior will allow package maintainers to precisely specify
|
46
|
+
# the version of the software they're packaging as in the following example:
|
48
47
|
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
48
|
+
# $ git describe > lib/facter/VERSION
|
49
|
+
# $ ruby -r facter -e 'puts Facter.version'
|
50
|
+
# 1.6.14-6-g66f2c99
|
52
51
|
#
|
53
52
|
# @api public
|
54
53
|
#
|
@@ -62,17 +61,21 @@ module Facter
|
|
62
61
|
@facter_version ||= FACTERVERSION
|
63
62
|
end
|
64
63
|
|
64
|
+
# Sets the Facter version
|
65
|
+
#
|
66
|
+
# @return [void]
|
67
|
+
#
|
68
|
+
# @api private
|
65
69
|
def self.version=(version)
|
66
70
|
@facter_version = version
|
67
71
|
end
|
68
72
|
|
69
|
-
|
70
|
-
# read_version_file reads the content of the "VERSION" file that lives in the
|
73
|
+
# This reads the content of the "VERSION" file that lives in the
|
71
74
|
# same directory as this source code file.
|
72
75
|
#
|
73
76
|
# @api private
|
74
77
|
#
|
75
|
-
# @return [String] for example: "1.6.14-6-gea42046" or nil if the VERSION
|
78
|
+
# @return [String] the version -- for example: "1.6.14-6-gea42046" or nil if the VERSION
|
76
79
|
# file does not exist.
|
77
80
|
def self.read_version_file(path)
|
78
81
|
if File.exists?(path)
|
data/lib/facter/virtual.rb
CHANGED
@@ -55,13 +55,12 @@ end
|
|
55
55
|
Facter.add("virtual") do
|
56
56
|
confine :kernel => 'SunOS'
|
57
57
|
has_weight 10
|
58
|
+
self.timeout = 6
|
59
|
+
|
58
60
|
setcode do
|
59
61
|
next "zone" if Facter::Util::Virtual.zone?
|
60
62
|
|
61
|
-
|
62
|
-
resolver.timeout = 6
|
63
|
-
resolver.setcode('prtdiag')
|
64
|
-
output = resolver.value
|
63
|
+
output = Facter::Core::Execution.exec('prtdiag')
|
65
64
|
if output
|
66
65
|
lines = output.split("\n")
|
67
66
|
next "parallels" if lines.any? {|l| l =~ /Parallels/ }
|
@@ -92,7 +91,7 @@ Facter.add("virtual") do
|
|
92
91
|
confine :kernel => 'OpenBSD'
|
93
92
|
has_weight 10
|
94
93
|
setcode do
|
95
|
-
output = Facter::
|
94
|
+
output = Facter::Core::Execution.exec('sysctl -n hw.product 2>/dev/null')
|
96
95
|
if output
|
97
96
|
lines = output.split("\n")
|
98
97
|
next "parallels" if lines.any? {|l| l =~ /Parallels/ }
|
@@ -133,7 +132,7 @@ Facter.add("virtual") do
|
|
133
132
|
end
|
134
133
|
|
135
134
|
# Parse dmidecode
|
136
|
-
output = Facter::
|
135
|
+
output = Facter::Core::Execution.exec('dmidecode 2> /dev/null')
|
137
136
|
if output
|
138
137
|
lines = output.split("\n")
|
139
138
|
next "parallels" if lines.any? {|l| l =~ /Parallels/ }
|
@@ -146,7 +145,7 @@ Facter.add("virtual") do
|
|
146
145
|
end
|
147
146
|
|
148
147
|
# Sample output of vmware -v `VMware Server 1.0.5 build-80187`
|
149
|
-
output = Facter::
|
148
|
+
output = Facter::Core::Execution.exec("vmware -v")
|
150
149
|
if output
|
151
150
|
mdata = output.match /(\S+)\s+(\S+)/
|
152
151
|
next "#{mdata[1]}_#{mdata[2]}".downcase if mdata
|
data/lib/facter/zfs_version.rb
CHANGED
@@ -2,9 +2,9 @@ require 'facter'
|
|
2
2
|
|
3
3
|
Facter.add('zfs_version') do
|
4
4
|
setcode do
|
5
|
-
if Facter::
|
6
|
-
zfs_v = Facter::
|
7
|
-
zfs_version = zfs_v.scan(/^\s+(\d+)\s+/m).flatten.last unless zfs_v.
|
5
|
+
if Facter::Core::Execution.which('zfs')
|
6
|
+
zfs_v = Facter::Core::Execution.exec('zfs upgrade -v')
|
7
|
+
zfs_version = zfs_v.scan(/^\s+(\d+)\s+/m).flatten.last unless zfs_v.empty?
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/lib/facter/zpool_version.rb
CHANGED
@@ -2,9 +2,9 @@ require 'facter'
|
|
2
2
|
|
3
3
|
Facter.add('zpool_version') do
|
4
4
|
setcode do
|
5
|
-
if Facter::
|
6
|
-
zpool_v = Facter::
|
7
|
-
zpool_version = zpool_v.match(/ZFS pool version (\d+)./).captures.first unless zpool_v.
|
5
|
+
if Facter::Core::Execution.which('zpool')
|
6
|
+
zpool_v = Facter::Core::Execution.exec('zpool upgrade -v')
|
7
|
+
zpool_version = zpool_v.match(/ZFS pool version (\d+)./).captures.first unless zpool_v.empty?
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
|
2
|
+
options=3<RXCSUM,TXCSUM>
|
3
|
+
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
|
4
|
+
inet 127.0.0.1 netmask 0xff000000
|
5
|
+
inet6 ::1 prefixlen 128
|
6
|
+
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
|
7
|
+
stf0: flags=0<> mtu 1280
|
8
|
+
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
|
9
|
+
ether 28:cf:e9:1a:8a:2d
|
10
|
+
inet6 fe80::2acf:e9ff:fe1a:8a2d%en0 prefixlen 64 scopeid 0x5
|
11
|
+
inet 10.16.141.17 netmask 0xfffffc00 broadcast 10.16.143.255
|
12
|
+
media: autoselect
|
13
|
+
status: active
|
14
|
+
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
|
15
|
+
ether 0a:cf:e9:1a:8a:2d
|
16
|
+
media: autoselect
|
17
|
+
status: inactive
|
18
|
+
vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
|
19
|
+
ether 00:50:56:c0:00:01
|
20
|
+
inet 192.168.51.1 netmask 0xffffff00 broadcast 192.168.51.255
|
21
|
+
vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
|
22
|
+
ether 00:50:56:c0:00:08
|
23
|
+
inet 172.16.138.1 netmask 0xffffff00 broadcast 172.16.138.255
|
24
|
+
en3: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
|
25
|
+
options=4<VLAN_MTU>
|
26
|
+
ether 70:11:24:8c:33:df
|
27
|
+
inet6 fe80::7211:24ff:fe8c:33df%en3 prefixlen 64 scopeid 0x7
|
28
|
+
inet 10.16.16.205 netmask 0xfffffc00 broadcast 10.16.19.255
|
29
|
+
media: autoselect (100baseTX <full-duplex>)
|
30
|
+
status: active
|
@@ -8,7 +8,7 @@ describe Facter::Application do
|
|
8
8
|
Facter::Application.parse(['architecture', 'kernel']).should == {}
|
9
9
|
end
|
10
10
|
|
11
|
-
[:yaml, :json
|
11
|
+
[:yaml, :json].each do |option_key|
|
12
12
|
it "sets options[:#{option_key}] when given --#{option_key}" do
|
13
13
|
options = Facter::Application.parse(["--#{option_key}"])
|
14
14
|
options[option_key].should be_true
|
@@ -31,6 +31,13 @@ describe Facter::Application do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
it "enables tracing when given --trace" do
|
35
|
+
Facter.trace(false)
|
36
|
+
Facter::Application.parse(['--trace'])
|
37
|
+
Facter.should be_trace
|
38
|
+
Facter.trace(false)
|
39
|
+
end
|
40
|
+
|
34
41
|
['-t', '--timing'].each do |option|
|
35
42
|
it "enables timing when given #{option}" do
|
36
43
|
Facter.timing(false)
|
@@ -52,5 +59,43 @@ describe Facter::Application do
|
|
52
59
|
Facter::Application.parse(argv)
|
53
60
|
argv.should == ['uptime', 'virtual']
|
54
61
|
end
|
62
|
+
|
63
|
+
after(:all) do
|
64
|
+
Facter.debugging(false)
|
65
|
+
Facter.timing(false)
|
66
|
+
Facter.trace(false)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "formatting facts" do
|
71
|
+
before do
|
72
|
+
Facter.stubs(:to_hash)
|
73
|
+
Facter.stubs(:value)
|
74
|
+
Facter::Application.stubs(:puts)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "delegates YAML formatting" do
|
78
|
+
Facter::Util::Formatter.expects(:format_yaml)
|
79
|
+
Facter::Application.stubs(:exit).with(0)
|
80
|
+
Facter::Application.run(['--yaml'])
|
81
|
+
end
|
82
|
+
|
83
|
+
it "delegates JSON formatting", :if => Facter.json? do
|
84
|
+
Facter::Util::Formatter.expects(:format_json)
|
85
|
+
Facter::Application.stubs(:exit).with(0)
|
86
|
+
Facter::Application.run(['--json'])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "delegates plaintext formatting" do
|
90
|
+
Facter::Util::Formatter.expects(:format_plaintext)
|
91
|
+
Facter::Application.stubs(:exit).with(0)
|
92
|
+
Facter::Application.run(['--plaintext'])
|
93
|
+
end
|
94
|
+
|
95
|
+
it "defaults to plaintext" do
|
96
|
+
Facter::Util::Formatter.expects(:format_plaintext)
|
97
|
+
Facter::Application.stubs(:exit).with(0)
|
98
|
+
Facter::Application.run([])
|
99
|
+
end
|
55
100
|
end
|
56
101
|
end
|