facter 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (55) hide show
  1. data/CHANGELOG +42 -0
  2. data/COPYING +0 -458
  3. data/LICENSE +670 -13
  4. data/Rakefile +54 -10
  5. data/bin/facter +6 -2
  6. data/conf/osx/createpackage.sh +2 -1
  7. data/conf/osx/preflight +2 -1
  8. data/conf/redhat/facter.spec +25 -9
  9. data/install.rb +0 -0
  10. data/lib/facter.rb +6 -6
  11. data/lib/facter/Cfkey.rb +2 -2
  12. data/lib/facter/domain.rb +21 -52
  13. data/lib/facter/fqdn.rb +2 -1
  14. data/lib/facter/hardwareisa.rb +1 -1
  15. data/lib/facter/id.rb +12 -1
  16. data/lib/facter/interfaces.rb +32 -0
  17. data/lib/facter/ipaddress.rb +1 -1
  18. data/lib/facter/kernelrelease.rb +2 -2
  19. data/lib/facter/kernelversion.rb +4 -4
  20. data/lib/facter/lsb.rb +1 -1
  21. data/lib/facter/lsbmajdistrelease.rb +1 -1
  22. data/lib/facter/macaddress.rb +27 -27
  23. data/lib/facter/macosx.rb +3 -3
  24. data/lib/facter/manufacturer.rb +11 -2
  25. data/lib/facter/network.rb +10 -0
  26. data/lib/facter/operatingsystem.rb +4 -0
  27. data/lib/facter/operatingsystemrelease.rb +12 -15
  28. data/lib/facter/processor.rb +1 -1
  29. data/lib/facter/puppetversion.rb +2 -2
  30. data/lib/facter/uniqueid.rb +1 -1
  31. data/lib/facter/uptime.rb +20 -0
  32. data/lib/facter/util/fact.rb +1 -1
  33. data/lib/facter/util/ip.rb +134 -66
  34. data/lib/facter/util/macosx.rb +43 -30
  35. data/lib/facter/util/manufacturer.rb +13 -6
  36. data/lib/facter/util/netmask.rb +21 -23
  37. data/lib/facter/util/plist.rb +1 -1
  38. data/lib/facter/util/uptime.rb +32 -0
  39. data/lib/facter/virtual.rb +66 -53
  40. data/spec/integration/facter.rb +0 -0
  41. data/spec/spec_helper.rb +1 -10
  42. data/spec/unit/data/6.0-STABLE_FreeBSD_ifconfig +12 -0
  43. data/spec/unit/data/Mac_OS_X_10.5.5_ifconfig +26 -0
  44. data/spec/unit/data/darwin_ifconfig_single_interface +6 -0
  45. data/spec/unit/facter.rb +1 -1
  46. data/spec/unit/interfaces.rb +19 -0
  47. data/spec/unit/util/collection.rb +2 -2
  48. data/spec/unit/util/confine.rb +0 -0
  49. data/spec/unit/util/fact.rb +0 -0
  50. data/spec/unit/util/ip.rb +65 -9
  51. data/spec/unit/util/loader.rb +1 -1
  52. data/spec/unit/util/macosx.rb +47 -0
  53. data/spec/unit/util/resolution.rb +0 -0
  54. metadata +12 -4
  55. data/lib/facter/ipmess.rb +0 -46
@@ -16,35 +16,48 @@
16
16
  ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
17
17
  ##
18
18
 
19
- module Facter::Macosx
20
- require 'thread'
21
- require 'facter/util/plist'
22
-
23
- # JJM I'd really like to dynamically generate these methods
24
- # by looking at the _name key of the _items dict for each _dataType
25
-
26
- def self.hardware_overview
27
- # JJM Perhaps we should cache the XML data in a "class" level object.
28
- top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPHardwareDataType}
29
- system_hardware = top_level_plist[0]['_items'][0]
30
- system_hardware.delete '_name'
31
- system_hardware
32
- end
33
-
34
- # SPSoftwareDataType
35
- def self.os_overview
36
- top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPSoftwareDataType}
37
- os_stuff = top_level_plist[0]['_items'][0]
38
- os_stuff.delete '_name'
39
- os_stuff
40
- end
41
-
42
- def self.sw_vers
43
- ver = Hash.new
44
- [ "productName", "productVersion", "buildVersion" ].each do |option|
45
- ver["macosx_#{option}"] = %x{sw_vers -#{option}}.strip
19
+ module Facter::Util::Macosx
20
+ require 'thread'
21
+ require 'facter/util/plist'
22
+ require 'facter/util/resolution'
23
+
24
+ # JJM I'd really like to dynamically generate these methods
25
+ # by looking at the _name key of the _items dict for each _dataType
26
+
27
+ def self.profiler_xml(data_field)
28
+ Facter::Util::Resolution.exec("/usr/sbin/system_profiler -xml #{data_field}")
29
+ end
30
+
31
+ def self.intern_xml(xml)
32
+ return nil unless xml
33
+ Plist::parse_xml(xml)
34
+ end
35
+
36
+ # Return an xml result, modified as we need it.
37
+ def self.profiler_data(data_field)
38
+ begin
39
+ return nil unless parsed_xml = intern_xml(profiler_xml(data_field))
40
+ return nil unless data = parsed_xml[0]['_items'][0]
41
+ data.delete '_name'
42
+ data
43
+ rescue
44
+ return nil
45
+ end
46
46
  end
47
- ver
48
- end
49
- end
50
47
 
48
+ def self.hardware_overview
49
+ profiler_data("SPHardwareDataType")
50
+ end
51
+
52
+ def self.os_overview
53
+ profiler_data("SPSoftwareDataType")
54
+ end
55
+
56
+ def self.sw_vers
57
+ ver = Hash.new
58
+ [ "productName", "productVersion", "buildVersion" ].each do |option|
59
+ ver["macosx_#{option}"] = %x{sw_vers -#{option}}.strip
60
+ end
61
+ ver
62
+ end
63
+ end
@@ -3,6 +3,7 @@
3
3
 
4
4
  module Facter::Manufacturer
5
5
  def self.dmi_find_system_info(name)
6
+ splitstr="Handle"
6
7
  case Facter.value(:kernel)
7
8
  when 'Linux'
8
9
  return nil unless FileTest.exists?("/usr/sbin/dmidecode")
@@ -16,16 +17,22 @@ module Facter::Manufacturer
16
17
  return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode")
17
18
 
18
19
  output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
20
+ when 'SunOS'
21
+ return nil unless FileTest.exists?("/usr/sbin/smbios")
22
+ splitstr="ID SIZE TYPE"
23
+ output=%x{/usr/sbin/smbios 2>/dev/null}
24
+
19
25
  else
20
26
  return
21
27
  end
22
28
  name.each_pair do |key,v|
23
- v.each do |value|
24
- output.split("Handle").each do |line|
25
- if line =~ /#{key}/ and line =~ /#{value} ([-\w].*)\n*./
29
+ v.each do |v2|
30
+ v2.each_pair do |value,facterkey|
31
+ output.split(splitstr).each do |line|
32
+ if line =~ /#{key}/ and ( line =~ /#{value} 0x\d+ \(([-\w].*)\)\n*./ or line =~ /#{value} ([-\w].*)\n*./ )
26
33
  result = $1
27
- Facter.add(value.chomp(':').gsub(' ','')) do
28
- confine :kernel => [ :linux, :freebsd, :netbsd, :openbsd ]
34
+ Facter.add(facterkey) do
35
+ confine :kernel => [ :linux, :freebsd, :netbsd, :openbsd, :sunos ]
29
36
  setcode do
30
37
  result
31
38
  end
@@ -35,5 +42,5 @@ module Facter::Manufacturer
35
42
  end
36
43
  end
37
44
  end
45
+ end
38
46
  end
39
-
@@ -1,36 +1,34 @@
1
1
  module Facter::NetMask
2
-
3
- def self.get_netmask
2
+ def self.get_netmask
4
3
  netmask = nil;
5
4
  ipregex = %r{(\d{1,3}\.){3}\d{1,3}}
6
5
 
7
6
  ops = nil
8
7
  case Facter.value(:kernel)
9
- when 'Linux'
10
- ops = {
11
- :ifconfig => '/sbin/ifconfig',
12
- :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
13
- :munge => nil,
14
- }
15
- when 'SunOS'
16
- ops = {
17
- :ifconfig => '/usr/sbin/ifconfig -a',
18
- :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x,
19
- :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
20
- }
8
+ when 'Linux'
9
+ ops = {
10
+ :ifconfig => '/sbin/ifconfig',
11
+ :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
12
+ :munge => nil,
13
+ }
14
+ when 'SunOS'
15
+ ops = {
16
+ :ifconfig => '/usr/sbin/ifconfig -a',
17
+ :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x,
18
+ :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
19
+ }
21
20
  end
22
21
 
23
22
  %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line|
24
- matches = line.match(ops[:regex])
25
- if !matches.nil?
26
- if ops[:munge].nil?
27
- netmask = matches[1]
28
- else
29
- netmask = ops[:munge].call(matches[1])
30
- end
23
+ matches = line.match(ops[:regex])
24
+ if !matches.nil?
25
+ if ops[:munge].nil?
26
+ netmask = matches[1]
27
+ else
28
+ netmask = ops[:munge].call(matches[1])
31
29
  end
30
+ end
32
31
  end
33
32
  netmask
34
- end
35
-
33
+ end
36
34
  end
@@ -18,7 +18,7 @@ require 'facter/util/plist/generator'
18
18
  require 'facter/util/plist/parser'
19
19
 
20
20
  module Plist
21
- VERSION = '3.0.0'
21
+ VERSION = '3.0.0'
22
22
  end
23
23
 
24
24
  # $Id: plist.rb 1781 2006-10-16 01:01:35Z luke $
@@ -0,0 +1,32 @@
1
+ # A module to gather uptime facts
2
+ #
3
+ module Facter::Util::Uptime
4
+
5
+ def self.get_uptime_simple
6
+ time = Facter::Util::Resolution.exec('uptime')
7
+ if time =~ /up\s*(\d+\s\w+)/
8
+ $1
9
+ else
10
+ "unknown"
11
+ end
12
+ end
13
+
14
+ def self.get_uptime
15
+ uptime, idletime = File.open("/proc/uptime").gets.split(" ")
16
+ uptime_seconds = uptime.to_i
17
+ end
18
+
19
+ def self.get_uptime_period(seconds, label)
20
+
21
+ case label
22
+ when 'days'
23
+ value = seconds / 86400
24
+ when 'hours'
25
+ value = seconds / 3600
26
+ when 'seconds'
27
+ seconds
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -1,62 +1,75 @@
1
1
  Facter.add("virtual") do
2
- confine :kernel => %w{Linux FreeBSD OpenBSD}
3
-
4
- ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin"
5
-
6
- result = "physical"
7
-
8
- setcode do
9
-
10
- if FileTest.exists?("/proc/user_beancounters")
11
- result = "openvz"
12
- end
2
+ confine :kernel => %w{Linux FreeBSD OpenBSD SunOS}
13
3
 
14
- if FileTest.exists?("/proc/xen/capabilities") && FileTest.readable?("/proc/xen/capabilities")
15
- txt = File.read("/proc/xen/capabilities")
16
- if txt =~ /control_d/i
17
- result = "xen0"
18
- else
19
- result = "xenu"
20
- end
21
- end
4
+ result = "physical"
22
5
 
23
- if result == "physical"
24
- lspciexists = system "which lspci > /dev/null 2>&1"
25
- if $?.exitstatus == 0
26
- output = %x{lspci}
27
- output.each {|p|
28
- # --- look for the vmware video card to determine if it is virtual => vmware.
29
- # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter
30
- result = "vmware" if p =~ /VM[wW]are/
31
- }
32
- else
33
- dmidecodeexists = system "which dmidecode > /dev/null 2>&1"
34
- if $?.exitstatus == 0
35
- outputd = %x{dmidecode}
36
- outputd.each {|pd|
37
- result = "vmware" if pd =~ /VMware|Parallels/
38
- }
6
+ setcode do
7
+ if FileTest.exists?("/proc/user_beancounters")
8
+ # openvz. can be hardware node or virtual environment
9
+ # read the init process' status file, it has laxer permissions
10
+ # than /proc/user_beancounters (so this won't fail as non-root)
11
+ txt = File.read("/proc/1/status")
12
+ if txt =~ /^envID:[[:blank:]]+0$/mi
13
+ result = "openvzhn"
14
+ else
15
+ result = "openvzve"
16
+ end
39
17
  end
40
- end
41
- end
42
18
 
43
- # VMware server 1.0.3 rpm places vmware-vmx in this place, other versions or platforms may not.
44
- if FileTest.exists?("/usr/lib/vmware/bin/vmware-vmx")
45
- result = "vmware_server"
46
- end
19
+ if FileTest.exists?("/proc/xen/capabilities") && FileTest.readable?("/proc/xen/capabilities")
20
+ txt = File.read("/proc/xen/capabilities")
21
+ if txt =~ /control_d/i
22
+ result = "xen0"
23
+ else
24
+ result = "xenu"
25
+ end
26
+ end
47
27
 
48
- mountexists = system "which mount > /dev/null 2>&1"
49
- if $?.exitstatus == 0
50
- output = %x{mount}
51
- output.each {|p|
52
- result = "vserver" if p =~ /\/dev\/hdv1/
53
- }
54
- end
28
+ if result == "physical"
29
+ path = %x{which lspci 2> /dev/null}.chomp
30
+ if path !~ /no lspci/
31
+ output = %x{#{path}}
32
+ output.each do |p|
33
+ # --- look for the vmware video card to determine if it is virtual => vmware.
34
+ # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter
35
+ result = "vmware" if p =~ /VM[wW]are/
36
+ end
37
+ else
38
+ path = %x{which dmidecode 2> /dev/null}.chomp
39
+ if path !~ /no dmidecode/
40
+ output = %x{#{path}}
41
+ output.each do |pd|
42
+ result = "vmware" if pd =~ /VMware|Parallels/
43
+ end
44
+ else
45
+ path = %x{which prtdiag 2> /dev/null}.chomp
46
+ if path !~ /no prtdiag/
47
+ output = %x{#{path}}
48
+ output.each do |pd|
49
+ result = "vmware" if pd =~ /VMware|Parallels/
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
55
 
56
- if FileTest.directory?('/proc/virtual')
57
- result = "vserver_host"
58
- end
56
+ # VMware server 1.0.3 rpm places vmware-vmx in this place, other versions or platforms may not.
57
+ if FileTest.exists?("/usr/lib/vmware/bin/vmware-vmx")
58
+ result = "vmware_server"
59
+ end
60
+
61
+ mountexists = system "which mount > /dev/null 2>&1"
62
+ if $?.exitstatus == 0
63
+ output = %x{mount}
64
+ output.each do |p|
65
+ result = "vserver" if p =~ /\/dev\/hdv1/
66
+ end
67
+ end
68
+
69
+ if FileTest.directory?('/proc/virtual')
70
+ result = "vserver_host"
71
+ end
59
72
 
60
- result
61
- end
73
+ result
74
+ end
62
75
  end
File without changes
@@ -3,16 +3,7 @@ dir = File.expand_path(File.dirname(__FILE__))
3
3
  $LOAD_PATH.unshift("#{dir}/")
4
4
  $LOAD_PATH.unshift("#{dir}/../lib")
5
5
 
6
- # include any gems in vendor/gems
7
- Dir["#{dir}/../vendor/gems/**"].each do |path|
8
- libpath = File.join(path, "lib")
9
- if File.directory?(libpath)
10
- $LOAD_PATH.unshift(libpath)
11
- else
12
- $LOAD_PATH.unshift(path)
13
- end
14
- end
15
-
6
+ require 'rubygems'
16
7
  require 'mocha'
17
8
  require 'spec'
18
9
  require 'facter'
@@ -0,0 +1,12 @@
1
+ fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
2
+ options=b<RXCSUM,TXCSUM,VLAN_MTU>
3
+ inet x.x.58.26 netmask 0xfffffff8 broadcast x.x.58.31
4
+ inet x.x.58.27 netmask 0xffffffff broadcast x.x.58.27
5
+ inet x.x.58.28 netmask 0xffffffff broadcast x.x.58.28
6
+ inet x.x.58.29 netmask 0xffffffff broadcast x.x.58.29
7
+ inet x.x.58.30 netmask 0xffffffff broadcast x.x.58.30
8
+ ether 00:0e:0c:68:67:7c
9
+ media: Ethernet autoselect (100baseTX <full-duplex>)
10
+ status: active
11
+ lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
12
+ inet 127.0.0.1 netmask 0xff000000
@@ -0,0 +1,26 @@
1
+ lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
2
+ inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
3
+ inet 127.0.0.1 netmask 0xff000000
4
+ inet6 ::1 prefixlen 128
5
+ gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
6
+ stf0: flags=0<> mtu 1280
7
+ en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
8
+ ether 00:1b:63:ae:02:66
9
+ media: autoselect status: inactive
10
+ supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full-duplex,hw-loopback> 1000baseT <full-duplex,flow-control> none
11
+ fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
12
+ lladdr 00:1e:52:ff:fe:31:1a:80
13
+ media: autoselect <full-duplex> status: inactive
14
+ supported media: autoselect <full-duplex>
15
+ en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
16
+ inet6 fe80::21e:52ff:fe70:d7b6%en1 prefixlen 64 scopeid 0x6
17
+ inet 192.168.0.4 netmask 0xffffff00 broadcast 192.168.0.255
18
+ ether 00:1e:52:70:d7:b6
19
+ media: autoselect status: active
20
+ supported media: autoselect
21
+ vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
22
+ inet 172.16.15.1 netmask 0xffffff00 broadcast 172.16.15.255
23
+ ether 00:50:56:c0:00:08
24
+ vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
25
+ inet 192.168.89.1 netmask 0xffffff00 broadcast 192.168.89.255
26
+ ether 00:50:56:c0:00:01
@@ -0,0 +1,6 @@
1
+ en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
2
+ inet6 fe80::21c:b3ff:febe:81c9%en1 prefixlen 64 scopeid 0x6
3
+ inet 10.0.0.101 netmask 0xffffff00 broadcast 10.0.0.255
4
+ ether 00:1c:b3:be:81:c9
5
+ media: autoselect status: active
6
+ supported media: autoselect
@@ -3,7 +3,7 @@
3
3
  require File.dirname(__FILE__) + '/../spec_helper'
4
4
 
5
5
  describe Facter do
6
-
6
+
7
7
  it "should have a version" do
8
8
  Facter.version.should =~ /^[0-9]+(\.[0-9]+)*$/
9
9
  end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ require 'facter'
6
+
7
+ describe "Per Interface IP facts" do
8
+ before do
9
+ Facter.loadfacts
10
+ end
11
+
12
+ it "should replace the ':' in an interface list with '_'" do
13
+ # So we look supported
14
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
15
+
16
+ Facter::Util::IP.expects(:get_interfaces).returns %w{eth0:1 eth1:2}
17
+ Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2}
18
+ end
19
+ end