summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-02 15:08:26 -0600
committerLuke Kanies <luke@madstop.com>2009-01-15 11:42:17 -0600
commit91e25b9cc12fcb5e8d684b6258aec20735b992e1 (patch)
treefb2617415ba9a4eb252f334bdb387d71b0266389
parent074eda99ffd186a667ec3f50fbb6d4e267f585cb (diff)
downloadfacter-91e25b9cc12fcb5e8d684b6258aec20735b992e1.tar.gz
facter-91e25b9cc12fcb5e8d684b6258aec20735b992e1.tar.xz
facter-91e25b9cc12fcb5e8d684b6258aec20735b992e1.zip
Fixing indentation everywhere
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/facter.rb10
-rw-r--r--lib/facter/Cfkey.rb4
-rw-r--r--lib/facter/fqdn.rb3
-rw-r--r--lib/facter/ipmess.rb46
-rw-r--r--lib/facter/kernelrelease.rb4
-rw-r--r--lib/facter/kernelversion.rb8
-rw-r--r--lib/facter/lsb.rb2
-rw-r--r--lib/facter/macaddress.rb52
-rw-r--r--lib/facter/manufacturer.rb2
-rw-r--r--lib/facter/operatingsystemrelease.rb16
-rw-r--r--lib/facter/processor.rb2
-rw-r--r--lib/facter/puppetversion.rb4
-rw-r--r--lib/facter/util/fact.rb2
-rw-r--r--lib/facter/util/ip.rb151
-rw-r--r--lib/facter/util/macosx.rb49
-rw-r--r--lib/facter/util/manufacturer.rb3
-rw-r--r--lib/facter/util/netmask.rb44
-rw-r--r--lib/facter/util/plist.rb2
-rw-r--r--lib/facter/virtual.rb133
-rwxr-xr-xspec/unit/facter.rb2
-rwxr-xr-xspec/unit/util/collection.rb4
-rw-r--r--spec/unit/util/ip.rb5
-rwxr-xr-xspec/unit/util/loader.rb2
23 files changed, 272 insertions, 278 deletions
diff --git a/lib/facter.rb b/lib/facter.rb
index 46a9717..e764255 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -1,20 +1,20 @@
#--
# Copyright 2006 Luke Kanies <luke@madstop.com>
-#
+#
# 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.
-#
+#
# 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.
-#
+#
# 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
-#
+#
#--
module Facter
@@ -153,7 +153,7 @@ module Facter
case bit
when TrueClass: @@debug = 1
when FalseClass: @@debug = 0
- when Fixnum:
+ when Fixnum:
if bit > 0
@@debug = 1
else
diff --git a/lib/facter/Cfkey.rb b/lib/facter/Cfkey.rb
index 4c17a0a..a4e0c11 100644
--- a/lib/facter/Cfkey.rb
+++ b/lib/facter/Cfkey.rb
@@ -22,7 +22,7 @@ Facter.add(:Cfkey) do
"/var/cfengine/ppkeys/localhost.pub",
"/var/lib/cfengine/ppkeys/localhost.pub",
"/var/lib/cfengine2/ppkeys/localhost.pub"
- ].each { |file|
+ ].each do |file|
if FileTest.file?(file)
File.open(file) { |openfile|
value = openfile.readlines.reject { |line|
@@ -35,7 +35,7 @@ Facter.add(:Cfkey) do
if value
break
end
- }
+ end
value
end
diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb
index 1fcc764..5ebc5f5 100644
--- a/lib/facter/fqdn.rb
+++ b/lib/facter/fqdn.rb
@@ -1,4 +1,5 @@
-Facter.add(:fqdn) do setcode do
+Facter.add(:fqdn) do
+ setcode do
host = Facter.value(:hostname)
domain = Facter.value(:domain)
if host and domain
diff --git a/lib/facter/ipmess.rb b/lib/facter/ipmess.rb
index e879300..c61b1ec 100644
--- a/lib/facter/ipmess.rb
+++ b/lib/facter/ipmess.rb
@@ -3,7 +3,7 @@
#
# Original concept Copyright (C) 2007 psychedelys <psychedelys@gmail.com>
# Update and *BSD support (C) 2007 James Turnbull <james@lovedthanlost.net>
-#
+#
require 'facter/util/ip'
@@ -14,33 +14,33 @@ Facter.add(:interfaces) do
end
end
-case Facter.value(:kernel)
- when 'SunOS', 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
- Facter::IPAddress.get_interfaces.each do |interface|
- mi = interface.gsub(/[:.]/, '_')
+case Facter.value(:kernel)
+when 'SunOS', 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
+ Facter::IPAddress.get_interfaces.each do |interface|
+ mi = interface.gsub(/[:.]/, '_')
- Facter.add("ipaddress_" + mi) do
- confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
- setcode do
- label = 'ipaddress'
- Facter::IPAddress.get_interface_value(interface, label)
+ Facter.add("ipaddress_" + mi) do
+ confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
+ setcode do
+ label = 'ipaddress'
+ Facter::IPAddress.get_interface_value(interface, label)
+ end
end
- end
- Facter.add("macaddress_" + mi) do
- confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
- setcode do
- label = 'macaddress'
- Facter::IPAddress.get_interface_value(interface, label)
+ Facter.add("macaddress_" + mi) do
+ confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
+ setcode do
+ label = 'macaddress'
+ Facter::IPAddress.get_interface_value(interface, label)
+ end
end
- end
- Facter.add("netmask_" + mi) do
- confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
- setcode do
- label = 'netmask'
- Facter::IPAddress.get_interface_value(interface, label)
+ Facter.add("netmask_" + mi) do
+ confine :kernel => [ :sunos, :freebsd, :openbsd, :netbsd, :linux ]
+ setcode do
+ label = 'netmask'
+ Facter::IPAddress.get_interface_value(interface, label)
+ end
end
end
- end
end
diff --git a/lib/facter/kernelrelease.rb b/lib/facter/kernelrelease.rb
index 5dccf8f..2f6ae45 100644
--- a/lib/facter/kernelrelease.rb
+++ b/lib/facter/kernelrelease.rb
@@ -14,10 +14,10 @@ Facter.add(:kernelrelease) do
version = ""
connection_string = "winmgmts://./root/cimv2"
wmi = WIN32OLE.connect(connection_string)
- wmi.ExecQuery("SELECT Version from Win32_OperatingSystem").each { |ole|
+ wmi.ExecQuery("SELECT Version from Win32_OperatingSystem").each do |ole|
version = "#{ole.Version}"
break
- }
+ end
version
end
end
diff --git a/lib/facter/kernelversion.rb b/lib/facter/kernelversion.rb
index 7d2b31d..4abb6d6 100644
--- a/lib/facter/kernelversion.rb
+++ b/lib/facter/kernelversion.rb
@@ -1,5 +1,5 @@
Facter.add("kernelversion") do
- setcode do
- Facter['kernelrelease'].value.split('-')[0]
- end
-end
+ setcode do
+ Facter['kernelrelease'].value.split('-')[0]
+ end
+end
diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb
index 2a1ca6e..fc07437 100644
--- a/lib/facter/lsb.rb
+++ b/lib/facter/lsb.rb
@@ -27,7 +27,7 @@
@@lsbtime = Time.now
@@lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
end
-
+
if pattern.match(@@lsbdata)
$1
else
diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb
index 28ded4c..e048209 100644
--- a/lib/facter/macaddress.rb
+++ b/lib/facter/macaddress.rb
@@ -3,9 +3,9 @@ Facter.add(:macaddress) do
setcode do
ether = []
output = %x{/sbin/ifconfig -a}
- output.each {|s|
- ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
- }
+ output.each do |s|
+ ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
+ end
ether[0]
end
end
@@ -15,11 +15,11 @@ Facter.add(:macaddress) do
setcode do
ether = []
output = %x{/sbin/ifconfig}
- output.each {|s|
- if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
- ether.push($1)
- end
- }
+ output.each do |s|
+ if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
+ ether.push($1)
+ end
+ end
ether[0]
end
end
@@ -30,12 +30,12 @@ Facter.add(:macaddress) do
ether = nil
output = %x{/sbin/ifconfig}
- output.split(/^\S/).each { |str|
+ output.split(/^\S/).each do |str|
if str =~ /10baseT/ # we're wired
str =~ /ether (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
ether = $1
end
- }
+ end
ether
end
@@ -47,19 +47,19 @@ Facter.add(:macaddress) do
ether = []
ip = nil
output = %x{/usr/sbin/ifconfig -a}
- output.each { |str|
+ output.each do |str|
if str =~ /([a-z]+\d+): flags=/
devname = $1
unless devname =~ /lo0/
- output2 = %x{/usr/bin/entstat #{devname}}
- output2.each { |str2|
- if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
- ether.push($1)
- end
- }
+ output2 = %x{/usr/bin/entstat #{devname}}
+ output2.each do |str2|
+ if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
+ ether.push($1)
+ end
+ end
end
end
- }
+ end
ether[0]
end
end
@@ -67,13 +67,13 @@ end
Facter.add(:macaddress) do
confine :kernel => %w(windows)
setcode do
- ether = []
- output = %x{ipconfig /all}
- output.split(/\r\n/).each do |str|
- if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/
- ether.push($1.gsub(/-/, ":"))
- end
- end
- ether[0]
+ ether = []
+ output = %x{ipconfig /all}
+ output.split(/\r\n/).each do |str|
+ if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/
+ ether.push($1.gsub(/-/, ":"))
+ end
+ end
+ ether[0]
end
end
diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb
index b217fdc..d2b13b9 100644
--- a/lib/facter/manufacturer.rb
+++ b/lib/facter/manufacturer.rb
@@ -16,4 +16,4 @@ query = {
]
}
-Facter::Manufacturer.dmi_find_system_info(query)
+Facter::Manufacturer.dmi_find_system_info(query)
diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb
index 586d104..f88278a 100644
--- a/lib/facter/operatingsystemrelease.rb
+++ b/lib/facter/operatingsystemrelease.rb
@@ -29,11 +29,11 @@ end
Facter.add(:operatingsystemrelease) do
confine :operatingsystem => %w{CentOS}
setcode do
- centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/ \((Branch|Final)\)//' /etc/redhat-release")
+ centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/ \((Branch|Final)\)//' /etc/redhat-release")
if centos_release =~ /5/
- release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2')
+ release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2')
else
- release = centos_release
+ release = centos_release
end
end
end
@@ -42,16 +42,16 @@ Facter.add(:operatingsystemrelease) do
confine :operatingsystem => %w{Debian}
setcode do
release = Facter::Util::Resolution.exec('cat /etc/debian_version')
- end
+ end
end
Facter.add(:operatingsystemrelease) do
confine :operatingsystem => %w{Ubuntu}
setcode do
release = Facter::Util::Resolution.exec('cat /etc/issue')
- if release =~ /Ubuntu (\d+.\d+)/
- $1
- end
+ if release =~ /Ubuntu (\d+.\d+)/
+ $1
+ end
end
end
@@ -76,7 +76,7 @@ end
Facter.add(:operatingsystemrelease) do
confine :operatingsystem => %w{Solaris}
setcode do
- release = Facter::Util::Resolution.exec('uname -v')
+ release = Facter::Util::Resolution.exec('uname -v')
end
end
diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb
index afc604e..154cced 100644
--- a/lib/facter/processor.rb
+++ b/lib/facter/processor.rb
@@ -46,7 +46,7 @@ if Facter.value(:kernel) == "AIX"
procs.each do |proc|
if proc =~ /^proc(\d+)/
processor_num = $1.to_i
- # Not retrieving the frequency since AIX 4.3.3 doesn't support the
+ # Not retrieving the frequency since AIX 4.3.3 doesn't support the
# attribute and some people still use the OS.
proctype = Facter::Util::Resolution.exec('lsattr -El proc0 -a type')
if proctype =~ /^type\s+(\S+)\s+/
diff --git a/lib/facter/puppetversion.rb b/lib/facter/puppetversion.rb
index 66fcfe8..d2eb1f3 100644
--- a/lib/facter/puppetversion.rb
+++ b/lib/facter/puppetversion.rb
@@ -1,10 +1,10 @@
Facter.add(:puppetversion) do
- setcode {
+ setcode do
begin
require 'puppet'
Puppet::PUPPETVERSION.to_s
rescue LoadError
nil
end
- }
+ end
end
diff --git a/lib/facter/util/fact.rb b/lib/facter/util/fact.rb
index ca2ba03..cfdfb60 100644
--- a/lib/facter/util/fact.rb
+++ b/lib/facter/util/fact.rb
@@ -102,7 +102,7 @@ class Facter::Util::Fact
def searching
if searching?
Facter.debug "Caught recursion on %s" % @name
-
+
# return a cached value if we've got it
if @value
return @value
diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb
index 5449858..3dbfcda 100644
--- a/lib/facter/util/ip.rb
+++ b/lib/facter/util/ip.rb
@@ -1,27 +1,27 @@
+# A base module for collecting IP-related
+# information from all kinds of platforms.
module Facter::IPAddress
-
def self.get_interfaces
-
- int = nil
-
- output = Facter::IPAddress.get_all_interface_output()
- # We get lots of warnings on platforms that don't get an output
- # made.
- if output
- int = output.scan(/^\w+[.:]?\d+/)
- else
- []
- end
-
+ int = nil
+
+ output = Facter::IPAddress.get_all_interface_output()
+
+ # We get lots of warnings on platforms that don't get an output
+ # made.
+ if output
+ int = output.scan(/^\w+[.:]?\d+/)
+ else
+ []
+ end
end
def self.get_all_interface_output
case Facter.value(:kernel)
- when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
- output = %x{/sbin/ifconfig -a}
- when 'SunOS'
- output = %x{/usr/sbin/ifconfig -a}
+ when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
+ output = %x{/sbin/ifconfig -a}
+ when 'SunOS'
+ output = %x{/usr/sbin/ifconfig -a}
end
output
end
@@ -29,9 +29,9 @@ module Facter::IPAddress
def self.get_single_interface_output(interface)
output = ""
case Facter.value(:kernel)
- when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
- output = %x{/sbin/ifconfig #{interface}}
- when 'SunOS'
+ when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD'
+ output = %x{/sbin/ifconfig #{interface}}
+ when 'SunOS'
output = %x{/usr/sbin/ifconfig #{interface}}
end
output
@@ -43,75 +43,76 @@ module Facter::IPAddress
end
# We need ip instead of ifconfig because it will show us
# the bonding master device.
- if not FileTest.executable?("/sbin/ip")
+ if not FileTest.executable?("/sbin/ip")
return nil
end
regex = /SLAVE[,>].* (bond[0-9]+)/
- ethbond = regex.match(%x{/sbin/ip link show #{interface}})
- if ethbond
+ ethbond = regex.match(%x{/sbin/ip link show #{interface}})
+ if ethbond
device = ethbond[1]
else
device = nil
end
device
end
-
+
def self.get_interface_value(interface, label)
-
- tmp1 = []
+ tmp1 = []
- case Facter.value(:kernel)
- when 'Linux'
- addr = /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
- mac = /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
- mask = /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
- when 'OpenBSD', 'NetBSD', 'FreeBSD'
- addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
- mac = /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
- mask = /netmask\s+(\w{10})/
- when 'SunOS'
- addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
- mac = /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/
- mask = /netmask\s+(\w{8})/
- end
+ # LAK:NOTE This is pretty ugly - two case statements being used for most of the
+ # logic. These should be pulled into a small dispatch table. We don't have tests for this code,
+ # though, so it's not exactly trivial to do so.
+ case Facter.value(:kernel)
+ when 'Linux'
+ addr = /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
+ mac = /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
+ mask = /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
+ when 'OpenBSD', 'NetBSD', 'FreeBSD'
+ addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
+ mac = /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
+ mask = /netmask\s+(\w{10})/
+ when 'SunOS'
+ addr = /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
+ mac = /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/
+ mask = /netmask\s+(\w{8})/
+ end
+
+ case label
+ when 'ipaddress'
+ regex = addr
+ when 'macaddress'
+ regex = mac
+ when 'netmask'
+ regex = mask
+ end
- case label
- when 'ipaddress'
- regex = addr
- when 'macaddress'
- regex = mac
- when 'netmask'
- regex = mask
- end
+ # Linux changes the MAC address reported via ifconfig when an ethernet interface
+ # becomes a slave of a bonding device to the master MAC address.
+ # We have to dig a bit to get the original/real MAC address of the interface.
+ bonddev = get_bonding_master(interface)
+ if label == 'macaddress' and bonddev
+ bondinfo = IO.readlines("/proc/net/bonding/#{bonddev}")
+ hwaddrre = /^Slave Interface: #{interface}\n[^\n].+?\nPermanent HW addr: (([0-9a-fA-F]{2}:?)*)$/m
+ value = hwaddrre.match(bondinfo.to_s)[1].upcase
+ else
+ output_int = get_single_interface_output(interface)
- # Linux changes the MAC address reported via ifconfig when an ethernet interface
- # becomes a slave of a bonding device to the master MAC address.
- # We have to dig a bit to get the original/real MAC address of the interface.
- bonddev = get_bonding_master(interface)
- if label == 'macaddress' and bonddev
- bondinfo = IO.readlines("/proc/net/bonding/#{bonddev}")
- hwaddrre = /^Slave Interface: #{interface}\n[^\n].+?\nPermanent HW addr: (([0-9a-fA-F]{2}:?)*)$/m
- value = hwaddrre.match(bondinfo.to_s)[1].upcase
- else
- output_int = get_single_interface_output(interface)
-
- if interface != "lo" && interface != "lo0"
- output_int.each { |s|
- if s =~ regex
- value = $1
- if label == 'netmask' && Facter.value(:kernel) == "SunOS"
- value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.')
- end
- tmp1.push(value)
- end
- }
- end
+ if interface != "lo" && interface != "lo0"
+ output_int.each { |s|
+ if s =~ regex
+ value = $1
+ if label == 'netmask' && Facter.value(:kernel) == "SunOS"
+ value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.')
+ end
+ tmp1.push(value)
+ end
+ }
+ end
- if tmp1
- value = tmp1.shift
- end
+ if tmp1
+ value = tmp1.shift
+ end
+ end
end
-
- end
end
diff --git a/lib/facter/util/macosx.rb b/lib/facter/util/macosx.rb
index 1e596d8..2704a7c 100644
--- a/lib/facter/util/macosx.rb
+++ b/lib/facter/util/macosx.rb
@@ -17,34 +17,33 @@
##
module Facter::Macosx
- require 'thread'
- require 'facter/util/plist'
+ require 'thread'
+ require 'facter/util/plist'
- # JJM I'd really like to dynamically generate these methods
- # by looking at the _name key of the _items dict for each _dataType
+ # JJM I'd really like to dynamically generate these methods
+ # by looking at the _name key of the _items dict for each _dataType
- def self.hardware_overview
- # JJM Perhaps we should cache the XML data in a "class" level object.
- top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPHardwareDataType}
- system_hardware = top_level_plist[0]['_items'][0]
- system_hardware.delete '_name'
- system_hardware
- end
+ def self.hardware_overview
+ # JJM Perhaps we should cache the XML data in a "class" level object.
+ top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPHardwareDataType}
+ system_hardware = top_level_plist[0]['_items'][0]
+ system_hardware.delete '_name'
+ system_hardware
+ end
- # SPSoftwareDataType
- def self.os_overview
- top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPSoftwareDataType}
- os_stuff = top_level_plist[0]['_items'][0]
- os_stuff.delete '_name'
- os_stuff
- end
+ # SPSoftwareDataType
+ def self.os_overview
+ top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPSoftwareDataType}
+ os_stuff = top_level_plist[0]['_items'][0]
+ os_stuff.delete '_name'
+ os_stuff
+ end
- def self.sw_vers
- ver = Hash.new
- [ "productName", "productVersion", "buildVersion" ].each do |option|
- ver["macosx_#{option}"] = %x{sw_vers -#{option}}.strip
+ def self.sw_vers
+ ver = Hash.new
+ [ "productName", "productVersion", "buildVersion" ].each do |option|
+ ver["macosx_#{option}"] = %x{sw_vers -#{option}}.strip
+ end
+ ver
end
- ver
- end
end
-
diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb
index 657901d..ff12e7e 100644
--- a/lib/facter/util/manufacturer.rb
+++ b/lib/facter/util/manufacturer.rb
@@ -42,6 +42,5 @@ module Facter::Manufacturer
end
end
end
+ end
end
-end
-
diff --git a/lib/facter/util/netmask.rb b/lib/facter/util/netmask.rb
index 71696ad..dcbb795 100644
--- a/lib/facter/util/netmask.rb
+++ b/lib/facter/util/netmask.rb
@@ -1,36 +1,34 @@
module Facter::NetMask
-
-def self.get_netmask
+ def self.get_netmask
netmask = nil;
ipregex = %r{(\d{1,3}\.){3}\d{1,3}}
ops = nil
case Facter.value(:kernel)
- when 'Linux'
- ops = {
- :ifconfig => '/sbin/ifconfig',
- :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
- :munge => nil,
- }
- when 'SunOS'
- ops = {
- :ifconfig => '/usr/sbin/ifconfig -a',
- :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x,
- :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
- }
+ when 'Linux'
+ ops = {
+ :ifconfig => '/sbin/ifconfig',
+ :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
+ :munge => nil,
+ }
+ when 'SunOS'
+ ops = {
+ :ifconfig => '/usr/sbin/ifconfig -a',
+ :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x,
+ :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
+ }
end
%x{#{ops[:ifconfig]}}.split(/\n/).collect do |line|
- matches = line.match(ops[:regex])
- if !matches.nil?
- if ops[:munge].nil?
- netmask = matches[1]
- else
- netmask = ops[:munge].call(matches[1])
- end
+ matches = line.match(ops[:regex])
+ if !matches.nil?
+ if ops[:munge].nil?
+ netmask = matches[1]
+ else
+ netmask = ops[:munge].call(matches[1])
end
+ end
end
netmask
-end
-
+ end
end
diff --git a/lib/facter/util/plist.rb b/lib/facter/util/plist.rb
index 32e9e2b..54f5248 100644
--- a/lib/facter/util/plist.rb
+++ b/lib/facter/util/plist.rb
@@ -18,7 +18,7 @@ require 'facter/util/plist/generator'
require 'facter/util/plist/parser'
module Plist
- VERSION = '3.0.0'
+ VERSION = '3.0.0'
end
# $Id: plist.rb 1781 2006-10-16 01:01:35Z luke $
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index db8dc33..fdb340f 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -1,76 +1,75 @@
Facter.add("virtual") do
- confine :kernel => %w{Linux FreeBSD OpenBSD SunOS}
-
- result = "physical"
-
- setcode do
+ confine :kernel => %w{Linux FreeBSD OpenBSD SunOS}
- if FileTest.exists?("/proc/user_beancounters")
- # openvz. can be hardware node or virtual environment
- # read the init process' status file, it has laxer permissions
- # than /proc/user_beancounters (so this won't fail as non-root)
- txt = File.read("/proc/1/status")
- if txt =~ /^envID:[[:blank:]]+0$/mi
- result = "openvzhn"
- else
- result = "openvzve"
- end
- end
+ result = "physical"
- if FileTest.exists?("/proc/xen/capabilities") && FileTest.readable?("/proc/xen/capabilities")
- txt = File.read("/proc/xen/capabilities")
- if txt =~ /control_d/i
- result = "xen0"
- else
- result = "xenu"
- end
- end
+ setcode do
+ if FileTest.exists?("/proc/user_beancounters")
+ # openvz. can be hardware node or virtual environment
+ # read the init process' status file, it has laxer permissions
+ # than /proc/user_beancounters (so this won't fail as non-root)
+ txt = File.read("/proc/1/status")
+ if txt =~ /^envID:[[:blank:]]+0$/mi
+ result = "openvzhn"
+ else
+ result = "openvzve"
+ end
+ end
- if result == "physical"
- path = %x{which lspci 2> /dev/null}.chomp
- if path !~ /no lspci/
- output = %x{#{path}}
- output.each {|p|
- # --- 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/
- }
- else
- path = %x{which dmidecode 2> /dev/null}.chomp
- if path !~ /no dmidecode/
- output = %x{#{path}}
- output.each {|pd|
- result = "vmware" if pd =~ /VMware|Parallels/
- }
- else
- path = %x{which prtdiag 2> /dev/null}.chomp
- if path !~ /no prtdiag/
- output = %x{#{path}}
- output.each {|pd|
- result = "vmware" if pd =~ /VMware|Parallels/
- }
- end
- end
- end
- end
+ if FileTest.exists?("/proc/xen/capabilities") && FileTest.readable?("/proc/xen/capabilities")
+ txt = File.read("/proc/xen/capabilities")
+ if txt =~ /control_d/i
+ result = "xen0"
+ else
+ result = "xenu"
+ end
+ end
- # VMware server 1.0.3 rpm places vmware-vmx in this place, other versions or platforms may not.
- if FileTest.exists?("/usr/lib/vmware/bin/vmware-vmx")
- result = "vmware_server"
- end
+ if result == "physical"
+ path = %x{which lspci 2> /dev/null}.chomp
+ if path !~ /no lspci/
+ output = %x{#{path}}
+ output.each do |p|
+ # --- 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/
+ end
+ else
+ path = %x{which dmidecode 2> /dev/null}.chomp
+ if path !~ /no dmidecode/
+ output = %x{#{path}}
+ output.each do |pd|
+ result = "vmware" if pd =~ /VMware|Parallels/
+ end
+ else
+ path = %x{which prtdiag 2> /dev/null}.chomp
+ if path !~ /no prtdiag/
+ output = %x{#{path}}
+ output.each do |pd|
+ result = "vmware" if pd =~ /VMware|Parallels/
+ end
+ end
+ end
+ end
+ end
- mountexists = system "which mount > /dev/null 2>&1"
- if $?.exitstatus == 0
- output = %x{mount}
- output.each {|p|
- result = "vserver" if p =~ /\/dev\/hdv1/
- }
- end
+ # VMware server 1.0.3 rpm places vmware-vmx in this place, other versions or platforms may not.
+ if FileTest.exists?("/usr/lib/vmware/bin/vmware-vmx")
+ result = "vmware_server"
+ end
- if FileTest.directory?('/proc/virtual')
- result = "vserver_host"
- end
+ mountexists = system "which mount > /dev/null 2>&1"
+ if $?.exitstatus == 0
+ output = %x{mount}
+ output.each do |p|
+ result = "vserver" if p =~ /\/dev\/hdv1/
+ end
+ end
- result
- end
+ if FileTest.directory?('/proc/virtual')
+ result = "vserver_host"
+ end
+
+ result
+ end
end
diff --git a/spec/unit/facter.rb b/spec/unit/facter.rb
index 05d99c8..bdef726 100755
--- a/spec/unit/facter.rb
+++ b/spec/unit/facter.rb
@@ -3,7 +3,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Facter do
-
+
it "should have a version" do
Facter.version.should =~ /^[0-9]+(\.[0-9]+)*$/
end
diff --git a/spec/unit/util/collection.rb b/spec/unit/util/collection.rb
index 7585a52..7baef96 100755
--- a/spec/unit/util/collection.rb
+++ b/spec/unit/util/collection.rb
@@ -114,7 +114,7 @@ describe Facter::Util::Collection do
it "should be case-insensitive" do
@coll.fact("yayness").should equal(@fact)
end
-
+
it "should treat strings and symbols equivalently" do
@coll.fact(:yayness).should equal(@fact)
end
@@ -156,7 +156,7 @@ describe Facter::Util::Collection do
it "should be case-insensitive" do
@coll.value("yayness").should_not be_nil
end
-
+
it "should treat strings and symbols equivalently" do
@coll.value(:yayness).should_not be_nil
end
diff --git a/spec/unit/util/ip.rb b/spec/unit/util/ip.rb
index e27531e..059bdd1 100644
--- a/spec/unit/util/ip.rb
+++ b/spec/unit/util/ip.rb
@@ -5,7 +5,6 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'facter/util/ip'
describe Facter::IPAddress do
-
it "should return a list of interfaces" do
Facter::IPAddress.should respond_to(:get_interfaces)
end
@@ -23,7 +22,7 @@ describe Facter::IPAddress do
end
it "should return a value for a specific interface" do
- Facter::IPAddress.should respond_to(:get_interface_value)
+ Facter::IPAddress.should respond_to(:get_interface_value)
end
it "should return a human readable netmask on Solaris" do
@@ -35,6 +34,4 @@ describe Facter::IPAddress do
Facter::IPAddress.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
end
-
end
-
diff --git a/spec/unit/util/loader.rb b/spec/unit/util/loader.rb
index b9b4306..945d3af 100755
--- a/spec/unit/util/loader.rb
+++ b/spec/unit/util/loader.rb
@@ -83,7 +83,7 @@ describe Facter::Util::Loader do
@loader.load(:testing)
end
end
-
+
it "should load any files in the search path with names matching the fact name" do
@loader.expects(:search_path).returns %w{/one/dir /two/dir}
FileTest.stubs(:exist?).returns false