summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/application.rb2
-rw-r--r--lib/facter/id.rb2
-rw-r--r--lib/facter/ipaddress.rb2
-rw-r--r--lib/facter/lsb.rb8
-rw-r--r--lib/facter/lsbmajdistrelease.rb2
-rw-r--r--lib/facter/operatingsystem.rb2
-rw-r--r--lib/facter/processor.rb7
-rw-r--r--lib/facter/selinux.rb41
-rw-r--r--lib/facter/util/ip.rb18
-rw-r--r--lib/facter/util/virtual.rb7
-rw-r--r--lib/facter/util/vlans.rb4
-rw-r--r--lib/facter/virtual.rb4
12 files changed, 71 insertions, 28 deletions
diff --git a/lib/facter/application.rb b/lib/facter/application.rb
index 9d6bc34..6b351b1 100644
--- a/lib/facter/application.rb
+++ b/lib/facter/application.rb
@@ -85,7 +85,7 @@ module Facter
begin
require 'rdoc/ri/ri_paths'
require 'rdoc/usage'
- puts RDoc.usage
+ RDoc.usage # print usage and exit
rescue LoadError
$stderr.puts "No help available unless your RDoc has RDoc.usage"
exit(1)
diff --git a/lib/facter/id.rb b/lib/facter/id.rb
index c2ab3b7..c2c3594 100644
--- a/lib/facter/id.rb
+++ b/lib/facter/id.rb
@@ -1,5 +1,5 @@
Facter.add(:id) do
- confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS GNU/kFreeBSD}
+ confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS GNU/kFreeBSD windows}
setcode "whoami"
end
diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
index 08a5dc8..d563408 100644
--- a/lib/facter/ipaddress.rb
+++ b/lib/facter/ipaddress.rb
@@ -47,7 +47,7 @@ Facter.add(:ipaddress) do
output.split(/^\S/).each { |str|
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
tmp = $1
- unless tmp =~ /^127\./
+ unless tmp =~ /^127\./ or tmp == "0.0.0.0"
ip = tmp
break
end
diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb
index 4b98466..bf4b9db 100644
--- a/lib/facter/lsb.rb
+++ b/lib/facter/lsb.rb
@@ -22,13 +22,13 @@
Facter.add(fact) do
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
setcode do
- unless defined?(@@lsbdata) and defined?(@@lsbtime) and (Time.now.to_i - @@lsbtime.to_i < 5)
+ unless defined?(lsbdata) and defined?(lsbtime) and (Time.now.to_i - lsbtime.to_i < 5)
type = nil
- @@lsbtime = Time.now
- @@lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
+ lsbtime = Time.now
+ lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
end
- if pattern.match(@@lsbdata)
+ if pattern.match(lsbdata)
$1
else
nil
diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb
index 997e7ef..34a2f1e 100644
--- a/lib/facter/lsbmajdistrelease.rb
+++ b/lib/facter/lsbmajdistrelease.rb
@@ -3,7 +3,7 @@
require 'facter'
Facter.add("lsbmajdistrelease") do
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS GNU/kFreeBSD}
+ confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS GNU/kFreeBSD}
setcode do
if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
result=$1
diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb
index 061e18e..1675909 100644
--- a/lib/facter/operatingsystem.rb
+++ b/lib/facter/operatingsystem.rb
@@ -36,6 +36,8 @@ Facter.add(:operatingsystem) do
txt = File.read("/etc/redhat-release")
if txt =~ /centos/i
"CentOS"
+ elsif txt =~ /scientific/i
+ "Scientific"
else
"RedHat"
end
diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb
index ac75867..c71bad4 100644
--- a/lib/facter/processor.rb
+++ b/lib/facter/processor.rb
@@ -17,6 +17,9 @@ if ["Linux", "GNU/kFreeBSD"].include? Facter.value(:kernel)
elsif l =~ /model name\s+:\s+(.*)\s*$/
processor_list[processor_num] = $1 unless processor_num == -1
processor_num = -1
+ elsif l =~ /processor\s+(\d+):\s+(.*)/
+ processor_num = $1.to_i
+ processor_list[processor_num] = $2 unless processor_num == -1
end
end
end
@@ -80,9 +83,9 @@ if Facter.value(:kernel) == "OpenBSD"
Facter::Util::Resolution.exec("uname -p")
end
end
-
+
Facter.add("ProcessorCount") do
- confine :kernel => :openbsd
+ confine :kernel => :openbsd
setcode do
Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d'=' -f2")
end
diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb
index 0e9637d..9fab427 100644
--- a/lib/facter/selinux.rb
+++ b/lib/facter/selinux.rb
@@ -4,7 +4,7 @@
Facter.add("selinux") do
confine :kernel => :linux
- setcode do
+ setcode do
result = "false"
if FileTest.exists?("/selinux/enforce")
if FileTest.exists?("/proc/self/attr/current")
@@ -31,15 +31,48 @@ end
Facter.add("selinux_policyversion") do
confine :selinux => :true
- setcode do
+ setcode do
File.read("/selinux/policyvers")
end
end
-Facter.add("selinux_mode") do
+Facter.add("selinux_current_mode") do
+ confine :selinux => :true
+ setcode do
+ result = 'unknown'
+ mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus')
+ mode.each_line { |l| result = $1 if l =~ /^Current mode\:\s+(\w+)$/i }
+ result.chomp
+ end
+end
+
+Facter.add("selinux_config_mode") do
confine :selinux => :true
setcode do
- %x{/usr/sbin/sestatus | /bin/grep "Policy from config file:" | awk '{print $5}'}
+ result = 'unknown'
+ mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus')
+ mode.each_line { |l| result = $1 if l =~ /^Mode from config file\:\s+(\w+)$/i }
+ result.chomp
end
end
+Facter.add("selinux_config_policy") do
+ confine :selinux => :true
+ setcode do
+ result = 'unknown'
+ mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus')
+ mode.each_line { |l| result = $1 if l =~ /^Policy from config file\:\s+(\w+)$/i }
+ result.chomp
+ end
+end
+
+# This is a legacy fact which returns the old selinux_mode fact value to prevent
+# breakages of existing manifests. It should be removed at the next major release.
+# See ticket #6677.
+
+Facter.add("selinux_mode") do
+ confine :selinux => :true
+ setcode do
+ Facter.value(:selinux_config_policy)
+ end
+end
diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb
index 23eeb9c..e4370dc 100644
--- a/lib/facter/util/ip.rb
+++ b/lib/facter/util/ip.rb
@@ -59,7 +59,7 @@ module Facter::Util::IP
# at the end of interfaces. So, we have to trim those trailing
# characters. I tried making the regex better but supporting all
# platforms with a single regex is probably a bit too much.
- output.scan(/^[-\w]+[.:]?\d+[.:]?\d*[.:]?\w*/).collect { |i| i.sub(/:$/, '') }.uniq
+ output.scan(/^\S+/).collect { |i| i.sub(/:$/, '') }.uniq
end
def self.get_all_interface_output
@@ -69,7 +69,7 @@ module Facter::Util::IP
when 'SunOS'
output = %x{/usr/sbin/ifconfig -a}
when 'HP-UX'
- output = %x{/bin/netstat -i}
+ output = %x{/bin/netstat -in | sed -e 1d}
end
output
end
@@ -141,15 +141,13 @@ module Facter::Util::IP
else
output_int = get_single_interface_output(interface)
- if interface != /^lo[0:]?\d?/
- output_int.each_line do |s|
- if s =~ regex
- value = $1
+ output_int.each_line do |s|
+ if s =~ regex
+ value = $1
if label == 'netmask' && convert_from_hex?(kernel)
value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.')
end
- tmp1.push(value)
- end
+ tmp1.push(value)
end
end
@@ -158,13 +156,13 @@ module Facter::Util::IP
end
end
end
-
+
def self.get_network_value(interface)
require 'ipaddr'
ipaddress = get_interface_value(interface, "ipaddress")
netmask = get_interface_value(interface, "netmask")
-
+
if ipaddress && netmask
ip = IPAddr.new(ipaddress, Socket::AF_INET)
subnet = IPAddr.new(netmask, Socket::AF_INET)
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index 129448e..4355451 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -60,8 +60,8 @@ module Facter::Util::Virtual
def self.jail?
path = case Facter.value(:kernel)
- when "FreeBSD": "/sbin"
- when "GNU/kFreeBSD": "/bin"
+ when "FreeBSD" then "/sbin"
+ when "GNU/kFreeBSD" then "/bin"
end
Facter::Util::Resolution.exec("#{path}/sysctl -n security.jail.jailed") == "1"
end
@@ -70,4 +70,7 @@ module Facter::Util::Virtual
Facter::Util::Resolution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/
end
+ def self.zlinux?
+ "zlinux"
+ end
end
diff --git a/lib/facter/util/vlans.rb b/lib/facter/util/vlans.rb
index 6d226ff..2b2a72f 100644
--- a/lib/facter/util/vlans.rb
+++ b/lib/facter/util/vlans.rb
@@ -12,7 +12,7 @@ module Facter::Util::Vlans
def self.get_vlans
vlans = Array.new
if self.get_vlan_config
- self.get_vlan_config.each do |line|
+ self.get_vlan_config.each_line do |line|
if line =~ /^([0-9A-Za-z]+)\.([0-9]+) /
vlans.insert(-1, $~[2]) if $~[2]
end
@@ -21,4 +21,4 @@ module Facter::Util::Vlans
vlans.join(',')
end
-end
+end
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index 47c9504..a5954cd 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -31,6 +31,10 @@ Facter.add("virtual") do
result = "hpvm" if Facter::Util::Virtual.hpvm?
end
+ if Facter.value(:architecture)=="s390x"
+ result = "zlinux" if Facter::Util::Virtual.zlinux?
+ end
+
if Facter::Util::Virtual.openvz?
result = Facter::Util::Virtual.openvz_type()
end