facter 1.5.8 → 1.5.9
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.
- data/CHANGELOG +94 -0
- data/INSTALL +1 -1
- data/README +1 -1
- data/README.rst +3 -3
- data/Rakefile +9 -6
- data/bin/facter +18 -123
- data/conf/redhat/facter.spec +21 -3
- data/conf/solaris/pkginfo +2 -2
- data/install.rb +18 -10
- data/lib/facter.rb +27 -1
- data/lib/facter/application.rb +123 -0
- data/lib/facter/arp.rb +28 -0
- data/lib/facter/ec2.rb +32 -11
- data/lib/facter/hardwareisa.rb +1 -1
- data/lib/facter/id.rb +2 -9
- data/lib/facter/interfaces.rb +1 -1
- data/lib/facter/ipaddress.rb +2 -33
- data/lib/facter/ipaddress6.rb +68 -0
- data/lib/facter/lsb.rb +5 -5
- data/lib/facter/lsbmajdistrelease.rb +1 -1
- data/lib/facter/macaddress.rb +4 -14
- data/lib/facter/manufacturer.rb +9 -0
- data/lib/facter/memory.rb +110 -6
- data/lib/facter/netmask.rb +1 -1
- data/lib/facter/operatingsystem.rb +17 -2
- data/lib/facter/operatingsystemrelease.rb +34 -0
- data/lib/facter/processor.rb +8 -5
- data/lib/facter/selinux.rb +37 -4
- data/lib/facter/uniqueid.rb +1 -1
- data/lib/facter/util/#uptime.rb# +64 -0
- data/lib/facter/util/ip.rb +23 -15
- data/lib/facter/util/loader.rb +2 -2
- data/lib/facter/util/macaddress.rb +28 -0
- data/lib/facter/util/manufacturer.rb +39 -2
- data/lib/facter/util/memory.rb +43 -0
- data/lib/facter/util/netmask.rb +1 -1
- data/lib/facter/util/resolution.rb +7 -0
- data/lib/facter/util/uptime.rb +11 -1
- data/lib/facter/util/virtual.rb +13 -2
- data/lib/facter/util/vlans.rb +2 -2
- data/lib/facter/util/xendomains.rb +10 -0
- data/lib/facter/virtual.rb +45 -13
- data/lib/facter/xendomains.rb +10 -0
- data/spec/fixtures/ifconfig/bsd_ifconfig_all_with_multiple_interfaces +18 -0
- data/spec/fixtures/ifconfig/centos_5_5 +17 -0
- data/spec/fixtures/ifconfig/centos_5_5_eth0 +8 -0
- data/spec/fixtures/ifconfig/darwin_10_3_0 +26 -0
- data/spec/fixtures/ifconfig/darwin_10_3_0_en0 +6 -0
- data/spec/fixtures/ifconfig/darwin_10_6_4 +28 -0
- data/spec/fixtures/ifconfig/darwin_10_6_4_en1 +6 -0
- data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack +8 -0
- data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack_en1 +7 -0
- data/spec/fixtures/ifconfig/darwin_9_8_0 +26 -0
- data/spec/fixtures/ifconfig/darwin_9_8_0_en0 +6 -0
- data/spec/fixtures/ifconfig/darwin_ifconfig_all_with_multiple_interfaces +23 -0
- data/spec/fixtures/ifconfig/fedora_10 +36 -0
- data/spec/fixtures/ifconfig/fedora_10_eth0 +9 -0
- data/spec/fixtures/ifconfig/fedora_13 +18 -0
- data/spec/fixtures/ifconfig/fedora_13_eth0 +9 -0
- data/spec/fixtures/ifconfig/fedora_8 +38 -0
- data/spec/fixtures/ifconfig/fedora_8_eth0 +9 -0
- data/spec/fixtures/ifconfig/freebsd_6_0 +12 -0
- data/spec/fixtures/ifconfig/linux_ifconfig_all_with_multiple_interfaces +19 -0
- data/spec/fixtures/ifconfig/open_solaris_10 +12 -0
- data/spec/fixtures/ifconfig/open_solaris_b132 +20 -0
- data/spec/fixtures/ifconfig/sunos_ifconfig_all_with_multiple_interfaces +10 -0
- data/spec/fixtures/ifconfig/ubuntu_7_04 +38 -0
- data/spec/fixtures/ifconfig/ubuntu_7_04_eth0 +9 -0
- data/spec/fixtures/netstat/centos_5_5 +5 -0
- data/spec/fixtures/netstat/darwin_10_3_0 +35 -0
- data/spec/fixtures/netstat/darwin_10_6_4 +29 -0
- data/spec/fixtures/netstat/darwin_10_6_6_dualstack +34 -0
- data/spec/fixtures/netstat/darwin_9_8_0 +28 -0
- data/spec/fixtures/netstat/fedora_10 +7 -0
- data/spec/fixtures/netstat/open_solaris_10 +16 -0
- data/spec/fixtures/netstat/open_solaris_b132 +17 -0
- data/spec/fixtures/netstat/ubuntu_7_04 +7 -0
- data/spec/fixtures/uptime/kstat_boot_time +1 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_1/guest +37 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_1/host +36 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_3/guest +39 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_3/host +39 -0
- data/spec/integration/{facter.rb → facter_spec.rb} +1 -1
- data/spec/spec_helper.rb +8 -3
- data/spec/unit/data/debian_kfreebsd_ifconfig +40 -0
- data/spec/unit/data/hpux_netstat_all_interfaces +3 -6
- data/spec/unit/data/selinux_sestatus +6 -0
- data/spec/unit/data/xendomains +4 -0
- data/spec/unit/{facter.rb → facter_spec.rb} +28 -1
- data/spec/unit/id_spec.rb +27 -0
- data/spec/unit/{interfaces.rb → interfaces_spec.rb} +1 -1
- data/spec/unit/ipaddress6_spec.rb +36 -0
- data/spec/unit/memory_spec.rb +45 -0
- data/spec/unit/{operatingsystem.rb → operatingsystem_spec.rb} +22 -8
- data/spec/unit/operatingsystemrelease_spec.rb +49 -0
- data/spec/unit/selinux_spec.rb +89 -0
- data/spec/unit/{uptime.rb → uptime_spec.rb} +4 -4
- data/spec/unit/util/{collection.rb → collection_spec.rb} +1 -1
- data/spec/unit/util/{confine.rb → confine_spec.rb} +1 -1
- data/spec/unit/util/{fact.rb → fact_spec.rb} +1 -1
- data/spec/unit/util/{ip.rb → ip_spec.rb} +47 -12
- data/spec/unit/util/{loader.rb → loader_spec.rb} +51 -1
- data/spec/unit/util/macaddress_spec.rb +68 -0
- data/spec/unit/util/{macosx.rb → macosx_spec.rb} +1 -1
- data/spec/unit/util/{manufacturer.rb → manufacturer_spec.rb} +15 -4
- data/spec/unit/util/{resolution.rb → resolution_spec.rb} +1 -1
- data/spec/unit/util/uptime_spec.rb +73 -0
- data/spec/unit/util/{virtual.rb → virtual_spec.rb} +37 -3
- data/spec/unit/util/{vlans.rb → vlans_spec.rb} +1 -1
- data/spec/unit/util/xendomains_spec.rb +23 -0
- data/spec/unit/virtual_spec.rb +196 -0
- metadata +149 -98
- data/spec/Rakefile +0 -18
- data/spec/unit/data/hpux_ifconfig +0 -3
- data/spec/unit/data/hpux_netscan +0 -4
- data/spec/unit/operatingsystemrelease.rb +0 -39
- data/spec/unit/selinux.rb +0 -48
- data/spec/unit/util/uptime.rb +0 -53
- data/spec/unit/virtual.rb +0 -71
@@ -0,0 +1,123 @@
|
|
1
|
+
module Facter
|
2
|
+
module Application
|
3
|
+
def self.run(argv)
|
4
|
+
require 'optparse'
|
5
|
+
require 'facter'
|
6
|
+
|
7
|
+
options = parse(argv)
|
8
|
+
|
9
|
+
# Accept fact names to return from the command line
|
10
|
+
names = argv
|
11
|
+
|
12
|
+
# Create the facts hash that is printed to standard out.
|
13
|
+
# Pre-load all of the facts, since we can have multiple facts
|
14
|
+
# per file, and since we can't know ahead of time which file a
|
15
|
+
# fact will be in, we'll need to load every file.
|
16
|
+
facts = Facter.to_hash
|
17
|
+
unless names.empty?
|
18
|
+
facts = {}
|
19
|
+
names.each do |name|
|
20
|
+
begin
|
21
|
+
facts[name] = Facter.value(name)
|
22
|
+
rescue => error
|
23
|
+
$stderr.puts "Could not retrieve #{name}: #{error}"
|
24
|
+
exit 10
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Print the facts as YAML and exit
|
30
|
+
if options[:yaml]
|
31
|
+
require 'yaml'
|
32
|
+
puts YAML.dump(facts)
|
33
|
+
exit(0)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Print the facts as JSON and exit
|
37
|
+
if options[:json]
|
38
|
+
begin
|
39
|
+
require 'json'
|
40
|
+
puts JSON.dump(facts)
|
41
|
+
exit(0)
|
42
|
+
rescue LoadError
|
43
|
+
$stderr.puts "You do not have JSON support in your version of Ruby. JSON output disabled"
|
44
|
+
exit(1)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Print the value of a single fact, otherwise print a list sorted by fact
|
49
|
+
# name and separated by "=>"
|
50
|
+
if facts.length == 1
|
51
|
+
if value = facts.values.first
|
52
|
+
puts value
|
53
|
+
end
|
54
|
+
else
|
55
|
+
facts.sort_by{ |fact| fact.first }.each do |name,value|
|
56
|
+
puts "#{name} => #{value}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
rescue => e
|
61
|
+
if options && options[:trace]
|
62
|
+
raise e
|
63
|
+
else
|
64
|
+
$stderr.puts "Error: #{e}"
|
65
|
+
exit(12)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def self.parse(argv)
|
72
|
+
options = {}
|
73
|
+
OptionParser.new do |opts|
|
74
|
+
opts.on("-y", "--yaml") { |v| options[:yaml] = v }
|
75
|
+
opts.on("-j", "--json") { |v| options[:json] = v }
|
76
|
+
opts.on( "--trace") { |v| options[:trace] = v }
|
77
|
+
opts.on("-d", "--debug") { |v| Facter.debugging(1) }
|
78
|
+
opts.on("-t", "--timing") { |v| Facter.timing(1) }
|
79
|
+
opts.on("-p", "--puppet") { |v| load_puppet }
|
80
|
+
|
81
|
+
opts.on_tail("-v", "--version") do
|
82
|
+
puts Facter.version
|
83
|
+
exit(0)
|
84
|
+
end
|
85
|
+
|
86
|
+
opts.on_tail("-h", "--help") do
|
87
|
+
begin
|
88
|
+
require 'rdoc/ri/ri_paths'
|
89
|
+
require 'rdoc/usage'
|
90
|
+
RDoc.usage # print usage and exit
|
91
|
+
rescue LoadError
|
92
|
+
$stderr.puts "No help available unless your RDoc has RDoc.usage"
|
93
|
+
exit(1)
|
94
|
+
rescue => e
|
95
|
+
$stderr.puts "fatal: #{e}"
|
96
|
+
exit(1)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end.parse!
|
100
|
+
|
101
|
+
options
|
102
|
+
rescue OptionParser::InvalidOption => e
|
103
|
+
$stderr.puts e.message
|
104
|
+
exit(12)
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.load_puppet
|
108
|
+
require 'puppet'
|
109
|
+
Puppet.parse_config
|
110
|
+
|
111
|
+
# If you've set 'vardir' but not 'libdir' in your
|
112
|
+
# puppet.conf, then the hook to add libdir to $:
|
113
|
+
# won't get triggered. This makes sure that it's setup
|
114
|
+
# correctly.
|
115
|
+
unless $LOAD_PATH.include?(Puppet[:libdir])
|
116
|
+
$LOAD_PATH << Puppet[:libdir]
|
117
|
+
end
|
118
|
+
rescue LoadError => detail
|
119
|
+
$stderr.puts "Could not load Puppet: #{detail}"
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
data/lib/facter/arp.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'facter/util/ip'
|
2
|
+
|
3
|
+
Facter.add(:arp) do
|
4
|
+
confine :kernel => :linux
|
5
|
+
setcode do
|
6
|
+
output = Facter::Util::Resolution.exec('arp -a')
|
7
|
+
if not output.nil?
|
8
|
+
arp = ""
|
9
|
+
output.each_line do |s|
|
10
|
+
if s =~ /^\S+\s\S+\s\S+\s(\S+)\s\S+\s\S+\s\S+$/
|
11
|
+
arp = $1.downcase
|
12
|
+
break # stops on the first match
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
"fe:ff:ff:ff:ff:ff" == arp ? arp : nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Facter::Util::IP.get_interfaces.each do |interface|
|
21
|
+
Facter.add("arp_" + Facter::Util::IP.alphafy(interface)) do
|
22
|
+
confine :kernel => :linux
|
23
|
+
setcode do
|
24
|
+
arp = Facter::Util::IP.get_arp_value(interface)
|
25
|
+
"fe:ff:ff:ff:ff:ff" == arp ? arp : nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/facter/ec2.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Original fact Tim Dysinger
|
2
|
+
# Additional work from KurtBe
|
3
|
+
# Additional work for Paul Nasrat
|
4
|
+
# Additional work modelled on Ohai EC2 fact
|
4
5
|
|
5
6
|
require 'open-uri'
|
6
7
|
require 'timeout'
|
7
8
|
|
8
|
-
def can_connect?(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def can_connect?(wait_sec=2)
|
10
|
+
url = "http://169.254.169.254:80/"
|
11
|
+
Timeout::timeout(wait_sec) {open(url)}
|
12
|
+
return true
|
13
|
+
rescue Timeout::Error
|
14
|
+
return false
|
15
|
+
rescue
|
16
|
+
return false
|
13
17
|
end
|
14
18
|
|
15
|
-
|
16
19
|
def metadata(id = "")
|
17
20
|
open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read.
|
18
21
|
split("\n").each do |o|
|
@@ -29,7 +32,25 @@ def metadata(id = "")
|
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
|
-
|
33
|
-
|
35
|
+
def userdata()
|
36
|
+
begin
|
37
|
+
value = OpenURI.open_uri("http://169.254.169.254/2008-02-01/user-data/").read.split
|
38
|
+
Facter.add(:ec2_userdata) { setcode { value } }
|
39
|
+
rescue OpenURI::HTTPError
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def has_euca_mac?
|
44
|
+
!!(Facter.value(:macaddress) =~ %r{^[dD]0:0[dD]:})
|
34
45
|
end
|
35
46
|
|
47
|
+
def has_ec2_arp?
|
48
|
+
!!(Facter.value(:arp) == "fe:ff:ff:ff:ff:ff")
|
49
|
+
end
|
50
|
+
|
51
|
+
if (has_euca_mac? || has_ec2_arp?) && can_connect?
|
52
|
+
metadata
|
53
|
+
userdata
|
54
|
+
else
|
55
|
+
Facter.debug "Not an EC2 host"
|
56
|
+
end
|
data/lib/facter/hardwareisa.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
Facter.add(:hardwareisa) do
|
2
2
|
setcode 'uname -p', '/bin/sh'
|
3
|
-
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS}
|
3
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS GNU/kFreeBSD}
|
4
4
|
end
|
data/lib/facter/id.rb
CHANGED
@@ -1,15 +1,8 @@
|
|
1
1
|
Facter.add(:id) do
|
2
|
-
confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS}
|
3
2
|
setcode "whoami"
|
4
3
|
end
|
5
4
|
|
6
5
|
Facter.add(:id) do
|
7
|
-
confine :
|
8
|
-
setcode
|
9
|
-
if %x{id} =~ /^uid=\d+\((\S+)\)/
|
10
|
-
$1
|
11
|
-
else
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
end
|
6
|
+
confine :kernel => :SunOS
|
7
|
+
setcode "/usr/xpg4/bin/id -un"
|
15
8
|
end
|
data/lib/facter/interfaces.rb
CHANGED
@@ -22,7 +22,7 @@ Facter::Util::IP.get_interfaces.each do |interface|
|
|
22
22
|
# Make a fact for each detail of each interface. Yay.
|
23
23
|
# There's no point in confining these facts, since we wouldn't be able to create
|
24
24
|
# them if we weren't running on a supported platform.
|
25
|
-
%w{ipaddress macaddress netmask}.each do |label|
|
25
|
+
%w{ipaddress ipaddress6 macaddress netmask}.each do |label|
|
26
26
|
Facter.add(label + "_" + Facter::Util::IP.alphafy(interface)) do
|
27
27
|
setcode do
|
28
28
|
Facter::Util::IP.get_interface_value(interface, label)
|
data/lib/facter/ipaddress.rb
CHANGED
@@ -19,7 +19,7 @@ Facter.add(:ipaddress) do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
Facter.add(:ipaddress) do
|
22
|
-
confine :kernel => %w{FreeBSD OpenBSD}
|
22
|
+
confine :kernel => %w{FreeBSD OpenBSD Darwin}
|
23
23
|
setcode do
|
24
24
|
ip = nil
|
25
25
|
output = %x{/sbin/ifconfig}
|
@@ -47,38 +47,7 @@ Facter.add(:ipaddress) do
|
|
47
47
|
output.split(/^\S/).each { |str|
|
48
48
|
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
49
49
|
tmp = $1
|
50
|
-
unless tmp =~ /^127\./
|
51
|
-
ip = tmp
|
52
|
-
break
|
53
|
-
end
|
54
|
-
end
|
55
|
-
}
|
56
|
-
|
57
|
-
ip
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
Facter.add(:ipaddress) do
|
62
|
-
confine :kernel => %w{darwin}
|
63
|
-
setcode do
|
64
|
-
ip = nil
|
65
|
-
iface = ""
|
66
|
-
output = %x{/usr/sbin/netstat -rn}
|
67
|
-
if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/
|
68
|
-
iface = $1
|
69
|
-
else
|
70
|
-
warn "Could not find a default route. Using first non-loopback interface"
|
71
|
-
end
|
72
|
-
if(iface != "")
|
73
|
-
output = %x{/sbin/ifconfig #{iface}}
|
74
|
-
else
|
75
|
-
output = %x{/sbin/ifconfig}
|
76
|
-
end
|
77
|
-
|
78
|
-
output.split(/^\S/).each { |str|
|
79
|
-
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
80
|
-
tmp = $1
|
81
|
-
unless tmp =~ /^127\./
|
50
|
+
unless tmp =~ /^127\./ or tmp == "0.0.0.0"
|
82
51
|
ip = tmp
|
83
52
|
break
|
84
53
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Cody Herriges <c.a.herriges@gmail.com>
|
2
|
+
#
|
3
|
+
# Used the ipaddress fact that is already part of
|
4
|
+
# Facter as a template.
|
5
|
+
|
6
|
+
# OS dependant code that parses the output of various networking
|
7
|
+
# tools and currently not very intelligent. Returns the first
|
8
|
+
# non-loopback and non-linklocal address found in the ouput unless
|
9
|
+
# a default route can be mapped to a routeable interface. Guessing
|
10
|
+
# an interface is currently only possible with BSD type systems
|
11
|
+
# to many assumptions have to be made on other platforms to make
|
12
|
+
# this work with the current code. Most code ported or modeled
|
13
|
+
# after the ipaddress fact for the sake of similar functionality
|
14
|
+
# and familiar mechanics.
|
15
|
+
Facter.add(:ipaddress6) do
|
16
|
+
confine :kernel => :linux
|
17
|
+
setcode do
|
18
|
+
ip = nil
|
19
|
+
output = Facter::Util::Resolution.exec('/sbin/ifconfig')
|
20
|
+
|
21
|
+
output.scan(/inet6 addr: ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each { |str|
|
22
|
+
str = str.to_s
|
23
|
+
unless str =~ /fe80.*/ or str == "::1"
|
24
|
+
ip = str
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
ip
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Facter.add(:ipaddress6) do
|
34
|
+
confine :kernel => %w{SunOS}
|
35
|
+
setcode do
|
36
|
+
output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a')
|
37
|
+
ip = nil
|
38
|
+
|
39
|
+
output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{0,2})+[0-9,a-f,A-F]{0,4})/).each { |str|
|
40
|
+
str = str.to_s
|
41
|
+
unless str =~ /fe80.*/ or str == "::1"
|
42
|
+
ip = str
|
43
|
+
end
|
44
|
+
}
|
45
|
+
|
46
|
+
ip
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Facter.add(:ipaddress6) do
|
52
|
+
confine :kernel => %w{Darwin FreeBSD OpenBSD}
|
53
|
+
setcode do
|
54
|
+
output = Facter::Util::Resolution.exec('/sbin/ifconfig -a')
|
55
|
+
ip = nil
|
56
|
+
|
57
|
+
output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |str|
|
58
|
+
str = str.to_s
|
59
|
+
unless str =~ /fe80.*/ or str == "::1"
|
60
|
+
ip = str
|
61
|
+
break
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
ip
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/lib/facter/lsb.rb
CHANGED
@@ -20,15 +20,15 @@
|
|
20
20
|
"LSBDistCodeName" => %r{^Codename:\t(.*)$}
|
21
21
|
}.each do |fact, pattern|
|
22
22
|
Facter.add(fact) do
|
23
|
-
confine :kernel => :linux
|
23
|
+
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
24
24
|
setcode do
|
25
|
-
unless defined?(
|
25
|
+
unless defined?(lsbdata) and defined?(lsbtime) and (Time.now.to_i - lsbtime.to_i < 5)
|
26
26
|
type = nil
|
27
|
-
|
28
|
-
|
27
|
+
lsbtime = Time.now
|
28
|
+
lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
|
29
29
|
end
|
30
30
|
|
31
|
-
if pattern.match(
|
31
|
+
if pattern.match(lsbdata)
|
32
32
|
$1
|
33
33
|
else
|
34
34
|
nil
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'facter'
|
4
4
|
|
5
5
|
Facter.add("lsbmajdistrelease") do
|
6
|
-
confine :operatingsystem => %w{
|
6
|
+
confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS GNU/kFreeBSD}
|
7
7
|
setcode do
|
8
8
|
if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
|
9
9
|
result=$1
|
data/lib/facter/macaddress.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'facter/util/macaddress'
|
2
|
+
|
1
3
|
Facter.add(:macaddress) do
|
2
|
-
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS}
|
4
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS GNU/kFreeBSD}
|
3
5
|
setcode do
|
4
6
|
ether = []
|
5
7
|
output = %x{/sbin/ifconfig -a}
|
@@ -26,19 +28,7 @@ end
|
|
26
28
|
|
27
29
|
Facter.add(:macaddress) do
|
28
30
|
confine :kernel => :darwin
|
29
|
-
setcode
|
30
|
-
ether = nil
|
31
|
-
output = %x{/sbin/ifconfig}
|
32
|
-
|
33
|
-
output.split(/^\S/).each do |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
|
-
end
|
39
|
-
|
40
|
-
ether
|
41
|
-
end
|
31
|
+
setcode { Facter::Util::Macaddress::Darwin.macaddress }
|
42
32
|
end
|
43
33
|
|
44
34
|
Facter.add(:macaddress) do
|
data/lib/facter/manufacturer.rb
CHANGED
@@ -13,6 +13,15 @@ if Facter.value(:kernel) == "OpenBSD"
|
|
13
13
|
}
|
14
14
|
|
15
15
|
Facter::Manufacturer.sysctl_find_system_info(mfg_keys)
|
16
|
+
elsif Facter.value(:kernel) == "SunOS" and Facter.value(:hardwareisa) == "sparc"
|
17
|
+
Facter::Manufacturer.prtdiag_sparc_find_system_info()
|
18
|
+
elsif Facter.value(:kernel) == "windows"
|
19
|
+
win32_keys = {
|
20
|
+
'manufacturer' => ['Manufacturer', 'Bios'],
|
21
|
+
'serialNumber' => ['Serialnumber', 'Bios'],
|
22
|
+
'productname' => ['Name', 'ComputerSystemProduct']
|
23
|
+
}
|
24
|
+
Facter::Manufacturer.win32_find_system_info(win32_keys)
|
16
25
|
else
|
17
26
|
query = {
|
18
27
|
'[Ss]ystem [Ii]nformation' => [
|
data/lib/facter/memory.rb
CHANGED
@@ -13,13 +13,43 @@ require 'facter/util/memory'
|
|
13
13
|
:SwapFree => "SwapFree"
|
14
14
|
}.each do |fact, name|
|
15
15
|
Facter.add(fact) do
|
16
|
-
confine :kernel => :linux
|
16
|
+
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
17
17
|
setcode do
|
18
18
|
Facter::Memory.meminfo_number(name)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
Facter.add("SwapSize") do
|
24
|
+
confine :kernel => :Darwin
|
25
|
+
setcode do
|
26
|
+
swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
|
27
|
+
swaptotal = 0
|
28
|
+
if swap =~ /total = (\S+)/ then swaptotal = $1; end
|
29
|
+
swaptotal
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Facter.add("SwapFree") do
|
34
|
+
confine :kernel => :Darwin
|
35
|
+
setcode do
|
36
|
+
swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
|
37
|
+
swapfree = 0
|
38
|
+
if swap =~ /free = (\S+)/ then swapfree = $1; end
|
39
|
+
swapfree
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Facter.add("SwapEncrypted") do
|
44
|
+
confine :kernel => :Darwin
|
45
|
+
setcode do
|
46
|
+
swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
|
47
|
+
encrypted = false
|
48
|
+
if swap =~ /\(encrypted\)/ then encrypted = true; end
|
49
|
+
encrypted
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
23
53
|
if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root"
|
24
54
|
swap = Facter::Util::Resolution.exec('swap -l')
|
25
55
|
swapfree, swaptotal = 0, 0
|
@@ -69,19 +99,93 @@ if Facter.value(:kernel) == "OpenBSD"
|
|
69
99
|
end
|
70
100
|
end
|
71
101
|
|
72
|
-
Facter.
|
102
|
+
Facter::Memory.vmstat_find_free_memory()
|
103
|
+
|
104
|
+
Facter.add("MemoryTotal") do
|
73
105
|
confine :kernel => :openbsd
|
74
|
-
|
106
|
+
memtotal = Facter::Util::Resolution.exec("sysctl hw.physmem | cut -d'=' -f2")
|
107
|
+
setcode do
|
108
|
+
Facter::Memory.scale_number(memtotal.to_f,"")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
if Facter.value(:kernel) == "Darwin"
|
114
|
+
swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
|
115
|
+
swapfree, swaptotal = 0, 0
|
116
|
+
unless swap.empty?
|
117
|
+
# Parse the line:
|
118
|
+
# vm.swapusage: total = 128.00M used = 0.37M free = 127.63M (encrypted)
|
119
|
+
if swap =~ /total\s=\s(\S+)\s+used\s=\s(\S+)\s+free\s=\s(\S+)\s/
|
120
|
+
swaptotal += $1.to_i
|
121
|
+
swapfree += $3.to_i
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
Facter.add("SwapSize") do
|
126
|
+
confine :kernel => :Darwin
|
75
127
|
setcode do
|
76
|
-
Facter::Memory.scale_number(
|
128
|
+
Facter::Memory.scale_number(swaptotal.to_f,"MB")
|
77
129
|
end
|
78
130
|
end
|
79
131
|
|
132
|
+
Facter.add("SwapFree") do
|
133
|
+
confine :kernel => :Darwin
|
134
|
+
setcode do
|
135
|
+
Facter::Memory.scale_number(swapfree.to_f,"MB")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
Facter::Memory.vmstat_darwin_find_free_memory()
|
140
|
+
|
80
141
|
Facter.add("MemoryTotal") do
|
81
|
-
confine :kernel => :
|
82
|
-
memtotal = Facter::Util::Resolution.exec("sysctl hw.
|
142
|
+
confine :kernel => :Darwin
|
143
|
+
memtotal = Facter::Util::Resolution.exec("sysctl hw.memsize | cut -d':' -f2")
|
83
144
|
setcode do
|
84
145
|
Facter::Memory.scale_number(memtotal.to_f,"")
|
85
146
|
end
|
86
147
|
end
|
87
148
|
end
|
149
|
+
|
150
|
+
if Facter.value(:kernel) == "SunOS"
|
151
|
+
swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l')
|
152
|
+
swapfree, swaptotal = 0, 0
|
153
|
+
swap.each do |dev|
|
154
|
+
if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/
|
155
|
+
swaptotal += $1.to_i / 2
|
156
|
+
swapfree += $2.to_i / 2
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
Facter.add("SwapSize") do
|
161
|
+
confine :kernel => :sunos
|
162
|
+
setcode do
|
163
|
+
Facter::Memory.scale_number(swaptotal.to_f,"kB")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
Facter.add("SwapFree") do
|
168
|
+
confine :kernel => :sunos
|
169
|
+
setcode do
|
170
|
+
Facter::Memory.scale_number(swapfree.to_f,"kB")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# Total memory size available from prtconf
|
175
|
+
pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf')
|
176
|
+
phymem = ""
|
177
|
+
pconf.each do |line|
|
178
|
+
if line =~ /^Memory size:\s+(\d+) Megabytes/
|
179
|
+
phymem = $1
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
Facter.add("MemorySize") do
|
184
|
+
confine :kernel => :sunos
|
185
|
+
setcode do
|
186
|
+
Facter::Memory.scale_number(phymem.to_f,"MB")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
Facter::Memory.vmstat_find_free_memory()
|
191
|
+
end
|