From 72996ff6d01c6891bad241c45a5555e1a639ddd5 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 22 Mar 2011 21:37:10 -0700 Subject: maint: cleanup whitespace --- lib/facter/memory.rb | 36 ++++++++++++++++++------------------ lib/facter/util/memory.rb | 1 - 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index 9dd2e29..0aa5e88 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -23,30 +23,30 @@ 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 + 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 + 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 + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + encrypted = false + if swap =~ /\(encrypted\)/ then encrypted = true; end + encrypted end end @@ -57,9 +57,9 @@ if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root" if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/ swaptotal += $1.to_i swapfree += $2.to_i - end - end - + end + end + Facter.add("SwapSize") do confine :kernel => :aix setcode do @@ -154,9 +154,9 @@ if Facter.value(:kernel) == "SunOS" if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/ swaptotal += $1.to_i / 2 swapfree += $2.to_i / 2 - end - end - + end + end + Facter.add("SwapSize") do confine :kernel => :sunos setcode do diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb index 029b117..b7ad198 100644 --- a/lib/facter/util/memory.rb +++ b/lib/facter/util/memory.rb @@ -94,4 +94,3 @@ module Facter::Memory end end end - -- cgit From fd4f31c3748d7e59b00473355a12fc232d173eab Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 22 Mar 2011 21:53:18 -0700 Subject: (#6817) Fix for Ruby 1.9 by calling .each_line on a string --- lib/facter/util/memory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb index b7ad198..d86a423 100644 --- a/lib/facter/util/memory.rb +++ b/lib/facter/util/memory.rb @@ -75,7 +75,7 @@ module Facter::Memory memspecfree = 0 vmstats = Facter::Util::Resolution.exec('vm_stat') - vmstats.each do |vmline| + vmstats.each_line do |vmline| case when vmline =~ /page\ssize\sof\s(\d+)\sbytes/ pagesize = $1.to_i -- cgit From 56b5f10e876b29f9a2fd1906087ebb3cb5d47035 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Mon, 28 Mar 2011 11:01:19 -0700 Subject: (#6613) Switch solaris macaddress fact to netstat - ifconfig on solaris will only return the mac address if run as root. netstat -np will provide the information to any user. --- lib/facter/macaddress.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index 4a12384..bf23ef6 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -12,6 +12,18 @@ Facter.add(:macaddress) do end end +Facter.add(:macaddress) do + confine :operatingsystem => "Solaris" + setcode do + ether = [] + output = Facter::Util::Resolution.exec("/usr/bin/netstat -np") + output.each_line do |s| + ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/ + end + ether[0] + end +end + Facter.add(:macaddress) do confine :operatingsystem => %w{FreeBSD OpenBSD} setcode do -- cgit From 1063753df8938d4ea350199a4dcedd6c08c2d092 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 28 Mar 2011 11:08:29 -0700 Subject: (#6862) Add a default subject for the mail_patches rake task This will prevent committers to forget to write cover letter subject when rake mail_patches needs to send multiple e-mails. It defaults to the "type" and "branch name" of the patch-set. This is taken from Brice's patch against Puppet (37f9ca09135330ed180fb68d9295a4967a5cc857). Signed-off-by: Brice Figureau --- tasks/rake/mail_patches.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasks/rake/mail_patches.rake b/tasks/rake/mail_patches.rake index be8dda1..1346faa 100644 --- a/tasks/rake/mail_patches.rake +++ b/tasks/rake/mail_patches.rake @@ -34,12 +34,14 @@ task :mail_patches do # If we've got more than one patch, add --compose if files.length > 1 compose = "--compose" + subject = %Q{--subject "#{type} #{name} against #{parent}"} else compose = "" + subject = "" end # Now send the mail. - sh "git send-email #{compose} --no-signed-off-by-cc --suppress-from --to puppet-dev@googlegroups.com 00*.patch" + sh "git send-email #{compose} #{subject} --no-signed-off-by-cc --suppress-from --to puppet-dev@googlegroups.com 00*.patch" # Finally, clean up the patches sh "rm 00*.patch" -- cgit From 06eb3f57f48a57881e8dadc19714366eed5add18 Mon Sep 17 00:00:00 2001 From: Ben Hughes Date: Tue, 29 Mar 2011 13:38:44 +1100 Subject: (#6883) Update Facter install.rb to be slightly more informative. Give slightly more information to the user when installing facter and the pre-requisite Ruby libraries are not installed. In the case of OpenSSL, the user can have OpenSSL installed, and not the gem/library, but the error message given in no way hints to this. --- install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.rb b/install.rb index eb91e7c..d4793eb 100755 --- a/install.rb +++ b/install.rb @@ -119,7 +119,7 @@ def check_prereqs begin require pre rescue LoadError - puts "Could not load %s; cannot install" % pre + puts "Could not load #{pre} Ruby library; cannot install" exit -1 end } -- cgit From 7c082702c72c168f3e739b9bc1c7562b0aa15ddd Mon Sep 17 00:00:00 2001 From: Ben H Date: Sun, 13 Mar 2011 14:07:37 +1100 Subject: (#5394) Document each Facter fact. Document all the builtin Facter facts in puppetdoc/rdoc format. This is laying the ground work for using a tool like puppet doc, or puppet describe but for facter, so you can see what a fact is for and how it resolves this. This is the "leg work" of documenting the actual facts, and the syntax of them may change in future. --- lib/facter/Cfkey.rb | 11 +++++++++++ lib/facter/architecture.rb | 13 ++++++++++++ lib/facter/domain.rb | 20 +++++++++++++++++++ lib/facter/facterversion.rb | 9 +++++++++ lib/facter/fqdn.rb | 11 +++++++++++ lib/facter/hardwareisa.rb | 12 ++++++++++++ lib/facter/hardwaremodel.rb | 13 ++++++++++++ lib/facter/hostname.rb | 13 ++++++++++++ lib/facter/id.rb | 13 ++++++++++++ lib/facter/interfaces.rb | 9 +++++++++ lib/facter/ipaddress.rb | 24 +++++++++++++++++++++++ lib/facter/ipaddress6.rb | 27 ++++++++++++++++--------- lib/facter/iphostnumber.rb | 11 +++++++++++ lib/facter/kernel.rb | 11 +++++++++++ lib/facter/kernelmajversion.rb | 10 ++++++++++ lib/facter/kernelrelease.rb | 13 ++++++++++++ lib/facter/kernelversion.rb | 12 ++++++++++++ lib/facter/lsb.rb | 13 ++++++++++++ lib/facter/lsbmajdistrelease.rb | 12 ++++++++++++ lib/facter/macaddress.rb | 9 +++++++++ lib/facter/macosx.rb | 13 ++++++++++++ lib/facter/manufacturer.rb | 13 ++++++++++++ lib/facter/memory.rb | 17 ++++++++++++++++ lib/facter/netmask.rb | 9 +++++++++ lib/facter/network.rb | 12 ++++++++++++ lib/facter/operatingsystem.rb | 13 ++++++++++++ lib/facter/operatingsystemrelease.rb | 17 ++++++++++++++++ lib/facter/path.rb | 9 +++++++++ lib/facter/physicalprocessorcount.rb | 11 +++++++++++ lib/facter/processor.rb | 15 +++++++++++++- lib/facter/ps.rb | 12 ++++++++++++ lib/facter/puppetversion.rb | 10 ++++++++++ lib/facter/rubysitedir.rb | 10 ++++++++++ lib/facter/rubyversion.rb | 9 +++++++++ lib/facter/selinux.rb | 9 +++++++++ lib/facter/ssh.rb | 9 +++++++++ lib/facter/timezone.rb | 9 +++++++++ lib/facter/uptime.rb | 11 +++++++++++ lib/facter/uptime_days.rb | 9 +++++++++ lib/facter/uptime_hours.rb | 9 +++++++++ lib/facter/uptime_seconds.rb | 14 +++++++++++++ lib/facter/virtual.rb | 38 ++++++++++++++++++++++++++++++++++++ lib/facter/vlans.rb | 10 ++++++++++ lib/facter/xendomains.rb | 11 +++++++++++ 44 files changed, 555 insertions(+), 10 deletions(-) diff --git a/lib/facter/Cfkey.rb b/lib/facter/Cfkey.rb index a4e0c11..8353392 100644 --- a/lib/facter/Cfkey.rb +++ b/lib/facter/Cfkey.rb @@ -1,3 +1,14 @@ +# Fact: Cfkey +# +# Purpose: Return the public key(s) for CFengine. +# +# Resolution: +# Tries each file of standard localhost.pub & cfkey.pub locations, +# checks if they appear to be a public key, and then join them all together. +# +# Caveats: +# + ## Cfkey.rb ## Facts related to cfengine ## diff --git a/lib/facter/architecture.rb b/lib/facter/architecture.rb index e4aaeba..cd606a2 100644 --- a/lib/facter/architecture.rb +++ b/lib/facter/architecture.rb @@ -1,3 +1,16 @@ +# Fact: architecture +# +# Purpose: +# Return the CPU hardware architecture. +# +# Resolution: +# On OpenBSD, Linux and Debian's kfreebsd, use the hardwaremodel fact. +# Gentoo and Debian call "x86_86" "amd64". +# Gentoo also calls "i386" "x86". +# +# Caveats: +# + Facter.add(:architecture) do confine :kernel => [:linux, :"gnu/kfreebsd"] setcode do diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb index 29bb204..2a79754 100644 --- a/lib/facter/domain.rb +++ b/lib/facter/domain.rb @@ -1,3 +1,23 @@ +# Fact: domain +# +# Purpose: +# Return the host's primary DNS domain name. +# +# Resolution: +# On UNIX (excluding Darwin), first try and use the hostname fact, +# which uses the hostname system command, and then parse the output +# of that. +# Failing that it tries the dnsdomainname system command. +# Failing that it uses /etc/resolv.conf and takes the domain from that, or as +# a final resort, the search from that. +# Otherwise returns nil. +# +# On Windows uses the win32ole gem and winmgmts to get the DNSDomain value +# from the Win32 networking stack. +# +# Caveats: +# + Facter.add(:domain) do setcode do # Get the domain from various sources; the order of these diff --git a/lib/facter/facterversion.rb b/lib/facter/facterversion.rb index 0b1cfda..574da99 100644 --- a/lib/facter/facterversion.rb +++ b/lib/facter/facterversion.rb @@ -1,3 +1,12 @@ +# Fact: facterversion +# +# Purpose: returns the version of the facter module. +# +# Resolution: Uses the version constant. +# +# Caveats: +# + Facter.add(:facterversion) do setcode { Facter::FACTERVERSION.to_s } end diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb index 5ebc5f5..090ca63 100644 --- a/lib/facter/fqdn.rb +++ b/lib/facter/fqdn.rb @@ -1,3 +1,14 @@ +# Fact: fqdn +# +# Purpose: Returns the fully qualified domain name of the host. +# +# Resolution: Simply joins the hostname fact with the domain name fact. +# +# Caveats: No attempt is made to check that the two facts are accurate or that +# the two facts go together. At no point is there any DNS resolution made +# either. +# + Facter.add(:fqdn) do setcode do host = Facter.value(:hostname) diff --git a/lib/facter/hardwareisa.rb b/lib/facter/hardwareisa.rb index 23f7d08..9d0830e 100644 --- a/lib/facter/hardwareisa.rb +++ b/lib/facter/hardwareisa.rb @@ -1,3 +1,15 @@ +# Fact: hardwareisa +# +# Purpose: +# Returns hardware processor type. +# +# Resolution: +# On Solaris, Linux and the BSDs simply uses the output of "uname -p" +# +# Caveats: +# Some linuxes return unknown to uname -p with relative ease. +# + Facter.add(:hardwareisa) do setcode 'uname -p', '/bin/sh' confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS GNU/kFreeBSD} diff --git a/lib/facter/hardwaremodel.rb b/lib/facter/hardwaremodel.rb index 6201bdd..8f52fef 100644 --- a/lib/facter/hardwaremodel.rb +++ b/lib/facter/hardwaremodel.rb @@ -1,3 +1,16 @@ +# Fact: hardwaremodel +# +# Purpose: +# Returns the hardware model of the system. +# +# Resolution: +# Uses purely "uname -m" on all platforms other than AIX and Windows. +# On AIX uses the parsed "modelname" output of "lsattr -El sys0 -a modelname". +# On Windows uses the 'host_cpu' pulled out of Ruby's config. +# +# Caveats: +# + Facter.add(:hardwaremodel) do setcode 'uname -m' end diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb index 188efa4..0dcd01c 100644 --- a/lib/facter/hostname.rb +++ b/lib/facter/hostname.rb @@ -1,3 +1,16 @@ +# Fact: hostname +# +# Purpose: Return the system's short hostname. +# +# Resolution: +# On all system bar Darwin, parses the output of the "hostname" system command +# to everything before the first period. +# On Darwin, uses the system configuration util to get the LocalHostName +# variable. +# +# Caveats: +# + Facter.add(:hostname, :ldapname => "cn") do setcode do hostname = nil diff --git a/lib/facter/id.rb b/lib/facter/id.rb index 1c42284..cc0a0a6 100644 --- a/lib/facter/id.rb +++ b/lib/facter/id.rb @@ -1,3 +1,16 @@ +# Fact: id +# +# Purpose: Internal fact used to specity the program to return the currently +# running user id. +# +# Resolution: +# On all Unixes bar Solaris, just returns "whoami". +# On Solaris, parses the output of the "id" command to grab the username, as +# Solaris doesn't have the whoami command. +# +# Caveats: +# + Facter.add(:id) do setcode "whoami" end diff --git a/lib/facter/interfaces.rb b/lib/facter/interfaces.rb index 4fbaef1..04b1c19 100644 --- a/lib/facter/interfaces.rb +++ b/lib/facter/interfaces.rb @@ -1,3 +1,12 @@ +# Fact: interfaces +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + # interfaces.rb # Try to get additional Facts about the machine's network interfaces # diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb index d563408..5260504 100644 --- a/lib/facter/ipaddress.rb +++ b/lib/facter/ipaddress.rb @@ -1,3 +1,27 @@ +# Fact: ipaddress +# +# Purpose: Return the main IP address for a host. +# +# Resolution: +# On the Unixes does an ifconfig, and returns the first non 127.0.0.0/8 +# subnetted IP it finds. +# On Windows, it attempts to use the socket library and resolve the machine's +# hostname via DNS. +# +# On LDAP based hosts it tries to use either the win32/resolv library to +# resolve the hostname to an IP address, or on Unix, it uses the resolv +# library. +# +# As a fall back for undefined systems, it tries to run the "host" command to +# resolve the machine's hostname using the system DNS. +# +# Caveats: +# DNS resolution relies on working DNS infrastructure and resolvers on the +# host system. +# The ifconfig parsing purely takes the first IP address it finds without any +# checking this is a useful IP address. +# + Facter.add(:ipaddress) do confine :kernel => :linux setcode do diff --git a/lib/facter/ipaddress6.rb b/lib/facter/ipaddress6.rb index 547d636..b494b9d 100644 --- a/lib/facter/ipaddress6.rb +++ b/lib/facter/ipaddress6.rb @@ -1,17 +1,26 @@ +# Fact: ipaddress6 +# +# Purpose: Returns the "main" IPv6 IP address of a system. +# +# Resolution: +# OS dependant code that parses the output of various networking +# tools and currently not very intelligent. Returns the first +# non-loopback and non-linklocal address found in the ouput unless +# a default route can be mapped to a routeable interface. Guessing +# an interface is currently only possible with BSD type systems +# to many assumptions have to be made on other platforms to make +# this work with the current code. Most code ported or modeled +# after the ipaddress fact for the sake of similar functionality +# and familiar mechanics. +# +# Caveats: +# + # Cody Herriges # # Used the ipaddress fact that is already part of # Facter as a template. -# OS dependant code that parses the output of various networking -# tools and currently not very intelligent. Returns the first -# non-loopback and non-linklocal address found in the ouput unless -# a default route can be mapped to a routeable interface. Guessing -# an interface is currently only possible with BSD type systems -# to many assumptions have to be made on other platforms to make -# this work with the current code. Most code ported or modeled -# after the ipaddress fact for the sake of similar functionality -# and familiar mechanics. Facter.add(:ipaddress6) do confine :kernel => :linux setcode do diff --git a/lib/facter/iphostnumber.rb b/lib/facter/iphostnumber.rb index bc38432..cddaadd 100644 --- a/lib/facter/iphostnumber.rb +++ b/lib/facter/iphostnumber.rb @@ -1,3 +1,14 @@ +# Fact: iphostnumber +# +# Purpose: On selected versions of Darwin, returns the host's IP address. +# +# Resolution: +# Uses either the scutil program to get the localhost name, or parses output +# of ifconfig for a MAC address. +# +# Caveats: +# + Facter.add(:iphostnumber) do confine :kernel => :darwin, :kernelrelease => "R6" setcode do diff --git a/lib/facter/kernel.rb b/lib/facter/kernel.rb index 66f21ce..f457e01 100644 --- a/lib/facter/kernel.rb +++ b/lib/facter/kernel.rb @@ -1,3 +1,14 @@ +# Fact: kernel +# +# Purpose: Returns the operating system's name. +# +# Resolution: +# Uses Ruby's rbconfig to find host_os, if that is a Windows derivative, the +# returns 'windows', otherwise returns "uname -s" verbatim. +# +# Caveats: +# + Facter.add(:kernel) do setcode do require 'rbconfig' diff --git a/lib/facter/kernelmajversion.rb b/lib/facter/kernelmajversion.rb index 32fd7aa..84f71d4 100644 --- a/lib/facter/kernelmajversion.rb +++ b/lib/facter/kernelmajversion.rb @@ -1,3 +1,13 @@ +# Fact: kernelmajversion +# +# Purpose: Return the operating system's release number's major value. +# +# Resolution: +# Takes the first 2 elements of the kernel version as delimited by periods. +# +# Caveats: +# + Facter.add("kernelmajversion") do setcode do Facter.value(:kernelversion).split('.')[0..1].join('.') diff --git a/lib/facter/kernelrelease.rb b/lib/facter/kernelrelease.rb index 2f6ae45..a6f9c2c 100644 --- a/lib/facter/kernelrelease.rb +++ b/lib/facter/kernelrelease.rb @@ -1,3 +1,16 @@ +# Fact: kernelrelease +# +# Purpose: Return the operating system's release number. +# +# Resolution: +# On AIX returns the output from the "oslevel -s" system command. +# On Windows based systems, uses the win32ole gem to query Windows Management +# for the 'Win32_OperatingSystem' value. +# Otherwise uses the output of "uname -r" system command. +# +# Caveats: +# + Facter.add(:kernelrelease) do setcode 'uname -r' end diff --git a/lib/facter/kernelversion.rb b/lib/facter/kernelversion.rb index cac6c14..7e0d95c 100644 --- a/lib/facter/kernelversion.rb +++ b/lib/facter/kernelversion.rb @@ -1,3 +1,15 @@ +# Fact: kernelversion +# +# Purpose: Return the operating system's kernel version. +# +# Resolution: +# On Solaris and SunOS based machines, returns the output of "uname -v". +# Otherwise returns the 'kernerlversion' fact up to the first '-'. This may be +# the entire 'kernelversion' fact in many cases. +# +# Caveats: +# + Facter.add("kernelversion") do setcode do Facter['kernelrelease'].value.split('-')[0] diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index bf4b9db..107419a 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb @@ -1,3 +1,16 @@ +# Fact: lsb +# +# Purpose: Return Linux Standard Base information for the host. +# +# Resolution: +# Uses the lsb_release system command and parses the output with a series of +# regular expressions. +# +# Caveats: +# Only works on Linux (and the kfreebsd derivative) systems. +# Requires the lsb_release program, which may not be installed by default. +# Also is as only as accurate as that program outputs. + ## lsb.rb ## Facts related to Linux Standard Base (LSB) ## diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb index 34a2f1e..3659541 100644 --- a/lib/facter/lsbmajdistrelease.rb +++ b/lib/facter/lsbmajdistrelease.rb @@ -1,3 +1,15 @@ +# Fact: lsbmajdistrelease +# +# Purpose: Returns the major version of the operation system version as gleaned +# from the lsbdistrelease fact. +# +# Resolution: +# Parses the lsbdistrelease fact for numbers followed by a period and +# returns those, or just the lsbdistrelease fact if none were found. +# +# Caveats: +# + # lsbmajdistrelease.rb # require 'facter' diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index 4a12384..fa9e567 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -1,3 +1,12 @@ +# Fact: macaddress +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + require 'facter/util/macaddress' Facter.add(:macaddress) do diff --git a/lib/facter/macosx.rb b/lib/facter/macosx.rb index 3841c50..f5289df 100644 --- a/lib/facter/macosx.rb +++ b/lib/facter/macosx.rb @@ -1,3 +1,16 @@ +# Fact: macosx +# +# Purpose: +# Returns a number of Mac specific facts, from system profiler and +# sw_vers. +# +# Resolution: +# Uses util/macosx.rb to do the fact reconnaissance, then outputs them +# preceded by 'sp_' +# +# Caveats: +# + # # macosx.rb # Additional Facts coming from Mac OS X system_profiler command diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb index 4f2df98..26aef5f 100644 --- a/lib/facter/manufacturer.rb +++ b/lib/facter/manufacturer.rb @@ -1,3 +1,16 @@ +# Fact: manufacturer +# +# Purpose: Return the hardware manufacturer information about the hardware. +# +# Resolution: +# On OpenBSD, queries sysctl values, via a util class. +# On SunOS Sparc, uses prtdiag via a util class. +# On Windows, queries the system via a util class. +# Uses the 'util/manufacturer.rb' for fallback parsing. +# +# Caveats: +# + # manufacturer.rb # Facts related to hardware manufacturer # diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index 0aa5e88..992f2ad 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -1,3 +1,20 @@ +# Fact: memory +# +# Purpose: Return information about memory and swap usage. +# +# Resolution: +# On Linuxes, uses Facter::Memory.meminfo_number from +# 'facter/util/memory.rb' +# On AIX, parses "swap -l" for swap values only. +# On OpenBSD, it parses "swapctl -l" for swap values, vmstat via a module for +# free memory, and "sysctl hw.physmem" for maximum memory. +# On Solaris, use "swap -l" for swap values, and parsing prtconf for maximum +# memory, and again, the vmstat module for free memory. +# +# Caveats: +# Some BSD platforms aren't covered at all. AIX is missing memory values. +# + # memory.rb # Additional Facts for memory/swap usage # diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb index d6d125e..fbb84f5 100644 --- a/lib/facter/netmask.rb +++ b/lib/facter/netmask.rb @@ -1,3 +1,12 @@ +# Fact: netmask +# +# Purpose: Returns the netmask for the main interfaces. +# +# Resolution: Uses the facter/util/netmask library routines. +# +# Caveats: +# + # netmask.rb # Find the netmask of the primary ipaddress # Copyright (C) 2007 David Schmitt diff --git a/lib/facter/network.rb b/lib/facter/network.rb index df53ce4..d4faaac 100644 --- a/lib/facter/network.rb +++ b/lib/facter/network.rb @@ -1,3 +1,15 @@ +# Fact: network +# +# Purpose: +# Get IP, network and netmask information for available network +# interfacs. +# +# Resolution: +# Uses 'facter/util/ip' to enumerate interfaces and return their information. +# +# Caveats: +# + require 'facter/util/ip' Facter::Util::IP.get_interfaces.each do |interface| diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index 25eeb00..a90c283 100644 --- a/lib/facter/operatingsystem.rb +++ b/lib/facter/operatingsystem.rb @@ -1,3 +1,16 @@ +# Fact: operatingsystem +# +# Purpose: Return the name of the operating system. +# +# Resolution: +# If the kernel is a Linux kernel, check for the existence of a selection of +# files in /etc/ to find the specific flavour. +# On SunOS based kernels, return Solaris. +# On systems other than Linux, use the kernel value. +# +# Caveats: +# + require 'facter/lsb' Facter.add(:operatingsystem) do diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb index da1b76a..347fe7f 100644 --- a/lib/facter/operatingsystemrelease.rb +++ b/lib/facter/operatingsystemrelease.rb @@ -1,3 +1,20 @@ +# Fact: operatingsystemrelease +# +# Purpose: Returns the release of the operating system. +# +# Resolution: +# On RedHat derivatives, returns their '/etc/-release' file. +# On Debian, returns '/etc/debian_version'. +# On Ubuntu, parses '/etc/issue' for the release version. +# On Suse, derivatives, parses '/etc/SuSE-release' for a selection of version +# information. +# On Slackware, parses '/etc/slackware-version'. +# +# On all remaining systems, returns the 'kernelrelease' value. +# +# Caveats: +# + Facter.add(:operatingsystemrelease) do confine :operatingsystem => %w{CentOS Fedora oel ovs RedHat MeeGo} setcode do diff --git a/lib/facter/path.rb b/lib/facter/path.rb index 03907c0..71df6cd 100644 --- a/lib/facter/path.rb +++ b/lib/facter/path.rb @@ -1,3 +1,12 @@ +# Fact: path +# +# Purpose: Returns the $PATH variable. +# +# Resolution: Gets $PATH from the environment. +# +# Caveats: +# + Facter.add(:path) do setcode do ENV['PATH'] diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 8fe643e..9c59614 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -1,3 +1,14 @@ +# Fact: physicalprocessorcount +# +# Purpose: Return the number of physical processors. +# +# Resolution: +# On linux, parses the output of '/proc/cpuinfo' for the number of unique +# lines with "physical id" in them. +# +# Caveats: +# + Facter.add("physicalprocessorcount") do confine :kernel => :linux diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb index c71bad4..ec196b2 100644 --- a/lib/facter/processor.rb +++ b/lib/facter/processor.rb @@ -1,5 +1,18 @@ +# Fact: processor +# +# Purpose: +# Additional Facts about the machine's CPUs. +# +# Resolution: +# On Linux and kFreeBSD, parse '/proc/cpuinfo' for each processor. +# On AIX, parse the output of 'lsdev' for it's processor section. +# On OpenBSD, use 'uname -p' and the sysctl variable for 'hw.ncpu' for CPU +# count. +# +# Caveats: +# + # processor.rb -# Additional Facts about the machine's CPUs # # Copyright (C) 2006 Mooter Media Ltd # Author: Matthew Palmer diff --git a/lib/facter/ps.rb b/lib/facter/ps.rb index e7bcdae..ef803fb 100644 --- a/lib/facter/ps.rb +++ b/lib/facter/ps.rb @@ -1,3 +1,15 @@ +# Fact: ps +# +# Purpose: Internal fact for what to use to list all processes. Used by +# Service{} type in Puppet. +# +# Resolution: +# Assumes "ps -ef" for all operating systems other than BSD derivatives, where +# it uses "ps auxwww" +# +# Caveats: +# + Facter.add(:ps) do setcode do 'ps -ef' end end diff --git a/lib/facter/puppetversion.rb b/lib/facter/puppetversion.rb index d2eb1f3..01422f0 100644 --- a/lib/facter/puppetversion.rb +++ b/lib/facter/puppetversion.rb @@ -1,3 +1,13 @@ +# Fact: puppetversion +# +# Purpose: Return the version of puppet installed. +# +# Resolution: +# Requres puppet via Ruby and returns it's version constant. +# +# Caveats: +# + Facter.add(:puppetversion) do setcode do begin diff --git a/lib/facter/rubysitedir.rb b/lib/facter/rubysitedir.rb index c205322..9973329 100644 --- a/lib/facter/rubysitedir.rb +++ b/lib/facter/rubysitedir.rb @@ -1,3 +1,13 @@ +# Fact: rubysitedir +# +# Purpose: Returns Ruby's site library directory. +# +# Resolution: Works out the version to major/minor (1.8, 1.9, etc), then joins +# that with all the $: library paths. +# +# Caveats: +# + Facter.add :rubysitedir do setcode do version = RUBY_VERSION.to_s.sub(/\.\d+$/, '') diff --git a/lib/facter/rubyversion.rb b/lib/facter/rubyversion.rb index 48f5cc8..e578400 100644 --- a/lib/facter/rubyversion.rb +++ b/lib/facter/rubyversion.rb @@ -1,3 +1,12 @@ +# Fact: rubyversion +# +# Purpose: Returns the version of Ruby facter is running under. +# +# Resolution: Returns RUBY_VERSION. +# +# Caveats: +# + Facter.add(:rubyversion) do setcode { RUBY_VERSION.to_s } end diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb index 9fab427..1555da0 100644 --- a/lib/facter/selinux.rb +++ b/lib/facter/selinux.rb @@ -1,3 +1,12 @@ +# Fact: selinux +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + # Fact for SElinux # Written by immerda admin team (admin(at)immerda.ch) diff --git a/lib/facter/ssh.rb b/lib/facter/ssh.rb index 318e9d4..beb5692 100644 --- a/lib/facter/ssh.rb +++ b/lib/facter/ssh.rb @@ -1,3 +1,12 @@ +# Fact: ssh +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + ## ssh.rb ## Facts related to SSH ## diff --git a/lib/facter/timezone.rb b/lib/facter/timezone.rb index 744e06a..462c9ba 100644 --- a/lib/facter/timezone.rb +++ b/lib/facter/timezone.rb @@ -1,3 +1,12 @@ +# Fact: timezone +# +# Purpose: Return the machine's time zone. +# +# Resolution: Uses's Ruby's Time module's Time.new call. +# +# Caveats: +# + Facter.add("timezone") do setcode do Time.new.zone diff --git a/lib/facter/uptime.rb b/lib/facter/uptime.rb index 56a959b..7aeeb39 100644 --- a/lib/facter/uptime.rb +++ b/lib/facter/uptime.rb @@ -1,3 +1,14 @@ +# Fact: uptime +# +# Purpose: return the system uptime in a human readable format. +# +# Resolution: +# Does basic maths on the "uptime_seconds" fact to return a count of +# days, hours and minutes of uptime +# +# Caveats: +# + require 'facter/util/uptime' Facter.add(:uptime) do diff --git a/lib/facter/uptime_days.rb b/lib/facter/uptime_days.rb index add305c..25af966 100644 --- a/lib/facter/uptime_days.rb +++ b/lib/facter/uptime_days.rb @@ -1,3 +1,12 @@ +# Fact: uptime_days +# +# Purpose: Return purely number of days of uptime. +# +# Resolution: Divides uptime_hours fact by 24. +# +# Caveats: +# + Facter.add(:uptime_days) do setcode do hours = Facter.value(:uptime_hours) diff --git a/lib/facter/uptime_hours.rb b/lib/facter/uptime_hours.rb index ce691d2..d02ac32 100644 --- a/lib/facter/uptime_hours.rb +++ b/lib/facter/uptime_hours.rb @@ -1,3 +1,12 @@ +# Fact: uptime_hours +# +# Purpose: Return purely number of hours of uptime. +# +# Resolution: Divides uptime_seconds fact by 3600. +# +# Caveats: +# + Facter.add(:uptime_hours) do setcode do seconds = Facter.value(:uptime_seconds) diff --git a/lib/facter/uptime_seconds.rb b/lib/facter/uptime_seconds.rb index 14bb573..9793e41 100644 --- a/lib/facter/uptime_seconds.rb +++ b/lib/facter/uptime_seconds.rb @@ -1,3 +1,17 @@ +# Fact: uptime_seconds +# +# Purpose: Return purely number of seconds of uptime. +# +# Resolution: +# Using the 'facter/util/uptime.rb' module, try a verity of methods to acquire +# the uptime on Unix. +# +# On Windows, the module calculates the uptime by the "LastBootupTime" Windows +# management value. +# +# Caveats: +# + require 'facter/util/uptime' Facter.add(:uptime_seconds) do diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 468ab77..02802e6 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -1,3 +1,30 @@ +# Fact: virtual +# +# Purpose: Determine if the system's hardware is real or virtualised. +# +# Resolution: +# Assumes physical unless proven otherwise. +# +# On Darwin, use the macosx util module to acquire the SPDisplaysDataType, +# from that parse it to see if it's VMWare or Parallels pretending to be the +# display. +# +# On Linux, BSD, Solaris and HPUX: +# Much of the logic here is obscured behind util/virtual.rb, which rather +# than document here, which would encourage drift, just refer to it. +# The Xen tests in here rely on /sys and /proc, and check for the presence and +# contents of files in there. +# If after all the other tests, it's still seen as physical, then it tries to +# parse the output of the "lspci", "dmidecode" and "prtdiag" and parses them +# for obvious signs of being under VMWare or Parallels. +# Finally it checks for the existence of vmware-vmx, which would hint it's +# VMWare. +# +# Caveats: +# Virtualbox detection isn't implemented. +# Many checks rely purely on existence of files. +# + require 'facter/util/virtual' Facter.add("virtual") do @@ -108,6 +135,17 @@ Facter.add("virtual") do end end +# Fact: is_virtual +# +# Purpose: returning true or false for if a machine is virtualised or not. +# +# Resolution: The Xen domain 0 machine is virtualised to a degree, but is generally +# not viewed as being a virtual machine. This checks that the machine is not +# physical nor xen0, if that is the case, it is virtual. +# +# Caveats: +# + Facter.add("is_virtual") do confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD} diff --git a/lib/facter/vlans.rb b/lib/facter/vlans.rb index d65bdd8..8c485a4 100644 --- a/lib/facter/vlans.rb +++ b/lib/facter/vlans.rb @@ -1,3 +1,13 @@ +# Fact: vlans +# +# Purpose: On Linux, return a list of all the VLANs on the system. +# +# Resolution: On Linux only, checks for and reads /proc/net/vlan/config and +# parses it. +# +# Caveats: +# + require 'facter/util/vlans' Facter.add("vlans") do diff --git a/lib/facter/xendomains.rb b/lib/facter/xendomains.rb index 972ac90..5bcde05 100644 --- a/lib/facter/xendomains.rb +++ b/lib/facter/xendomains.rb @@ -1,3 +1,14 @@ +# Fact: xendomains +# +# Purpose: Return the list of Xen domains on the Dom0. +# +# Resolution: +# On a Xen Dom0 host, return a list of Xen domains using the 'util/xendomains' +# library. +# +# Caveats: +# + require 'facter/util/xendomains' Facter.add("xendomains") do -- cgit From 0b5b546e304fcf15a60f6489f89509e3bd2620f4 Mon Sep 17 00:00:00 2001 From: Ben Hughes Date: Tue, 29 Mar 2011 13:38:44 +1100 Subject: (#6883) Update Facter install.rb to be slightly more informative. Give slightly more information to the user when installing facter and the pre-requisite Ruby libraries are not installed. In the case of OpenSSL, the user can have OpenSSL installed, and not the gem/library, but the error message given in no way hints to this. --- install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.rb b/install.rb index eb91e7c..d4793eb 100755 --- a/install.rb +++ b/install.rb @@ -119,7 +119,7 @@ def check_prereqs begin require pre rescue LoadError - puts "Could not load %s; cannot install" % pre + puts "Could not load #{pre} Ruby library; cannot install" exit -1 end } -- cgit From e42e57c1a5674d77dfa14e10ade9592f5d2052e7 Mon Sep 17 00:00:00 2001 From: Michael Kincaid Date: Thu, 31 Mar 2011 16:04:57 -0700 Subject: (#3856) Add virtualbox detection via lspci (graphics card), dmidecode, and prtdiag for Solaris and corresponding tests. Darwin case is not handled yet. --- lib/facter/virtual.rb | 5 +++++ spec/unit/virtual_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 02802e6..7c649ba 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -104,6 +104,9 @@ Facter.add("virtual") do # --- look for the vmware video card to determine if it is virtual => vmware. # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter result = "vmware" if p =~ /VM[wW]are/ + # --- look for virtualbox video card to determine if it is virtual => virtualbox. + # --- 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter + result = "virtualbox" if p =~ /VirtualBox/ # --- look for pci vendor id used by Parallels video card # --- 01:00.0 VGA compatible controller: Unknown device 1ab8:4005 result = "parallels" if p =~ /1ab8:|[Pp]arallels/ @@ -114,6 +117,7 @@ Facter.add("virtual") do output.each_line do |pd| result = "parallels" if pd =~ /Parallels/ result = "vmware" if pd =~ /VMware/ + result = "virtualbox" if pd =~ /VirtualBox/ end else output = Facter::Util::Resolution.exec('prtdiag') @@ -121,6 +125,7 @@ Facter.add("virtual") do output.each_line do |pd| result = "parallels" if pd =~ /Parallels/ result = "vmware" if pd =~ /VMware/ + result = "virtualbox" if pd =~ /VirtualBox/ end end end diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index 7e50847..ac0a9bb 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -94,6 +94,12 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "vmware" end + it "should be virtualbox with VirtualBox vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter") + Facter.fact(:virtual).value.should == "virtualbox" + end + it "should be vmware with VMWare vendor name from dmidecode" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) @@ -108,6 +114,13 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "parallels" end + it "should be virtualbox with VirtualBox vendor name from dmidecode" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("BIOS Information\nVendor: innotek GmbH\nVersion: VirtualBox\n\nSystem Information\nManufacturer: innotek GmbH\nProduct Name: VirtualBox\nFamily: Virtual Machine") + Facter.fact(:virtual).value.should == "virtualbox" + end + it "should be vmware with VMWare vendor name from prtdiag" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) @@ -123,6 +136,14 @@ describe "Virtual fact" do Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform") Facter.fact(:virtual).value.should == "parallels" end + + it "should be virtualbox with VirtualBox vendor name from prtdiag" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox") + Facter.fact(:virtual).value.should == "virtualbox" + end end end @@ -152,6 +173,12 @@ describe "is_virtual fact" do Facter.fact(:is_virtual).value.should == "true" end + it "should be true when running on virtualbox" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("virtualbox") + Facter.fact(:is_virtual).value.should == "true" + end + it "should be true when running on openvz" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter.fact(:virtual).stubs(:value).returns("openvzve") -- cgit From f6c9927b6450894fc7036881eab5ff2fb9524e71 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Fri, 1 Apr 2011 10:44:22 -0700 Subject: (#6719) Corrected faulty logic in bugfix --- lib/facter/virtual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index e9571df..3c2d10f 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -25,7 +25,7 @@ Facter.add("virtual") do setcode do - if Facter::Util::Virtual.zone? and Facter(:operatingsystem) == "Solaris" + if Facter.value(:operatingsystem) == "Solaris" and Facter::Util::Virtual.zone? result = "zone" end -- cgit From 861c2b20f44caf4d4f5a1188663f5b82a3435836 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 22 Mar 2011 21:37:10 -0700 Subject: maint: cleanup whitespace --- lib/facter/memory.rb | 36 ++++++++++++++++++------------------ lib/facter/util/memory.rb | 1 - 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index 9dd2e29..0aa5e88 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -23,30 +23,30 @@ 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 + 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 + 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 + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + encrypted = false + if swap =~ /\(encrypted\)/ then encrypted = true; end + encrypted end end @@ -57,9 +57,9 @@ if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root" if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/ swaptotal += $1.to_i swapfree += $2.to_i - end - end - + end + end + Facter.add("SwapSize") do confine :kernel => :aix setcode do @@ -154,9 +154,9 @@ if Facter.value(:kernel) == "SunOS" if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/ swaptotal += $1.to_i / 2 swapfree += $2.to_i / 2 - end - end - + end + end + Facter.add("SwapSize") do confine :kernel => :sunos setcode do diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb index 029b117..b7ad198 100644 --- a/lib/facter/util/memory.rb +++ b/lib/facter/util/memory.rb @@ -94,4 +94,3 @@ module Facter::Memory end end end - -- cgit From e056218cc6f7fd7a40923ec6472d6020e220a81f Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 22 Mar 2011 21:53:18 -0700 Subject: (#6817) Fix for Ruby 1.9 by calling .each_line on a string --- lib/facter/util/memory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb index b7ad198..d86a423 100644 --- a/lib/facter/util/memory.rb +++ b/lib/facter/util/memory.rb @@ -75,7 +75,7 @@ module Facter::Memory memspecfree = 0 vmstats = Facter::Util::Resolution.exec('vm_stat') - vmstats.each do |vmline| + vmstats.each_line do |vmline| case when vmline =~ /page\ssize\sof\s(\d+)\sbytes/ pagesize = $1.to_i -- cgit From d6967a0630dec168059316426b0eb4228b27e451 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Mon, 28 Mar 2011 11:01:19 -0700 Subject: (#6613) Switch solaris macaddress fact to netstat - ifconfig on solaris will only return the mac address if run as root. netstat -np will provide the information to any user. --- lib/facter/macaddress.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index 4a12384..bf23ef6 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -12,6 +12,18 @@ Facter.add(:macaddress) do end end +Facter.add(:macaddress) do + confine :operatingsystem => "Solaris" + setcode do + ether = [] + output = Facter::Util::Resolution.exec("/usr/bin/netstat -np") + output.each_line do |s| + ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/ + end + ether[0] + end +end + Facter.add(:macaddress) do confine :operatingsystem => %w{FreeBSD OpenBSD} setcode do -- cgit From af4947c603b8f6610d861f303a7813cbc5ecf5e7 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 28 Mar 2011 11:08:29 -0700 Subject: (#6862) Add a default subject for the mail_patches rake task This will prevent committers to forget to write cover letter subject when rake mail_patches needs to send multiple e-mails. It defaults to the "type" and "branch name" of the patch-set. This is taken from Brice's patch against Puppet (37f9ca09135330ed180fb68d9295a4967a5cc857). Signed-off-by: Brice Figureau --- tasks/rake/mail_patches.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasks/rake/mail_patches.rake b/tasks/rake/mail_patches.rake index be8dda1..1346faa 100644 --- a/tasks/rake/mail_patches.rake +++ b/tasks/rake/mail_patches.rake @@ -34,12 +34,14 @@ task :mail_patches do # If we've got more than one patch, add --compose if files.length > 1 compose = "--compose" + subject = %Q{--subject "#{type} #{name} against #{parent}"} else compose = "" + subject = "" end # Now send the mail. - sh "git send-email #{compose} --no-signed-off-by-cc --suppress-from --to puppet-dev@googlegroups.com 00*.patch" + sh "git send-email #{compose} #{subject} --no-signed-off-by-cc --suppress-from --to puppet-dev@googlegroups.com 00*.patch" # Finally, clean up the patches sh "rm 00*.patch" -- cgit From d31e3f9ee6b36e707a189569132bcdcea79f20f6 Mon Sep 17 00:00:00 2001 From: Ben H Date: Sun, 13 Mar 2011 14:07:37 +1100 Subject: (#5394) Document each Facter fact. Document all the builtin Facter facts in puppetdoc/rdoc format. This is laying the ground work for using a tool like puppet doc, or puppet describe but for facter, so you can see what a fact is for and how it resolves this. This is the "leg work" of documenting the actual facts, and the syntax of them may change in future. --- lib/facter/Cfkey.rb | 11 +++++++++++ lib/facter/architecture.rb | 13 ++++++++++++ lib/facter/domain.rb | 20 +++++++++++++++++++ lib/facter/facterversion.rb | 9 +++++++++ lib/facter/fqdn.rb | 11 +++++++++++ lib/facter/hardwareisa.rb | 12 ++++++++++++ lib/facter/hardwaremodel.rb | 13 ++++++++++++ lib/facter/hostname.rb | 13 ++++++++++++ lib/facter/id.rb | 13 ++++++++++++ lib/facter/interfaces.rb | 9 +++++++++ lib/facter/ipaddress.rb | 24 +++++++++++++++++++++++ lib/facter/ipaddress6.rb | 27 ++++++++++++++++--------- lib/facter/iphostnumber.rb | 11 +++++++++++ lib/facter/kernel.rb | 11 +++++++++++ lib/facter/kernelmajversion.rb | 10 ++++++++++ lib/facter/kernelrelease.rb | 13 ++++++++++++ lib/facter/kernelversion.rb | 12 ++++++++++++ lib/facter/lsb.rb | 13 ++++++++++++ lib/facter/lsbmajdistrelease.rb | 12 ++++++++++++ lib/facter/macaddress.rb | 9 +++++++++ lib/facter/macosx.rb | 13 ++++++++++++ lib/facter/manufacturer.rb | 13 ++++++++++++ lib/facter/memory.rb | 17 ++++++++++++++++ lib/facter/netmask.rb | 9 +++++++++ lib/facter/network.rb | 12 ++++++++++++ lib/facter/operatingsystem.rb | 13 ++++++++++++ lib/facter/operatingsystemrelease.rb | 17 ++++++++++++++++ lib/facter/path.rb | 9 +++++++++ lib/facter/physicalprocessorcount.rb | 11 +++++++++++ lib/facter/processor.rb | 15 +++++++++++++- lib/facter/ps.rb | 12 ++++++++++++ lib/facter/puppetversion.rb | 10 ++++++++++ lib/facter/rubysitedir.rb | 10 ++++++++++ lib/facter/rubyversion.rb | 9 +++++++++ lib/facter/selinux.rb | 9 +++++++++ lib/facter/ssh.rb | 9 +++++++++ lib/facter/timezone.rb | 9 +++++++++ lib/facter/uptime.rb | 11 +++++++++++ lib/facter/uptime_days.rb | 9 +++++++++ lib/facter/uptime_hours.rb | 9 +++++++++ lib/facter/uptime_seconds.rb | 14 +++++++++++++ lib/facter/virtual.rb | 38 ++++++++++++++++++++++++++++++++++++ lib/facter/vlans.rb | 10 ++++++++++ lib/facter/xendomains.rb | 11 +++++++++++ 44 files changed, 555 insertions(+), 10 deletions(-) diff --git a/lib/facter/Cfkey.rb b/lib/facter/Cfkey.rb index a4e0c11..8353392 100644 --- a/lib/facter/Cfkey.rb +++ b/lib/facter/Cfkey.rb @@ -1,3 +1,14 @@ +# Fact: Cfkey +# +# Purpose: Return the public key(s) for CFengine. +# +# Resolution: +# Tries each file of standard localhost.pub & cfkey.pub locations, +# checks if they appear to be a public key, and then join them all together. +# +# Caveats: +# + ## Cfkey.rb ## Facts related to cfengine ## diff --git a/lib/facter/architecture.rb b/lib/facter/architecture.rb index e4aaeba..cd606a2 100644 --- a/lib/facter/architecture.rb +++ b/lib/facter/architecture.rb @@ -1,3 +1,16 @@ +# Fact: architecture +# +# Purpose: +# Return the CPU hardware architecture. +# +# Resolution: +# On OpenBSD, Linux and Debian's kfreebsd, use the hardwaremodel fact. +# Gentoo and Debian call "x86_86" "amd64". +# Gentoo also calls "i386" "x86". +# +# Caveats: +# + Facter.add(:architecture) do confine :kernel => [:linux, :"gnu/kfreebsd"] setcode do diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb index 29bb204..2a79754 100644 --- a/lib/facter/domain.rb +++ b/lib/facter/domain.rb @@ -1,3 +1,23 @@ +# Fact: domain +# +# Purpose: +# Return the host's primary DNS domain name. +# +# Resolution: +# On UNIX (excluding Darwin), first try and use the hostname fact, +# which uses the hostname system command, and then parse the output +# of that. +# Failing that it tries the dnsdomainname system command. +# Failing that it uses /etc/resolv.conf and takes the domain from that, or as +# a final resort, the search from that. +# Otherwise returns nil. +# +# On Windows uses the win32ole gem and winmgmts to get the DNSDomain value +# from the Win32 networking stack. +# +# Caveats: +# + Facter.add(:domain) do setcode do # Get the domain from various sources; the order of these diff --git a/lib/facter/facterversion.rb b/lib/facter/facterversion.rb index 0b1cfda..574da99 100644 --- a/lib/facter/facterversion.rb +++ b/lib/facter/facterversion.rb @@ -1,3 +1,12 @@ +# Fact: facterversion +# +# Purpose: returns the version of the facter module. +# +# Resolution: Uses the version constant. +# +# Caveats: +# + Facter.add(:facterversion) do setcode { Facter::FACTERVERSION.to_s } end diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb index 5ebc5f5..090ca63 100644 --- a/lib/facter/fqdn.rb +++ b/lib/facter/fqdn.rb @@ -1,3 +1,14 @@ +# Fact: fqdn +# +# Purpose: Returns the fully qualified domain name of the host. +# +# Resolution: Simply joins the hostname fact with the domain name fact. +# +# Caveats: No attempt is made to check that the two facts are accurate or that +# the two facts go together. At no point is there any DNS resolution made +# either. +# + Facter.add(:fqdn) do setcode do host = Facter.value(:hostname) diff --git a/lib/facter/hardwareisa.rb b/lib/facter/hardwareisa.rb index 23f7d08..9d0830e 100644 --- a/lib/facter/hardwareisa.rb +++ b/lib/facter/hardwareisa.rb @@ -1,3 +1,15 @@ +# Fact: hardwareisa +# +# Purpose: +# Returns hardware processor type. +# +# Resolution: +# On Solaris, Linux and the BSDs simply uses the output of "uname -p" +# +# Caveats: +# Some linuxes return unknown to uname -p with relative ease. +# + Facter.add(:hardwareisa) do setcode 'uname -p', '/bin/sh' confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS GNU/kFreeBSD} diff --git a/lib/facter/hardwaremodel.rb b/lib/facter/hardwaremodel.rb index 6201bdd..8f52fef 100644 --- a/lib/facter/hardwaremodel.rb +++ b/lib/facter/hardwaremodel.rb @@ -1,3 +1,16 @@ +# Fact: hardwaremodel +# +# Purpose: +# Returns the hardware model of the system. +# +# Resolution: +# Uses purely "uname -m" on all platforms other than AIX and Windows. +# On AIX uses the parsed "modelname" output of "lsattr -El sys0 -a modelname". +# On Windows uses the 'host_cpu' pulled out of Ruby's config. +# +# Caveats: +# + Facter.add(:hardwaremodel) do setcode 'uname -m' end diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb index 188efa4..0dcd01c 100644 --- a/lib/facter/hostname.rb +++ b/lib/facter/hostname.rb @@ -1,3 +1,16 @@ +# Fact: hostname +# +# Purpose: Return the system's short hostname. +# +# Resolution: +# On all system bar Darwin, parses the output of the "hostname" system command +# to everything before the first period. +# On Darwin, uses the system configuration util to get the LocalHostName +# variable. +# +# Caveats: +# + Facter.add(:hostname, :ldapname => "cn") do setcode do hostname = nil diff --git a/lib/facter/id.rb b/lib/facter/id.rb index 1c42284..cc0a0a6 100644 --- a/lib/facter/id.rb +++ b/lib/facter/id.rb @@ -1,3 +1,16 @@ +# Fact: id +# +# Purpose: Internal fact used to specity the program to return the currently +# running user id. +# +# Resolution: +# On all Unixes bar Solaris, just returns "whoami". +# On Solaris, parses the output of the "id" command to grab the username, as +# Solaris doesn't have the whoami command. +# +# Caveats: +# + Facter.add(:id) do setcode "whoami" end diff --git a/lib/facter/interfaces.rb b/lib/facter/interfaces.rb index 4fbaef1..04b1c19 100644 --- a/lib/facter/interfaces.rb +++ b/lib/facter/interfaces.rb @@ -1,3 +1,12 @@ +# Fact: interfaces +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + # interfaces.rb # Try to get additional Facts about the machine's network interfaces # diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb index d563408..5260504 100644 --- a/lib/facter/ipaddress.rb +++ b/lib/facter/ipaddress.rb @@ -1,3 +1,27 @@ +# Fact: ipaddress +# +# Purpose: Return the main IP address for a host. +# +# Resolution: +# On the Unixes does an ifconfig, and returns the first non 127.0.0.0/8 +# subnetted IP it finds. +# On Windows, it attempts to use the socket library and resolve the machine's +# hostname via DNS. +# +# On LDAP based hosts it tries to use either the win32/resolv library to +# resolve the hostname to an IP address, or on Unix, it uses the resolv +# library. +# +# As a fall back for undefined systems, it tries to run the "host" command to +# resolve the machine's hostname using the system DNS. +# +# Caveats: +# DNS resolution relies on working DNS infrastructure and resolvers on the +# host system. +# The ifconfig parsing purely takes the first IP address it finds without any +# checking this is a useful IP address. +# + Facter.add(:ipaddress) do confine :kernel => :linux setcode do diff --git a/lib/facter/ipaddress6.rb b/lib/facter/ipaddress6.rb index 547d636..b494b9d 100644 --- a/lib/facter/ipaddress6.rb +++ b/lib/facter/ipaddress6.rb @@ -1,17 +1,26 @@ +# Fact: ipaddress6 +# +# Purpose: Returns the "main" IPv6 IP address of a system. +# +# Resolution: +# OS dependant code that parses the output of various networking +# tools and currently not very intelligent. Returns the first +# non-loopback and non-linklocal address found in the ouput unless +# a default route can be mapped to a routeable interface. Guessing +# an interface is currently only possible with BSD type systems +# to many assumptions have to be made on other platforms to make +# this work with the current code. Most code ported or modeled +# after the ipaddress fact for the sake of similar functionality +# and familiar mechanics. +# +# Caveats: +# + # Cody Herriges # # Used the ipaddress fact that is already part of # Facter as a template. -# OS dependant code that parses the output of various networking -# tools and currently not very intelligent. Returns the first -# non-loopback and non-linklocal address found in the ouput unless -# a default route can be mapped to a routeable interface. Guessing -# an interface is currently only possible with BSD type systems -# to many assumptions have to be made on other platforms to make -# this work with the current code. Most code ported or modeled -# after the ipaddress fact for the sake of similar functionality -# and familiar mechanics. Facter.add(:ipaddress6) do confine :kernel => :linux setcode do diff --git a/lib/facter/iphostnumber.rb b/lib/facter/iphostnumber.rb index bc38432..cddaadd 100644 --- a/lib/facter/iphostnumber.rb +++ b/lib/facter/iphostnumber.rb @@ -1,3 +1,14 @@ +# Fact: iphostnumber +# +# Purpose: On selected versions of Darwin, returns the host's IP address. +# +# Resolution: +# Uses either the scutil program to get the localhost name, or parses output +# of ifconfig for a MAC address. +# +# Caveats: +# + Facter.add(:iphostnumber) do confine :kernel => :darwin, :kernelrelease => "R6" setcode do diff --git a/lib/facter/kernel.rb b/lib/facter/kernel.rb index 66f21ce..f457e01 100644 --- a/lib/facter/kernel.rb +++ b/lib/facter/kernel.rb @@ -1,3 +1,14 @@ +# Fact: kernel +# +# Purpose: Returns the operating system's name. +# +# Resolution: +# Uses Ruby's rbconfig to find host_os, if that is a Windows derivative, the +# returns 'windows', otherwise returns "uname -s" verbatim. +# +# Caveats: +# + Facter.add(:kernel) do setcode do require 'rbconfig' diff --git a/lib/facter/kernelmajversion.rb b/lib/facter/kernelmajversion.rb index 32fd7aa..84f71d4 100644 --- a/lib/facter/kernelmajversion.rb +++ b/lib/facter/kernelmajversion.rb @@ -1,3 +1,13 @@ +# Fact: kernelmajversion +# +# Purpose: Return the operating system's release number's major value. +# +# Resolution: +# Takes the first 2 elements of the kernel version as delimited by periods. +# +# Caveats: +# + Facter.add("kernelmajversion") do setcode do Facter.value(:kernelversion).split('.')[0..1].join('.') diff --git a/lib/facter/kernelrelease.rb b/lib/facter/kernelrelease.rb index 2f6ae45..a6f9c2c 100644 --- a/lib/facter/kernelrelease.rb +++ b/lib/facter/kernelrelease.rb @@ -1,3 +1,16 @@ +# Fact: kernelrelease +# +# Purpose: Return the operating system's release number. +# +# Resolution: +# On AIX returns the output from the "oslevel -s" system command. +# On Windows based systems, uses the win32ole gem to query Windows Management +# for the 'Win32_OperatingSystem' value. +# Otherwise uses the output of "uname -r" system command. +# +# Caveats: +# + Facter.add(:kernelrelease) do setcode 'uname -r' end diff --git a/lib/facter/kernelversion.rb b/lib/facter/kernelversion.rb index cac6c14..7e0d95c 100644 --- a/lib/facter/kernelversion.rb +++ b/lib/facter/kernelversion.rb @@ -1,3 +1,15 @@ +# Fact: kernelversion +# +# Purpose: Return the operating system's kernel version. +# +# Resolution: +# On Solaris and SunOS based machines, returns the output of "uname -v". +# Otherwise returns the 'kernerlversion' fact up to the first '-'. This may be +# the entire 'kernelversion' fact in many cases. +# +# Caveats: +# + Facter.add("kernelversion") do setcode do Facter['kernelrelease'].value.split('-')[0] diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index bf4b9db..107419a 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb @@ -1,3 +1,16 @@ +# Fact: lsb +# +# Purpose: Return Linux Standard Base information for the host. +# +# Resolution: +# Uses the lsb_release system command and parses the output with a series of +# regular expressions. +# +# Caveats: +# Only works on Linux (and the kfreebsd derivative) systems. +# Requires the lsb_release program, which may not be installed by default. +# Also is as only as accurate as that program outputs. + ## lsb.rb ## Facts related to Linux Standard Base (LSB) ## diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb index 34a2f1e..3659541 100644 --- a/lib/facter/lsbmajdistrelease.rb +++ b/lib/facter/lsbmajdistrelease.rb @@ -1,3 +1,15 @@ +# Fact: lsbmajdistrelease +# +# Purpose: Returns the major version of the operation system version as gleaned +# from the lsbdistrelease fact. +# +# Resolution: +# Parses the lsbdistrelease fact for numbers followed by a period and +# returns those, or just the lsbdistrelease fact if none were found. +# +# Caveats: +# + # lsbmajdistrelease.rb # require 'facter' diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index bf23ef6..54c3c84 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -1,3 +1,12 @@ +# Fact: macaddress +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + require 'facter/util/macaddress' Facter.add(:macaddress) do diff --git a/lib/facter/macosx.rb b/lib/facter/macosx.rb index 3841c50..f5289df 100644 --- a/lib/facter/macosx.rb +++ b/lib/facter/macosx.rb @@ -1,3 +1,16 @@ +# Fact: macosx +# +# Purpose: +# Returns a number of Mac specific facts, from system profiler and +# sw_vers. +# +# Resolution: +# Uses util/macosx.rb to do the fact reconnaissance, then outputs them +# preceded by 'sp_' +# +# Caveats: +# + # # macosx.rb # Additional Facts coming from Mac OS X system_profiler command diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb index 4f2df98..26aef5f 100644 --- a/lib/facter/manufacturer.rb +++ b/lib/facter/manufacturer.rb @@ -1,3 +1,16 @@ +# Fact: manufacturer +# +# Purpose: Return the hardware manufacturer information about the hardware. +# +# Resolution: +# On OpenBSD, queries sysctl values, via a util class. +# On SunOS Sparc, uses prtdiag via a util class. +# On Windows, queries the system via a util class. +# Uses the 'util/manufacturer.rb' for fallback parsing. +# +# Caveats: +# + # manufacturer.rb # Facts related to hardware manufacturer # diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index 0aa5e88..992f2ad 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -1,3 +1,20 @@ +# Fact: memory +# +# Purpose: Return information about memory and swap usage. +# +# Resolution: +# On Linuxes, uses Facter::Memory.meminfo_number from +# 'facter/util/memory.rb' +# On AIX, parses "swap -l" for swap values only. +# On OpenBSD, it parses "swapctl -l" for swap values, vmstat via a module for +# free memory, and "sysctl hw.physmem" for maximum memory. +# On Solaris, use "swap -l" for swap values, and parsing prtconf for maximum +# memory, and again, the vmstat module for free memory. +# +# Caveats: +# Some BSD platforms aren't covered at all. AIX is missing memory values. +# + # memory.rb # Additional Facts for memory/swap usage # diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb index d6d125e..fbb84f5 100644 --- a/lib/facter/netmask.rb +++ b/lib/facter/netmask.rb @@ -1,3 +1,12 @@ +# Fact: netmask +# +# Purpose: Returns the netmask for the main interfaces. +# +# Resolution: Uses the facter/util/netmask library routines. +# +# Caveats: +# + # netmask.rb # Find the netmask of the primary ipaddress # Copyright (C) 2007 David Schmitt diff --git a/lib/facter/network.rb b/lib/facter/network.rb index df53ce4..d4faaac 100644 --- a/lib/facter/network.rb +++ b/lib/facter/network.rb @@ -1,3 +1,15 @@ +# Fact: network +# +# Purpose: +# Get IP, network and netmask information for available network +# interfacs. +# +# Resolution: +# Uses 'facter/util/ip' to enumerate interfaces and return their information. +# +# Caveats: +# + require 'facter/util/ip' Facter::Util::IP.get_interfaces.each do |interface| diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index 25eeb00..a90c283 100644 --- a/lib/facter/operatingsystem.rb +++ b/lib/facter/operatingsystem.rb @@ -1,3 +1,16 @@ +# Fact: operatingsystem +# +# Purpose: Return the name of the operating system. +# +# Resolution: +# If the kernel is a Linux kernel, check for the existence of a selection of +# files in /etc/ to find the specific flavour. +# On SunOS based kernels, return Solaris. +# On systems other than Linux, use the kernel value. +# +# Caveats: +# + require 'facter/lsb' Facter.add(:operatingsystem) do diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb index da1b76a..347fe7f 100644 --- a/lib/facter/operatingsystemrelease.rb +++ b/lib/facter/operatingsystemrelease.rb @@ -1,3 +1,20 @@ +# Fact: operatingsystemrelease +# +# Purpose: Returns the release of the operating system. +# +# Resolution: +# On RedHat derivatives, returns their '/etc/-release' file. +# On Debian, returns '/etc/debian_version'. +# On Ubuntu, parses '/etc/issue' for the release version. +# On Suse, derivatives, parses '/etc/SuSE-release' for a selection of version +# information. +# On Slackware, parses '/etc/slackware-version'. +# +# On all remaining systems, returns the 'kernelrelease' value. +# +# Caveats: +# + Facter.add(:operatingsystemrelease) do confine :operatingsystem => %w{CentOS Fedora oel ovs RedHat MeeGo} setcode do diff --git a/lib/facter/path.rb b/lib/facter/path.rb index 03907c0..71df6cd 100644 --- a/lib/facter/path.rb +++ b/lib/facter/path.rb @@ -1,3 +1,12 @@ +# Fact: path +# +# Purpose: Returns the $PATH variable. +# +# Resolution: Gets $PATH from the environment. +# +# Caveats: +# + Facter.add(:path) do setcode do ENV['PATH'] diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 8fe643e..9c59614 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -1,3 +1,14 @@ +# Fact: physicalprocessorcount +# +# Purpose: Return the number of physical processors. +# +# Resolution: +# On linux, parses the output of '/proc/cpuinfo' for the number of unique +# lines with "physical id" in them. +# +# Caveats: +# + Facter.add("physicalprocessorcount") do confine :kernel => :linux diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb index c71bad4..ec196b2 100644 --- a/lib/facter/processor.rb +++ b/lib/facter/processor.rb @@ -1,5 +1,18 @@ +# Fact: processor +# +# Purpose: +# Additional Facts about the machine's CPUs. +# +# Resolution: +# On Linux and kFreeBSD, parse '/proc/cpuinfo' for each processor. +# On AIX, parse the output of 'lsdev' for it's processor section. +# On OpenBSD, use 'uname -p' and the sysctl variable for 'hw.ncpu' for CPU +# count. +# +# Caveats: +# + # processor.rb -# Additional Facts about the machine's CPUs # # Copyright (C) 2006 Mooter Media Ltd # Author: Matthew Palmer diff --git a/lib/facter/ps.rb b/lib/facter/ps.rb index e7bcdae..ef803fb 100644 --- a/lib/facter/ps.rb +++ b/lib/facter/ps.rb @@ -1,3 +1,15 @@ +# Fact: ps +# +# Purpose: Internal fact for what to use to list all processes. Used by +# Service{} type in Puppet. +# +# Resolution: +# Assumes "ps -ef" for all operating systems other than BSD derivatives, where +# it uses "ps auxwww" +# +# Caveats: +# + Facter.add(:ps) do setcode do 'ps -ef' end end diff --git a/lib/facter/puppetversion.rb b/lib/facter/puppetversion.rb index d2eb1f3..01422f0 100644 --- a/lib/facter/puppetversion.rb +++ b/lib/facter/puppetversion.rb @@ -1,3 +1,13 @@ +# Fact: puppetversion +# +# Purpose: Return the version of puppet installed. +# +# Resolution: +# Requres puppet via Ruby and returns it's version constant. +# +# Caveats: +# + Facter.add(:puppetversion) do setcode do begin diff --git a/lib/facter/rubysitedir.rb b/lib/facter/rubysitedir.rb index c205322..9973329 100644 --- a/lib/facter/rubysitedir.rb +++ b/lib/facter/rubysitedir.rb @@ -1,3 +1,13 @@ +# Fact: rubysitedir +# +# Purpose: Returns Ruby's site library directory. +# +# Resolution: Works out the version to major/minor (1.8, 1.9, etc), then joins +# that with all the $: library paths. +# +# Caveats: +# + Facter.add :rubysitedir do setcode do version = RUBY_VERSION.to_s.sub(/\.\d+$/, '') diff --git a/lib/facter/rubyversion.rb b/lib/facter/rubyversion.rb index 48f5cc8..e578400 100644 --- a/lib/facter/rubyversion.rb +++ b/lib/facter/rubyversion.rb @@ -1,3 +1,12 @@ +# Fact: rubyversion +# +# Purpose: Returns the version of Ruby facter is running under. +# +# Resolution: Returns RUBY_VERSION. +# +# Caveats: +# + Facter.add(:rubyversion) do setcode { RUBY_VERSION.to_s } end diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb index 9fab427..1555da0 100644 --- a/lib/facter/selinux.rb +++ b/lib/facter/selinux.rb @@ -1,3 +1,12 @@ +# Fact: selinux +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + # Fact for SElinux # Written by immerda admin team (admin(at)immerda.ch) diff --git a/lib/facter/ssh.rb b/lib/facter/ssh.rb index 318e9d4..beb5692 100644 --- a/lib/facter/ssh.rb +++ b/lib/facter/ssh.rb @@ -1,3 +1,12 @@ +# Fact: ssh +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + ## ssh.rb ## Facts related to SSH ## diff --git a/lib/facter/timezone.rb b/lib/facter/timezone.rb index 744e06a..462c9ba 100644 --- a/lib/facter/timezone.rb +++ b/lib/facter/timezone.rb @@ -1,3 +1,12 @@ +# Fact: timezone +# +# Purpose: Return the machine's time zone. +# +# Resolution: Uses's Ruby's Time module's Time.new call. +# +# Caveats: +# + Facter.add("timezone") do setcode do Time.new.zone diff --git a/lib/facter/uptime.rb b/lib/facter/uptime.rb index 56a959b..7aeeb39 100644 --- a/lib/facter/uptime.rb +++ b/lib/facter/uptime.rb @@ -1,3 +1,14 @@ +# Fact: uptime +# +# Purpose: return the system uptime in a human readable format. +# +# Resolution: +# Does basic maths on the "uptime_seconds" fact to return a count of +# days, hours and minutes of uptime +# +# Caveats: +# + require 'facter/util/uptime' Facter.add(:uptime) do diff --git a/lib/facter/uptime_days.rb b/lib/facter/uptime_days.rb index add305c..25af966 100644 --- a/lib/facter/uptime_days.rb +++ b/lib/facter/uptime_days.rb @@ -1,3 +1,12 @@ +# Fact: uptime_days +# +# Purpose: Return purely number of days of uptime. +# +# Resolution: Divides uptime_hours fact by 24. +# +# Caveats: +# + Facter.add(:uptime_days) do setcode do hours = Facter.value(:uptime_hours) diff --git a/lib/facter/uptime_hours.rb b/lib/facter/uptime_hours.rb index ce691d2..d02ac32 100644 --- a/lib/facter/uptime_hours.rb +++ b/lib/facter/uptime_hours.rb @@ -1,3 +1,12 @@ +# Fact: uptime_hours +# +# Purpose: Return purely number of hours of uptime. +# +# Resolution: Divides uptime_seconds fact by 3600. +# +# Caveats: +# + Facter.add(:uptime_hours) do setcode do seconds = Facter.value(:uptime_seconds) diff --git a/lib/facter/uptime_seconds.rb b/lib/facter/uptime_seconds.rb index 14bb573..9793e41 100644 --- a/lib/facter/uptime_seconds.rb +++ b/lib/facter/uptime_seconds.rb @@ -1,3 +1,17 @@ +# Fact: uptime_seconds +# +# Purpose: Return purely number of seconds of uptime. +# +# Resolution: +# Using the 'facter/util/uptime.rb' module, try a verity of methods to acquire +# the uptime on Unix. +# +# On Windows, the module calculates the uptime by the "LastBootupTime" Windows +# management value. +# +# Caveats: +# + require 'facter/util/uptime' Facter.add(:uptime_seconds) do diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 468ab77..02802e6 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -1,3 +1,30 @@ +# Fact: virtual +# +# Purpose: Determine if the system's hardware is real or virtualised. +# +# Resolution: +# Assumes physical unless proven otherwise. +# +# On Darwin, use the macosx util module to acquire the SPDisplaysDataType, +# from that parse it to see if it's VMWare or Parallels pretending to be the +# display. +# +# On Linux, BSD, Solaris and HPUX: +# Much of the logic here is obscured behind util/virtual.rb, which rather +# than document here, which would encourage drift, just refer to it. +# The Xen tests in here rely on /sys and /proc, and check for the presence and +# contents of files in there. +# If after all the other tests, it's still seen as physical, then it tries to +# parse the output of the "lspci", "dmidecode" and "prtdiag" and parses them +# for obvious signs of being under VMWare or Parallels. +# Finally it checks for the existence of vmware-vmx, which would hint it's +# VMWare. +# +# Caveats: +# Virtualbox detection isn't implemented. +# Many checks rely purely on existence of files. +# + require 'facter/util/virtual' Facter.add("virtual") do @@ -108,6 +135,17 @@ Facter.add("virtual") do end end +# Fact: is_virtual +# +# Purpose: returning true or false for if a machine is virtualised or not. +# +# Resolution: The Xen domain 0 machine is virtualised to a degree, but is generally +# not viewed as being a virtual machine. This checks that the machine is not +# physical nor xen0, if that is the case, it is virtual. +# +# Caveats: +# + Facter.add("is_virtual") do confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD} diff --git a/lib/facter/vlans.rb b/lib/facter/vlans.rb index d65bdd8..8c485a4 100644 --- a/lib/facter/vlans.rb +++ b/lib/facter/vlans.rb @@ -1,3 +1,13 @@ +# Fact: vlans +# +# Purpose: On Linux, return a list of all the VLANs on the system. +# +# Resolution: On Linux only, checks for and reads /proc/net/vlan/config and +# parses it. +# +# Caveats: +# + require 'facter/util/vlans' Facter.add("vlans") do diff --git a/lib/facter/xendomains.rb b/lib/facter/xendomains.rb index 972ac90..5bcde05 100644 --- a/lib/facter/xendomains.rb +++ b/lib/facter/xendomains.rb @@ -1,3 +1,14 @@ +# Fact: xendomains +# +# Purpose: Return the list of Xen domains on the Dom0. +# +# Resolution: +# On a Xen Dom0 host, return a list of Xen domains using the 'util/xendomains' +# library. +# +# Caveats: +# + require 'facter/util/xendomains' Facter.add("xendomains") do -- cgit From 7c80172fa79105c642f327c59b69f23be2153bb1 Mon Sep 17 00:00:00 2001 From: Ben Hughes Date: Tue, 29 Mar 2011 13:38:44 +1100 Subject: (#6883) Update Facter install.rb to be slightly more informative. Give slightly more information to the user when installing facter and the pre-requisite Ruby libraries are not installed. In the case of OpenSSL, the user can have OpenSSL installed, and not the gem/library, but the error message given in no way hints to this. --- install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.rb b/install.rb index eb91e7c..d4793eb 100755 --- a/install.rb +++ b/install.rb @@ -119,7 +119,7 @@ def check_prereqs begin require pre rescue LoadError - puts "Could not load %s; cannot install" % pre + puts "Could not load #{pre} Ruby library; cannot install" exit -1 end } -- cgit From 3efa9d717572d7a9a2136c50cd863ff9d4c27372 Mon Sep 17 00:00:00 2001 From: Michael Kincaid Date: Thu, 31 Mar 2011 16:04:57 -0700 Subject: (#3856) Add virtualbox detection via lspci (graphics card), dmidecode, and prtdiag for Solaris and corresponding tests. Darwin case is not handled yet. --- lib/facter/virtual.rb | 5 +++++ spec/unit/virtual_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 02802e6..7c649ba 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -104,6 +104,9 @@ Facter.add("virtual") do # --- look for the vmware video card to determine if it is virtual => vmware. # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter result = "vmware" if p =~ /VM[wW]are/ + # --- look for virtualbox video card to determine if it is virtual => virtualbox. + # --- 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter + result = "virtualbox" if p =~ /VirtualBox/ # --- look for pci vendor id used by Parallels video card # --- 01:00.0 VGA compatible controller: Unknown device 1ab8:4005 result = "parallels" if p =~ /1ab8:|[Pp]arallels/ @@ -114,6 +117,7 @@ Facter.add("virtual") do output.each_line do |pd| result = "parallels" if pd =~ /Parallels/ result = "vmware" if pd =~ /VMware/ + result = "virtualbox" if pd =~ /VirtualBox/ end else output = Facter::Util::Resolution.exec('prtdiag') @@ -121,6 +125,7 @@ Facter.add("virtual") do output.each_line do |pd| result = "parallels" if pd =~ /Parallels/ result = "vmware" if pd =~ /VMware/ + result = "virtualbox" if pd =~ /VirtualBox/ end end end diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index 7e50847..ac0a9bb 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -94,6 +94,12 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "vmware" end + it "should be virtualbox with VirtualBox vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter") + Facter.fact(:virtual).value.should == "virtualbox" + end + it "should be vmware with VMWare vendor name from dmidecode" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) @@ -108,6 +114,13 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "parallels" end + it "should be virtualbox with VirtualBox vendor name from dmidecode" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("BIOS Information\nVendor: innotek GmbH\nVersion: VirtualBox\n\nSystem Information\nManufacturer: innotek GmbH\nProduct Name: VirtualBox\nFamily: Virtual Machine") + Facter.fact(:virtual).value.should == "virtualbox" + end + it "should be vmware with VMWare vendor name from prtdiag" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) @@ -123,6 +136,14 @@ describe "Virtual fact" do Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform") Facter.fact(:virtual).value.should == "parallels" end + + it "should be virtualbox with VirtualBox vendor name from prtdiag" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox") + Facter.fact(:virtual).value.should == "virtualbox" + end end end @@ -152,6 +173,12 @@ describe "is_virtual fact" do Facter.fact(:is_virtual).value.should == "true" end + it "should be true when running on virtualbox" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("virtualbox") + Facter.fact(:is_virtual).value.should == "true" + end + it "should be true when running on openvz" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter.fact(:virtual).stubs(:value).returns("openvzve") -- cgit From cb52b06d4ce0bc2d7b7f6dbfb8ff2a882b63d107 Mon Sep 17 00:00:00 2001 From: Krzysztof Wilczynski Date: Sun, 2 Jan 2011 03:27:59 +0000 Subject: Fix. Using sysfs file system entries to count the number of physical CPUs. Fall-back to "/proc/cpuinfo" included for backward-compatibility with legacy systems. --- lib/facter/physicalprocessorcount.rb | 45 +++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 9c59614..86d0749 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -3,16 +3,49 @@ # Purpose: Return the number of physical processors. # # Resolution: -# On linux, parses the output of '/proc/cpuinfo' for the number of unique -# lines with "physical id" in them. +# Attempts to use sysfs to get the physical IDs of the processors. Falls +# back to /proc/cpuinfo and "physical id" if sysfs is not available. # # Caveats: # -Facter.add("physicalprocessorcount") do - confine :kernel => :linux +Facter.add('physicalprocessorcount') do + confine :kernel => :linux - setcode do - ppcount = Facter::Util::Resolution.exec('grep "physical id" /proc/cpuinfo|cut -d: -f 2|sort -u|wc -l') + setcode do + sysfs_cpu_directory = '/sys/devices/system/cpu' # This should always be there ... + + if File.exists?(sysfs_cpu_directory) + # + # We assume that the sysfs file system has the correct number of entries + # under the "/sys/device/system/cpu" directory and if so then we process + # content of the file "physical_package_id" located inside the "topology" + # directory in each of the per-CPU sub-directories. + # + # As per Linux Kernel documentation and the file "cputopology.txt" located + # inside the "/usr/src/linux/Documentation" directory we can find following + # short explanation: + # + # (...) + # + # 1) /sys/devices/system/cpu/cpuX/topology/physical_package_id: + # + # physical package id of cpuX. Typically corresponds to a physical + # socket number, but the actual value is architecture and platform + # dependent. + # + # (...) + # + lookup_pattern = "#{sysfs_cpu_directory}/cpu*/topology/physical_package_id" + Dir[lookup_pattern].map { |i| File.read(i).strip }.uniq.size + else + # + # Try to count number of CPUs using the proc file system next ... + # + # We assume that /proc/cpuinfo has what we need and is so then we need + # to make sure that we only count unique entries ... + # + File.read('/proc/cpuinfo').scan(/physical.+:\s(\d+)/).uniq.size end + end end -- cgit From 0c4a98b2271ed5d84f2aa8783398f08502b578ee Mon Sep 17 00:00:00 2001 From: Krzysztof Wilczynski Date: Sun, 2 Jan 2011 04:24:42 +0000 Subject: Re-factor. Do not use pure-Ruby file reading against "/proc/cpuinfo" and possibly any entry under "/sys" from the sysfs file system. --- lib/facter/physicalprocessorcount.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 86d0749..144183c 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -36,8 +36,12 @@ Facter.add('physicalprocessorcount') do # # (...) # - lookup_pattern = "#{sysfs_cpu_directory}/cpu*/topology/physical_package_id" - Dir[lookup_pattern].map { |i| File.read(i).strip }.uniq.size + lookup_pattern = "#{sysfs_cpu_directory}" + + "/cpu*/topology/physical_package_id" + + Facter::Util::Resolution.exec( + "cat #{lookup_pattern}" + ).scan(/\d+/).uniq.size else # # Try to count number of CPUs using the proc file system next ... @@ -45,7 +49,9 @@ Facter.add('physicalprocessorcount') do # We assume that /proc/cpuinfo has what we need and is so then we need # to make sure that we only count unique entries ... # - File.read('/proc/cpuinfo').scan(/physical.+:\s(\d+)/).uniq.size + Facter::Util::Resolution.exec( + "grep 'physical.\\+:' /proc/cpuinfo" + ).scan(/\d+/).uniq.size end end end -- cgit From c2ff8330f4d705ded3f251e170df4bd973af3d43 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 15 Mar 2011 17:29:19 -0700 Subject: (#5135) Refactored physicalprocessorcount - Refactored code to make testing simpler --- lib/facter/physicalprocessorcount.rb | 14 ++++++----- spec/unit/physicalprocessorcount_spec.rb | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 spec/unit/physicalprocessorcount_spec.rb diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 144183c..cd5777c 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -39,9 +39,11 @@ Facter.add('physicalprocessorcount') do lookup_pattern = "#{sysfs_cpu_directory}" + "/cpu*/topology/physical_package_id" - Facter::Util::Resolution.exec( - "cat #{lookup_pattern}" - ).scan(/\d+/).uniq.size + ids = Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")} + + ids = ids.join if ids.is_a?(Array) + ids.scan(/\d+/).uniq.size + else # # Try to count number of CPUs using the proc file system next ... @@ -49,9 +51,9 @@ Facter.add('physicalprocessorcount') do # We assume that /proc/cpuinfo has what we need and is so then we need # to make sure that we only count unique entries ... # - Facter::Util::Resolution.exec( - "grep 'physical.\\+:' /proc/cpuinfo" - ).scan(/\d+/).uniq.size + str = Facter::Util::Resolution.exec("grep 'physical.\\+:' /proc/cpuinfo") + + if not str.nil? then str.scan(/\d+/).uniq.size; end end end end diff --git a/spec/unit/physicalprocessorcount_spec.rb b/spec/unit/physicalprocessorcount_spec.rb new file mode 100644 index 0000000..260788b --- /dev/null +++ b/spec/unit/physicalprocessorcount_spec.rb @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +require 'facter' + +describe "Physical processor count facts" do + before do + Facter.loadfacts + end + before do + Facter.clear + end + it "should return one physical CPU" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true) + Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns("/sys/devices/system/cpu/cpu0/topology/physical_package_id") + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0") + + Facter.fact(:physicalprocessorcount).value.should == 1 + end + + it "should return four physical CPUs" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true) + Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(%w{ + /sys/devices/system/cpu/cpu0/topology/physical_package_id + /sys/devices/system/cpu/cpu1/topology/physical_package_id + /sys/devices/system/cpu/cpu2/topology/physical_package_id + /sys/devices/system/cpu/cpu3/topology/physical_package_id + }) + + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0") + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu1/topology/physical_package_id").returns("1") + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu2/topology/physical_package_id").returns("2") + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu3/topology/physical_package_id").returns("3") + + Facter.fact(:physicalprocessorcount).value.should == 4 + end +end -- cgit From bfc16f6bb9ffbd0064300e647481aab83b7f6212 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 22 Mar 2011 11:20:27 -0700 Subject: (#2714) Added timeout to prtdiag resulution - prtdiag would hang in specific cases, subsequently hanging facter. This should kill prtdiag if it takes excessively long. --- lib/facter/virtual.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 7c649ba..2801a43 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -119,8 +119,11 @@ Facter.add("virtual") do result = "vmware" if pd =~ /VMware/ result = "virtualbox" if pd =~ /VirtualBox/ end - else - output = Facter::Util::Resolution.exec('prtdiag') + elsif Facter.value(:kernel) == 'SunOS' + res = Facter::Util::Resolution.new('prtdiag') + res.timeout = 6 + res.setcode('prtdiag') + output = res.value if not output.nil? output.each_line do |pd| result = "parallels" if pd =~ /Parallels/ -- cgit From 7f3e89de2d9da14bc7bef33709b79f48434eec6a Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 22 Mar 2011 12:40:16 -0700 Subject: (#2714) Fixed faulty test - Looks like some copy/paste added some linux tests that relied on prtdiag, which isn't possible. Corrected them to check against solaris. --- spec/unit/virtual_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index ac0a9bb..d169192 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -121,8 +121,10 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "virtualbox" end + end + describe "on Solaris" do it "should be vmware with VMWare vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:kernel).stubs(:value).returns("SunOS") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform") @@ -130,7 +132,7 @@ describe "Virtual fact" do end it "should be parallels with Parallels vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:kernel).stubs(:value).returns("SunOS") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform") @@ -138,7 +140,7 @@ describe "Virtual fact" do end it "should be virtualbox with VirtualBox vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:kernel).stubs(:value).returns("SunOS") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox") -- cgit From 7441b32f9e062f9ca73c9d452f0559aa866e0277 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 6 Apr 2011 03:04:02 +1000 Subject: Partial fix for #6971 - Fix for virtual tests --- spec/unit/virtual_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index d169192..f69c898 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -73,6 +73,7 @@ describe "Virtual fact" do before do FileTest.expects(:exists?).with("/usr/lib/vmware/bin/vmware-vmx").returns false + Facter.fact(:operatingsystem).stubs(:value).returns(true) Facter.fact(:architecture).stubs(:value).returns(true) end @@ -127,7 +128,7 @@ describe "Virtual fact" do Facter.fact(:kernel).stubs(:value).returns("SunOS") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform") + Facter::Util::Resolution.stubs(:exec).with('prtdiag', '/bin/sh').returns("System Configuration: VMware, Inc. VMware Virtual Platform") Facter.fact(:virtual).value.should == "vmware" end @@ -135,7 +136,7 @@ describe "Virtual fact" do Facter.fact(:kernel).stubs(:value).returns("SunOS") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform") + Facter::Util::Resolution.stubs(:exec).with('prtdiag', '/bin/sh').returns("System Configuration: Parallels Virtual Platform") Facter.fact(:virtual).value.should == "parallels" end @@ -143,7 +144,7 @@ describe "Virtual fact" do Facter.fact(:kernel).stubs(:value).returns("SunOS") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox") + Facter::Util::Resolution.stubs(:exec).with('prtdiag', '/bin/sh').returns("System Configuration: innotek GmbH VirtualBox") Facter.fact(:virtual).value.should == "virtualbox" end end -- cgit From 9f4c5c6ac79821700bf4e6beee81f3d865396f4b Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Fri, 11 Mar 2011 12:23:23 +0000 Subject: (#6740) facter doesn't always respect facts in environment variables On an OSX host: $ facter operatingsystem Darwin $ facter_operatingsystem=Not_Darwin facter operatingsystem Not_Darwin But on a linux/solaris host: $ facter operatingsystem CentOS $ facter_operatingsystem=Not_CentOS facter operatingsystem CentOS As the operatingsystem fact resolution for linux-based kernels has higher precedence than the environment variable as it has more matching confines than the value from the environment variable. This patch adds from_environment to the resolution mechanism, which makes the resolution have an artificially high weight by claiming the length of its confines array is 1 billion. --- lib/facter/util/loader.rb | 1 + lib/facter/util/resolution.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/facter/util/loader.rb b/lib/facter/util/loader.rb index 2d2d9e8..b6aa8de 100644 --- a/lib/facter/util/loader.rb +++ b/lib/facter/util/loader.rb @@ -90,6 +90,7 @@ class Facter::Util::Loader next if fact and env_name != fact Facter.add($1) do + from_environment setcode { value } end diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb index 4a99c35..2ca2447 100644 --- a/lib/facter/util/resolution.rb +++ b/lib/facter/util/resolution.rb @@ -85,17 +85,29 @@ class Facter::Util::Resolution end end + # Say this resolution came from the environment + def from_environment + @from_environment = true + end + # Create a new resolution mechanism. def initialize(name) @name = name @confines = [] @value = nil @timeout = 0 + @from_environment = false end # Return the number of confines. def length - @confines.length + # If the resolution came from an environment variable + # say we're very very sure about the value of the resolution + if @from_environment + 1_000_000_000 + else + @confines.length + end end # We need this as a getter for 'timeout', because some versions -- cgit From d56bca8534bd21c046fd19a7fb2f776fe3e100b4 Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Fri, 18 Mar 2011 00:10:00 +0000 Subject: refactor the mechanism for allowing for resolution ordering to be influenced renames Facter::Util::Resolution#length to weight as a more generic mechanism for allowing resolutions to state their importance --- lib/facter/util/fact.rb | 4 +--- lib/facter/util/loader.rb | 2 +- lib/facter/util/resolution.rb | 17 +++++++---------- spec/unit/util/fact_spec.rb | 22 +++++++++++----------- spec/unit/util/resolution_spec.rb | 22 ++++++++++++++++++++-- 5 files changed, 40 insertions(+), 27 deletions(-) diff --git a/lib/facter/util/fact.rb b/lib/facter/util/fact.rb index e78ed97..935b3c1 100644 --- a/lib/facter/util/fact.rb +++ b/lib/facter/util/fact.rb @@ -41,9 +41,7 @@ class Facter::Util::Fact # Immediately sort the resolutions, so that we always have # a sorted list for looking up values. - # We always want to look them up in the order of number of - # confines, so the most restricted resolution always wins. - @resolves.sort! { |a, b| b.length <=> a.length } + @resolves.sort! { |a, b| b.weight <=> a.weight } return resolve end diff --git a/lib/facter/util/loader.rb b/lib/facter/util/loader.rb index b6aa8de..a52012c 100644 --- a/lib/facter/util/loader.rb +++ b/lib/facter/util/loader.rb @@ -90,7 +90,7 @@ class Facter::Util::Loader next if fact and env_name != fact Facter.add($1) do - from_environment + has_weight 1_000_000 setcode { value } end diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb index 2ca2447..d82fab2 100644 --- a/lib/facter/util/resolution.rb +++ b/lib/facter/util/resolution.rb @@ -85,9 +85,8 @@ class Facter::Util::Resolution end end - # Say this resolution came from the environment - def from_environment - @from_environment = true + def has_weight(weight) + @weight = weight end # Create a new resolution mechanism. @@ -96,15 +95,13 @@ class Facter::Util::Resolution @confines = [] @value = nil @timeout = 0 - @from_environment = false + @weight = nil end - # Return the number of confines. - def length - # If the resolution came from an environment variable - # say we're very very sure about the value of the resolution - if @from_environment - 1_000_000_000 + # Return the importance of this resolution. + def weight + if @weight + @weight else @confines.length end diff --git a/spec/unit/util/fact_spec.rb b/spec/unit/util/fact_spec.rb index db08670..523c855 100755 --- a/spec/unit/util/fact_spec.rb +++ b/spec/unit/util/fact_spec.rb @@ -56,10 +56,10 @@ describe Facter::Util::Fact do @fact.add { } end - it "should re-sort the resolutions by length, so the most restricted resolutions are first" do - r1 = stub 'r1', :length => 1 - r2 = stub 'r2', :length => 2 - r3 = stub 'r3', :length => 0 + it "should re-sort the resolutions by weight, so the most restricted resolutions are first" do + r1 = stub 'r1', :weight => 1 + r2 = stub 'r2', :weight => 2 + r3 = stub 'r3', :weight => 0 Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) @fact.add { } @fact.add { } @@ -83,9 +83,9 @@ describe Facter::Util::Fact do end it "should return the first value returned by a resolution" do - r1 = stub 'r1', :length => 2, :value => nil, :suitable? => true - r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true - r3 = stub 'r3', :length => 0, :value => "foo", :suitable? => true + r1 = stub 'r1', :weight => 2, :value => nil, :suitable? => true + r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true + r3 = stub 'r3', :weight => 0, :value => "foo", :suitable? => true Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) @fact.add { } @fact.add { } @@ -95,8 +95,8 @@ describe Facter::Util::Fact do end it "should short-cut returning the value once one is found" do - r1 = stub 'r1', :length => 2, :value => "foo", :suitable? => true - r2 = stub 'r2', :length => 1, :suitable? => true # would fail if 'value' were asked for + r1 = stub 'r1', :weight => 2, :value => "foo", :suitable? => true + r2 = stub 'r2', :weight => 1, :suitable? => true # would fail if 'value' were asked for Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) @fact.add { } @fact.add { } @@ -105,8 +105,8 @@ describe Facter::Util::Fact do end it "should skip unsuitable resolutions" do - r1 = stub 'r1', :length => 2, :suitable? => false # would fail if 'value' were asked for' - r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true + r1 = stub 'r1', :weight => 2, :suitable? => false # would fail if 'value' were asked for' + r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) @fact.add { } @fact.add { } diff --git a/spec/unit/util/resolution_spec.rb b/spec/unit/util/resolution_spec.rb index 581d0e1..3e13cdc 100755 --- a/spec/unit/util/resolution_spec.rb +++ b/spec/unit/util/resolution_spec.rb @@ -13,6 +13,10 @@ describe Facter::Util::Resolution do Facter::Util::Resolution.new("yay").name.should == "yay" end + it "should have a method for setting the weight" do + Facter::Util::Resolution.new("yay").should respond_to(:has_weight) + end + it "should have a method for setting the code" do Facter::Util::Resolution.new("yay").should respond_to(:setcode) end @@ -195,11 +199,25 @@ describe Facter::Util::Resolution do it "should provide a method for returning the number of confines" do @resolve = Facter::Util::Resolution.new("yay") @resolve.confine "one" => "foo", "two" => "fee" - @resolve.length.should == 2 + @resolve.weight.should == 2 end it "should return 0 confines when no confines have been added" do - Facter::Util::Resolution.new("yay").length.should == 0 + Facter::Util::Resolution.new("yay").weight.should == 0 + end + + it "should provide a way to set the weight" do + @resolve = Facter::Util::Resolution.new("yay") + @resolve.has_weight(45) + @resolve.weight.should == 45 + end + + it "should allow the weight to override the number of confines" do + @resolve = Facter::Util::Resolution.new("yay") + @resolve.confine "one" => "foo", "two" => "fee" + @resolve.weight.should == 2 + @resolve.has_weight(45) + @resolve.weight.should == 45 end it "should have a method for determining if it is suitable" do -- cgit From bfa038de95ef3642dd0c66ad7e662b5b0f189555 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 6 Apr 2011 03:21:50 +1000 Subject: Fixed #6974 - Moved to Apache 2.0 license This is in line with our proposed plan to change from the GPL license to Apache 2.0. Please see this link for further explanation: https://groups.google.com/d/topic/puppet-users/NuspYhMpE5o/discussion --- COPYING | 339 ---------------------------------------------- LICENSE | 24 ++-- README | 8 -- README.md | 24 ++++ README.rst | 26 ---- TODO | 4 - bin/facter | 4 +- conf/redhat/facter.spec | 2 +- lib/facter.rb | 25 ++-- lib/facter/Cfkey.rb | 11 -- lib/facter/lsb.rb | 12 -- lib/facter/macosx.rb | 11 -- lib/facter/ssh.rb | 11 -- lib/facter/util/macosx.rb | 11 -- lib/facter/util/memory.rb | 11 -- 15 files changed, 49 insertions(+), 474 deletions(-) delete mode 100644 COPYING delete mode 100644 README create mode 100644 README.md delete mode 100644 README.rst delete mode 100644 TODO diff --git a/COPYING b/COPYING deleted file mode 100644 index d511905..0000000 --- a/COPYING +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/LICENSE b/LICENSE index 308f4e0..9cd62ce 100644 --- a/LICENSE +++ b/LICENSE @@ -1,17 +1,15 @@ -Facter - Host Fact Detection and Reporting. Copyright (C) 2005 Reductive Labs LLC +Facter - Host Fact Detection and Reporting -Reductive Labs can be contacted at: info@reductivelabs.com +Copyright 2011 Puppet Labs Inc -This program and entire repository is free software; you can -redistribute it and/or modify it under the terms of the GNU -General Public License as published by the Free Software -Foundation; either version 2 of the License, or any later version. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +http://www.apache.org/licenses/LICENSE-2.0 -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README b/README deleted file mode 100644 index 683833f..0000000 --- a/README +++ /dev/null @@ -1,8 +0,0 @@ -This package is largely meant to be a library for collecting facts about your -system. These facts are mostly strings (i.e., not numbers), and are things -like the output of 'uname', public ssh and cfengine keys, the number of -processors, etc. - -See bin/facter for an example of the interface. - -See http://www.puppetlabs.com/puppet/related-projects/facter for more details. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5a5453 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +Facter +====== + +This package is largely meant to be a library for collecting facts about your +system. These facts are mostly strings (i.e., not numbers), and are things +like the output of `uname`, public ssh and cfengine keys, the number of +processors, etc. + +See `bin/facter` for an example of the interface. + +Running Facter +-------------- + +Run the `facter` binary on the command for a full list of facts supported on your host. + +Adding your own facts +--------------------- + +See the [Adding Facts](http://docs.puppetlabs.com/guides/custom_facts.html) page for details of how to add your own custom facts to Facter. + +Further Information +------------------- + +See http://www.puppetlabs.com/puppet/related-projects/facter for more details. diff --git a/README.rst b/README.rst deleted file mode 100644 index 2b71136..0000000 --- a/README.rst +++ /dev/null @@ -1,26 +0,0 @@ -Facter -====== - -This package is largely meant to be a library for collecting facts about your -system. These facts are mostly strings (i.e., not numbers), and are things -like the output of ``uname``, public ssh and cfengine keys, the number of -processors, etc. - -See ``bin/facter`` for an example of the interface. - -Running Facter -++++++++++++++ - -Run the ``facter`` binary on the command for a full list of facts supported on your host. - -Adding your own facts -+++++++++++++++++++++ - -See the `Adding Facts`_ page for details of how to add your own custom facts to Facter. - -Further Information -+++++++++++++++++++ - -See http://www.puppetlabs.com/puppet/related-projects/facter for more details. - -.. _Adding Facts: http://docs.puppetlabs.com/guides/custom_facts.html diff --git a/TODO b/TODO deleted file mode 100644 index 9389e45..0000000 --- a/TODO +++ /dev/null @@ -1,4 +0,0 @@ -More documentation. - -The ability to specify fact names with strings or symbols; right now, only -strings are supported diff --git a/bin/facter b/bin/facter index 622d72e..6c5d4ce 100755 --- a/bin/facter +++ b/bin/facter @@ -52,8 +52,8 @@ # # = Copyright # -# Copyright (c) 2006 Reductive Labs, LLC -# Licensed under the GNU Public License +# Copyright (c) 2011 Puppet Labs, Inc +# Licensed under the Apache 2.0 license require 'facter/application' diff --git a/conf/redhat/facter.spec b/conf/redhat/facter.spec index 1148fd3..99a6505 100644 --- a/conf/redhat/facter.spec +++ b/conf/redhat/facter.spec @@ -7,7 +7,7 @@ Summary: Ruby module for collecting simple facts about a host operating system Name: facter Version: 1.5.8 Release: 1%{?dist} -License: GPLv2+ +License: Apache 2.0 Group: System Environment/Base URL: http://www.puppetlabs.com/puppet/related-projects/%{name}/ Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}.tar.gz diff --git a/lib/facter.rb b/lib/facter.rb index 63eea37..2073b84 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -1,21 +1,18 @@ -#-- -# Copyright 2006 Luke Kanies +# Facter - Host Fact Detection and Reporting # -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. +# Copyright 2011 Puppet Labs Inc # -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# http://www.apache.org/licenses/LICENSE-2.0 # -#-- +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. module Facter # This is just so the other classes have the constant. diff --git a/lib/facter/Cfkey.rb b/lib/facter/Cfkey.rb index 8353392..e54aeb0 100644 --- a/lib/facter/Cfkey.rb +++ b/lib/facter/Cfkey.rb @@ -12,17 +12,6 @@ ## Cfkey.rb ## Facts related to cfengine ## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## Facter.add(:Cfkey) do setcode do diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index 107419a..7beb41d 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb @@ -13,18 +13,6 @@ ## lsb.rb ## Facts related to Linux Standard Base (LSB) -## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## { "LSBRelease" => %r{^LSB Version:\t(.*)$}, "LSBDistId" => %r{^Distributor ID:\t(.*)$}, diff --git a/lib/facter/macosx.rb b/lib/facter/macosx.rb index f5289df..7c8562d 100644 --- a/lib/facter/macosx.rb +++ b/lib/facter/macosx.rb @@ -18,17 +18,6 @@ # Copyright (C) 2007 Jeff McCune # Author: Jeff McCune # -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation (version 2 of the License) -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA - # Jeff McCune # There's a lot more information coming out of system_profiler -xml # We could add quite a bit more, but I didn't want to overload facter diff --git a/lib/facter/ssh.rb b/lib/facter/ssh.rb index beb5692..5ae68ed 100644 --- a/lib/facter/ssh.rb +++ b/lib/facter/ssh.rb @@ -10,17 +10,6 @@ ## ssh.rb ## Facts related to SSH ## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## ["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each do |dir| {"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_key.pub"}.each do |name,file| diff --git a/lib/facter/util/macosx.rb b/lib/facter/util/macosx.rb index 6754f18..cc9b2df 100644 --- a/lib/facter/util/macosx.rb +++ b/lib/facter/util/macosx.rb @@ -4,17 +4,6 @@ ## Copyright (C) 2007 Jeff McCune ## Author: Jeff McCune ## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## module Facter::Util::Macosx require 'thread' diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb index d86a423..d49079d 100644 --- a/lib/facter/util/memory.rb +++ b/lib/facter/util/memory.rb @@ -1,17 +1,6 @@ ## memory.rb ## Support module for memory related facts ## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## module Facter::Memory require 'thread' -- cgit From 53cd946685fe5790dbbe5b2a3964e6d861bbfdde Mon Sep 17 00:00:00 2001 From: Ohad Levy Date: Tue, 22 Mar 2011 23:04:23 +0200 Subject: Ensures that ARP facts are returned only on EC2 hosts ARP facts on large network might lead to inconstant values as we are always using the first ARP entry from the output of the ARP command Signed-off-by: Ohad Levy --- lib/facter/arp.rb | 12 ++++++++---- lib/facter/ec2.rb | 16 +++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/facter/arp.rb b/lib/facter/arp.rb index 5035ad0..0a7cf67 100644 --- a/lib/facter/arp.rb +++ b/lib/facter/arp.rb @@ -3,14 +3,17 @@ require 'facter/util/ip' Facter.add(:arp) do confine :kernel => :linux setcode do - arp = [] output = Facter::Util::Resolution.exec('arp -a') if not output.nil? + arp = "" output.each_line do |s| - arp.push($1) if s =~ /^\S+\s\S+\s\S+\s(\S+)\s\S+\s\S+\s\S+$/ + if s =~ /^\S+\s\S+\s\S+\s(\S+)\s\S+\s\S+\s\S+$/ + arp = $1 + break # stops on the first match + end end end - arp[0] + EC2_ARP == arp ? arp : nil end end @@ -18,7 +21,8 @@ Facter::Util::IP.get_interfaces.each do |interface| Facter.add("arp_" + Facter::Util::IP.alphafy(interface)) do confine :kernel => :linux setcode do - Facter::Util::IP.get_arp_value(interface) + arp = Facter::Util::IP.get_arp_value(interface) + EC2_ARP == arp ? arp : nil end end end diff --git a/lib/facter/ec2.rb b/lib/facter/ec2.rb index 29b2a1c..693e78e 100644 --- a/lib/facter/ec2.rb +++ b/lib/facter/ec2.rb @@ -6,9 +6,11 @@ require 'open-uri' require 'socket' -EC2_ADDR = "169.254.169.254" +EC2_ADDR = "169.254.169.254" EC2_METADATA_URL = "http://#{EC2_ADDR}/2008-02-01/meta-data" EC2_USERDATA_URL = "http://#{EC2_ADDR}/2008-02-01/user-data" +EC2_ARP = "fe:ff:ff:ff:ff:ff" +EC2_EUCA_MAC = %r{^[dD]0:0[dD]:} def can_metadata_connect?(addr, port, timeout=2) t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) @@ -61,19 +63,11 @@ def userdata() end def has_euca_mac? - if Facter.value(:macaddress) =~ /^[dD]0:0[dD]:/ - return true - else - return false - end + !!(Facter.value(:macaddress) =~ EC2_EUCA_MAC) end def has_ec2_arp? - if Facter.value(:arp) == 'fe:ff:ff:ff:ff:ff' - return true - else - return false - end + !!(Facter.value(:arp) == EC2_ARP) end if (has_euca_mac? || has_ec2_arp?) && can_metadata_connect?(EC2_ADDR,80) -- cgit From 5b10173364a56458e3f2e8a44298722cda9321e7 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 5 Apr 2011 12:18:11 -0700 Subject: (#5135) Fix faulty logic in physicalprocessorcount - Was doing unnessary string manipulation when all that needed to be done was a uniq'd array. - Removed some backwards way of nil checking. --- lib/facter/physicalprocessorcount.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index c6145dc..22c00c1 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -39,10 +39,7 @@ Facter.add('physicalprocessorcount') do lookup_pattern = "#{sysfs_cpu_directory}" + "/cpu*/topology/physical_package_id" - ids = Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")} - - ids = ids.join if ids.is_a?(Array) - ids.scan(/\d+/).uniq.size + Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")}.uniq.size else # @@ -53,7 +50,7 @@ Facter.add('physicalprocessorcount') do # str = Facter::Util::Resolution.exec("grep 'physical.\\+:' /proc/cpuinfo") - if not str.nil? then str.scan(/\d+/).uniq.size; end + if str then str.scan(/\d+/).uniq.size; end end end end -- cgit From 19f96b59081558eefd613770fdf8c5f5665a150b Mon Sep 17 00:00:00 2001 From: Ben Hughes Date: Thu, 7 Apr 2011 11:33:09 +1000 Subject: (#6728) Facter improperly detects openvzve on CloudLinux systems Make the openvz check for more than just the vz directory to be sure it's OpenVZ. Update the OpenVZ fact to be slightly more resilient in it's checking of OpenVZ, so it doesn't clash with CloudLinux's LVE container system. --- lib/facter/util/virtual.rb | 2 +- spec/unit/util/virtual_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index 4355451..8bdde16 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb @@ -1,6 +1,6 @@ module Facter::Util::Virtual def self.openvz? - FileTest.directory?("/proc/vz") + FileTest.directory?("/proc/vz") and FileTest.exists?( '/proc/vz/veinfo' ) end def self.openvz_type diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb index aa2de5a..36e1bf1 100644 --- a/spec/unit/util/virtual_spec.rb +++ b/spec/unit/util/virtual_spec.rb @@ -9,6 +9,7 @@ describe Facter::Util::Virtual do end it "should detect openvz" do FileTest.stubs(:directory?).with("/proc/vz").returns(true) + FileTest.stubs(:exists?).with("/proc/vz/veinfo").returns(true) Facter::Util::Virtual.should be_openvz end -- cgit From 21fe2176f6a688da14d8382806787b6072ae1ed1 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Thu, 14 Apr 2011 11:27:22 -0700 Subject: (#6612) Changed uptime spec to be endian agnostic The sysctl uptime fixture was little endian, which fails on sparc hardware. Added a big endian fixture and endian detection. --- spec/fixtures/uptime/sysctl_kern_boottime | Bin 16 -> 0 bytes spec/fixtures/uptime/sysctl_kern_boottime_big_endian | Bin 0 -> 20 bytes spec/fixtures/uptime/sysctl_kern_boottime_little_endian | Bin 0 -> 16 bytes spec/unit/util/uptime_spec.rb | 7 ++++++- 4 files changed, 6 insertions(+), 1 deletion(-) delete mode 100644 spec/fixtures/uptime/sysctl_kern_boottime create mode 100644 spec/fixtures/uptime/sysctl_kern_boottime_big_endian create mode 100644 spec/fixtures/uptime/sysctl_kern_boottime_little_endian diff --git a/spec/fixtures/uptime/sysctl_kern_boottime b/spec/fixtures/uptime/sysctl_kern_boottime deleted file mode 100644 index 0c54fe4..0000000 Binary files a/spec/fixtures/uptime/sysctl_kern_boottime and /dev/null differ diff --git a/spec/fixtures/uptime/sysctl_kern_boottime_big_endian b/spec/fixtures/uptime/sysctl_kern_boottime_big_endian new file mode 100644 index 0000000..6b7be22 Binary files /dev/null and b/spec/fixtures/uptime/sysctl_kern_boottime_big_endian differ diff --git a/spec/fixtures/uptime/sysctl_kern_boottime_little_endian b/spec/fixtures/uptime/sysctl_kern_boottime_little_endian new file mode 100644 index 0000000..0c54fe4 Binary files /dev/null and b/spec/fixtures/uptime/sysctl_kern_boottime_little_endian differ diff --git a/spec/unit/util/uptime_spec.rb b/spec/unit/util/uptime_spec.rb index 8d3980c..98a1a1b 100755 --- a/spec/unit/util/uptime_spec.rb +++ b/spec/unit/util/uptime_spec.rb @@ -27,7 +27,12 @@ describe Facter::Util::Uptime do end it "should use 'sysctl kern.boottime'" do - sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'sysctl_kern_boottime') # Aug 01 14:13:47 -0700 2010 + if [1].pack("L") == [1].pack("V") # Determine endianness + sysctl_output_filename = 'sysctl_kern_boottime_little_endian' + else + sysctl_output_filename = 'sysctl_kern_boottime_big_endian' + end + sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', sysctl_output_filename) # Aug 01 14:13:47 -0700 2010 Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"") Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 -- cgit From 6b1cd16c7ef6ac78ffa85bfb81d193076db3e4c8 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Fri, 22 Apr 2011 13:56:39 -0700 Subject: (#6614) Update ipaddress6 fact to work with Ruby 1.9 Calling #to_s on an Array such as ["foo"] in Ruby 1.9 will result in the string '["foo"]', instead of stringifying the element in the array which would have given the expected result of "foo". Since the element of the array we're dealing with is already a string, we can just grab it out of the array by using #first. Paired-with: Josh Cooper --- lib/facter/ipaddress6.rb | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/lib/facter/ipaddress6.rb b/lib/facter/ipaddress6.rb index b494b9d..db3805b 100644 --- a/lib/facter/ipaddress6.rb +++ b/lib/facter/ipaddress6.rb @@ -21,21 +21,26 @@ # Used the ipaddress fact that is already part of # Facter as a template. +def get_address_after_token(output, token, return_first=false) + ip = nil + + output.scan(/#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match| + match = match.first + unless match =~ /fe80.*/ or match == "::1" + ip = match + break if return_first + end + end + + ip +end + Facter.add(:ipaddress6) do confine :kernel => :linux setcode do - ip = nil output = Facter::Util::Resolution.exec('/sbin/ifconfig') - output.scan(/inet6 addr: ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each { |str| - str = str.to_s - unless str =~ /fe80.*/ or str == "::1" - ip = str - end - } - - ip - + get_address_after_token(output, 'inet6 addr:') end end @@ -43,17 +48,8 @@ Facter.add(:ipaddress6) do confine :kernel => %w{SunOS} setcode do output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a') - ip = nil - - output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{0,2})+[0-9,a-f,A-F]{0,4})/).each { |str| - str = str.to_s - unless str =~ /fe80.*/ or str == "::1" - ip = str - end - } - - ip + get_address_after_token(output, 'inet6') end end @@ -61,17 +57,7 @@ Facter.add(:ipaddress6) do confine :kernel => %w{Darwin FreeBSD OpenBSD} setcode do output = Facter::Util::Resolution.exec('/sbin/ifconfig -a') - ip = nil - output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |str| - str = str.to_s - unless str =~ /fe80.*/ or str == "::1" - ip = str - break - end - end - - ip + get_address_after_token(output, 'inet6', true) end end - -- cgit From 063582222f83bd713699c86c825ec1e628a57473 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 4 May 2011 11:02:41 +1000 Subject: Removed inappropriately uncredited Ohai method from ec2 fact --- lib/facter/arp.rb | 4 ++-- lib/facter/ec2.rb | 54 ++++++++++++++++-------------------------------------- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/lib/facter/arp.rb b/lib/facter/arp.rb index 0a7cf67..85befa4 100644 --- a/lib/facter/arp.rb +++ b/lib/facter/arp.rb @@ -13,7 +13,7 @@ Facter.add(:arp) do end end end - EC2_ARP == arp ? arp : nil + "fe:ff:ff:ff:ff:ff" == arp ? arp : nil end end @@ -22,7 +22,7 @@ Facter::Util::IP.get_interfaces.each do |interface| confine :kernel => :linux setcode do arp = Facter::Util::IP.get_arp_value(interface) - EC2_ARP == arp ? arp : nil + "fe:ff:ff:ff:ff:ff" == arp ? arp : nil end end end diff --git a/lib/facter/ec2.rb b/lib/facter/ec2.rb index 693e78e..c52f76b 100644 --- a/lib/facter/ec2.rb +++ b/lib/facter/ec2.rb @@ -4,45 +4,24 @@ # Additional work modelled on Ohai EC2 fact require 'open-uri' -require 'socket' - -EC2_ADDR = "169.254.169.254" -EC2_METADATA_URL = "http://#{EC2_ADDR}/2008-02-01/meta-data" -EC2_USERDATA_URL = "http://#{EC2_ADDR}/2008-02-01/user-data" -EC2_ARP = "fe:ff:ff:ff:ff:ff" -EC2_EUCA_MAC = %r{^[dD]0:0[dD]:} - -def can_metadata_connect?(addr, port, timeout=2) - t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) - saddr = Socket.pack_sockaddr_in(port, addr) - connected = false - - begin - t.connect_nonblock(saddr) - rescue Errno::EINPROGRESS - r,w,e = IO::select(nil,[t],nil,timeout) - if !w.nil? - connected = true - else - begin - t.connect_nonblock(saddr) - rescue Errno::EISCONN - t.close - connected = true - rescue SystemCallError - end - end - rescue SystemCallError - end - connected +require 'timeout' + +def can_connect?(wait_sec=2) + url = "http://169.254.169.254:80/" + Timeout::timeout(wait_sec) {open(url)} + return true + rescue Timeout::Error + return false + rescue + return false end def metadata(id = "") - open("#{EC2_METADATA_URL}/#{id||=''}").read. + open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read. split("\n").each do |o| key = "#{id}#{o.gsub(/\=.*$/, '/')}" if key[-1..-1] != '/' - value = open("#{EC2_METADATA_URL}/#{key}").read. + value = open("http://169.254.169.254/2008-02-01/meta-data/#{key}").read. split("\n") value = value.size>1 ? value : value.first symbol = "ec2_#{key.gsub(/\-|\//, '_')}".to_sym @@ -54,23 +33,22 @@ def metadata(id = "") end def userdata() - # assumes the only expected error is the 404 if there's no user-data begin - value = OpenURI.open_uri("#{EC2_USERDATA_URL}/").read.split + value = OpenURI.open_uri("http://169.254.169.254/2008-02-01/user-data/").read.split Facter.add(:ec2_userdata) { setcode { value } } rescue OpenURI::HTTPError end end def has_euca_mac? - !!(Facter.value(:macaddress) =~ EC2_EUCA_MAC) + !!(Facter.value(:macaddress) =~ %r{^[dD]0:0[dD]:}) end def has_ec2_arp? - !!(Facter.value(:arp) == EC2_ARP) + !!(Facter.value(:arp) == "fe:ff:ff:ff:ff:ff") end -if (has_euca_mac? || has_ec2_arp?) && can_metadata_connect?(EC2_ADDR,80) +if (has_euca_mac? || has_ec2_arp?) && can_connect? metadata userdata else -- cgit From 8002c240dcd42d3fe0e70b99859c76067f298cef Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Fri, 20 May 2011 11:21:07 -0700 Subject: (#7507) Fix 1.9.2 test failure Dir.glob returns an array, but a test was stubbing it to return a string. In Ruby 1.8.7 if you call enumerable methods (each, collect, etc) on a string, the string is split on \n first. This meant the poor stubbing didn't affect 1.8.7, but 1.9.2 is more strict and won't automatically convert when you call enumerable methods on strings. Paired-with: Josh Cooper --- spec/unit/physicalprocessorcount_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/physicalprocessorcount_spec.rb b/spec/unit/physicalprocessorcount_spec.rb index 260788b..e1f7c60 100644 --- a/spec/unit/physicalprocessorcount_spec.rb +++ b/spec/unit/physicalprocessorcount_spec.rb @@ -14,7 +14,7 @@ describe "Physical processor count facts" do it "should return one physical CPU" do Facter.fact(:kernel).stubs(:value).returns("Linux") File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true) - Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns("/sys/devices/system/cpu/cpu0/topology/physical_package_id") + Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(["/sys/devices/system/cpu/cpu0/topology/physical_package_id"]) Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0") Facter.fact(:physicalprocessorcount).value.should == 1 -- cgit