diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/lsbmajdistrelease.rb | 2 | ||||
-rw-r--r-- | lib/facter/memory.rb | 30 | ||||
-rw-r--r-- | lib/facter/operatingsystem.rb | 10 | ||||
-rw-r--r-- | lib/facter/operatingsystemrelease.rb | 26 | ||||
-rw-r--r-- | lib/facter/processor.rb | 7 | ||||
-rw-r--r-- | lib/facter/selinux.rb | 41 | ||||
-rw-r--r-- | lib/facter/util/ip.rb | 18 | ||||
-rw-r--r-- | lib/facter/util/virtual.rb | 3 | ||||
-rw-r--r-- | lib/facter/virtual.rb | 8 |
9 files changed, 124 insertions, 21 deletions
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/memory.rb b/lib/facter/memory.rb index 86adc7f..aa67702 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -20,6 +20,36 @@ require 'facter/util/memory' end end +Facter.add("SwapSize") do + confine :kernel => :Darwin + setcode do + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + swaptotal = 0 + if swap =~ /total = (\S+)/ then swaptotal = $1; end + swaptotal + end +end + +Facter.add("SwapFree") do + confine :kernel => :Darwin + setcode do + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + swapfree = 0 + if swap =~ /free = (\S+)/ then swapfree = $1; end + swapfree + end +end + +Facter.add("SwapEncrypted") do + confine :kernel => :Darwin + setcode do + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + encrypted = false + if swap =~ /\(encrypted\)/ then encrypted = true; end + encrypted + end +end + if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root" swap = Facter::Util::Resolution.exec('swap -l') swapfree, swaptotal = 0, 0 diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index c5a3dc1..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 @@ -50,8 +52,12 @@ Facter.add(:operatingsystem) do else "SuSE" end - elsif FileTest.exists?("/etc/slackware-version") - "Slackware" + elsif FileTest.exists?("/etc/bluewhite64-version") + "Bluewhite64" + elsif FileTest.exists?("/etc/slamd64-version") + "Slamd64" + elsif FileTest.exists?("/etc/slackware-version") + "Slackware" end end end diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb index 280208b..ac9be65 100644 --- a/lib/facter/operatingsystemrelease.rb +++ b/lib/facter/operatingsystemrelease.rb @@ -72,5 +72,29 @@ Facter.add(:operatingsystemrelease) do end Facter.add(:operatingsystemrelease) do - setcode do Facter[:kernelrelease].value end + confine :operatingsystem => %w{Bluewhite64} + setcode do + releasefile = Facter::Util::Resolution.exec('cat /etc/bluewhite64-version') + if releasefile =~ /^\s*\w+\s+(\d+)\.(\d+)/ + $1 + "." + $2 + else + "unknown" + end + end +end + +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => %w{Slamd64} + setcode do + releasefile = Facter::Util::Resolution.exec('cat /etc/slamd64-version') + if releasefile =~ /^\s*\w+\s+(\d+)\.(\d+)/ + $1 + "." + $2 + else + "unknown" + end + end +end + +Facter.add(:operatingsystemrelease) do + setcode do Facter[:kernelrelease].value end 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 06b1b6d..4355451 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb @@ -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/virtual.rb b/lib/facter/virtual.rb index cf84f75..468ab77 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -25,12 +25,18 @@ Facter.add("virtual") do setcode do - result = "zone" if Facter::Util::Virtual.zone? + if Facter::Util::Virtual.zone? and Facter.value(:operatingsystem) == "Solaris" + result = "zone" + end if Facter.value(:kernel)=="HP-UX" 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 |