facter 1.5.7 → 1.5.8

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 (52) hide show
  1. data/CHANGELOG +105 -28
  2. data/Rakefile +23 -20
  3. data/bin/facter +3 -3
  4. data/conf/osx/createpackage.sh +12 -1
  5. data/conf/osx/preflight +4 -0
  6. data/install.rb +7 -14
  7. data/lib/facter.rb +14 -2
  8. data/lib/facter/architecture.rb +10 -2
  9. data/lib/facter/domain.rb +0 -3
  10. data/lib/facter/ipaddress.rb +18 -21
  11. data/lib/facter/kernel.rb +4 -2
  12. data/lib/facter/macaddress.rb +21 -8
  13. data/lib/facter/memory.rb +47 -6
  14. data/lib/facter/operatingsystem.rb +4 -0
  15. data/lib/facter/operatingsystemrelease.rb +15 -3
  16. data/lib/facter/processor.rb +16 -0
  17. data/lib/facter/uptime.rb +17 -14
  18. data/lib/facter/uptime_days.rb +7 -0
  19. data/lib/facter/uptime_hours.rb +7 -0
  20. data/lib/facter/uptime_seconds.rb +10 -0
  21. data/lib/facter/util/ip.rb +17 -5
  22. data/lib/facter/util/manufacturer.rb +13 -7
  23. data/lib/facter/util/resolution.rb +34 -11
  24. data/lib/facter/util/uptime.rb +45 -23
  25. data/lib/facter/util/virtual.rb +23 -1
  26. data/lib/facter/util/vlans.rb +24 -0
  27. data/lib/facter/virtual.rb +11 -3
  28. data/lib/facter/vlans.rb +8 -0
  29. data/spec/fixtures/uptime/sysctl_kern_boottime +0 -0
  30. data/spec/fixtures/uptime/ubuntu_proc_uptime +1 -0
  31. data/spec/fixtures/uptime/who_b_boottime +1 -0
  32. data/spec/spec_helper.rb +2 -0
  33. data/spec/unit/data/freebsd_dmidecode +42 -0
  34. data/spec/unit/data/hpux_ifconfig +3 -0
  35. data/spec/unit/data/hpux_ifconfig_single_interface +3 -0
  36. data/spec/unit/data/hpux_netscan +4 -0
  37. data/spec/unit/data/hpux_netstat_all_interfaces +6 -0
  38. data/spec/unit/data/linux_dmidecode_with_spaces +60 -0
  39. data/spec/unit/data/linux_vlan_config +6 -0
  40. data/spec/unit/data/opensolaris_smbios +33 -0
  41. data/spec/unit/facter.rb +73 -0
  42. data/spec/unit/operatingsystemrelease.rb +39 -0
  43. data/spec/unit/uptime.rb +112 -0
  44. data/spec/unit/util/ip.rb +59 -2
  45. data/spec/unit/util/manufacturer.rb +121 -0
  46. data/spec/unit/util/resolution.rb +44 -11
  47. data/spec/unit/util/uptime.rb +53 -0
  48. data/spec/unit/util/virtual.rb +24 -1
  49. data/spec/unit/util/vlans.rb +14 -0
  50. data/spec/unit/virtual.rb +20 -0
  51. metadata +115 -91
  52. data/ChangeLog +0 -1727
@@ -2,8 +2,8 @@
2
2
  # Support methods for manufacturer specific facts
3
3
 
4
4
  module Facter::Manufacturer
5
- def self.dmi_find_system_info(name)
6
- splitstr="Handle"
5
+
6
+ def self.get_dmi_table()
7
7
  case Facter.value(:kernel)
8
8
  when 'Linux'
9
9
  return nil unless FileTest.exists?("/usr/sbin/dmidecode")
@@ -19,18 +19,24 @@ module Facter::Manufacturer
19
19
  output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
20
20
  when 'SunOS'
21
21
  return nil unless FileTest.exists?("/usr/sbin/smbios")
22
- splitstr="ID SIZE TYPE"
23
- output=%x{/usr/sbin/smbios 2>/dev/null}
24
22
 
23
+ output=%x{/usr/sbin/smbios 2>/dev/null}
25
24
  else
26
- return
25
+ output=nil
27
26
  end
27
+ return output
28
+ end
29
+
30
+ def self.dmi_find_system_info(name)
31
+ splitstr= Facter.value(:kernel) == 'SunOS' ? "ID SIZE TYPE" : /^Handle/
32
+ output = self.get_dmi_table()
33
+ return if output.nil?
28
34
  name.each_pair do |key,v|
29
35
  v.each do |v2|
30
36
  v2.each_pair do |value,facterkey|
31
37
  output.split(splitstr).each do |line|
32
- if line =~ /#{key}/ and ( line =~ /#{value} 0x\d+ \(([-\w].*)\)\n*./ or line =~ /#{value} ([-\w].*)\n*./ )
33
- result = $1
38
+ if line =~ /#{key}/ and line =~ /\n\s+#{value} (.+)\n/
39
+ result = $1.strip
34
40
  Facter.add(facterkey) do
35
41
  confine :kernel => [ :linux, :freebsd, :netbsd, :sunos ]
36
42
  setcode do
@@ -11,9 +11,13 @@ require 'rbconfig'
11
11
  class Facter::Util::Resolution
12
12
  attr_accessor :interpreter, :code, :name, :timeout
13
13
 
14
+ WINDOWS = Config::CONFIG['host_os'] =~ /mswin|win32|dos|mingw|cygwin/i
15
+
16
+ INTERPRETER = WINDOWS ? 'cmd.exe' : '/bin/sh'
17
+
14
18
  def self.have_which
15
19
  if ! defined?(@have_which) or @have_which.nil?
16
- if Config::CONFIG['host_os'] =~ /mswin/
20
+ if Facter.value(:kernel) == 'windows'
17
21
  @have_which = false
18
22
  else
19
23
  %x{which which >/dev/null 2>&1}
@@ -23,31 +27,50 @@ class Facter::Util::Resolution
23
27
  @have_which
24
28
  end
25
29
 
26
- # Execute a chunk of code.
27
- def self.exec(code, interpreter = "/bin/sh")
28
- raise ArgumentError, "non-sh interpreters are not currently supported" unless interpreter == "/bin/sh"
29
- binary = code.split(/\s+/).shift
30
-
31
- if have_which
30
+ # Execute a program and return the output of that program.
31
+ #
32
+ # Returns nil if the program can't be found, or if there is a problem
33
+ # executing the code.
34
+ #
35
+ def self.exec(code, interpreter = INTERPRETER)
36
+ raise ArgumentError, "invalid interpreter" unless interpreter == INTERPRETER
37
+
38
+ # Try to guess whether the specified code can be executed by looking at the
39
+ # first word. If it cannot be found on the PATH defer on resolving the fact
40
+ # by returning nil.
41
+ # This only fails on shell built-ins, most of which are masked by stuff in
42
+ # /bin or of dubious value anyways. In the worst case, "sh -c 'builtin'" can
43
+ # be used to work around this limitation
44
+ #
45
+ # Windows' %x{} throws Errno::ENOENT when the command is not found, so we
46
+ # can skip the check there. This is good, since builtins cannot be found
47
+ # elsewhere.
48
+ if have_which and !WINDOWS
32
49
  path = nil
33
- if binary !~ /^\//
50
+ binary = code.split.first
51
+ if code =~ /^\//
52
+ path = binary
53
+ else
34
54
  path = %x{which #{binary} 2>/dev/null}.chomp
35
55
  # we don't have the binary necessary
36
56
  return nil if path == "" or path.match(/Command not found\./)
37
- else
38
- path = binary
39
57
  end
40
58
 
41
59
  return nil unless FileTest.exists?(path)
42
60
  end
43
61
 
44
62
  out = nil
63
+
45
64
  begin
46
65
  out = %x{#{code}}.chomp
66
+ rescue Errno::ENOENT => detail
67
+ # command not found on Windows
68
+ return nil
47
69
  rescue => detail
48
70
  $stderr.puts detail
49
71
  return nil
50
72
  end
73
+
51
74
  if out == ""
52
75
  return nil
53
76
  else
@@ -86,7 +109,7 @@ class Facter::Util::Resolution
86
109
  def setcode(string = nil, interp = nil, &block)
87
110
  if string
88
111
  @code = string
89
- @interpreter = interp || "/bin/sh"
112
+ @interpreter = interp || INTERPRETER
90
113
  else
91
114
  unless block_given?
92
115
  raise ArgumentError, "You must pass either code or a block"
@@ -1,32 +1,54 @@
1
+ require 'time'
2
+
1
3
  # A module to gather uptime facts
2
4
  #
3
5
  module Facter::Util::Uptime
4
- def self.get_uptime_simple
5
- time = Facter::Util::Resolution.exec('uptime')
6
- if time =~ /up\s*(\d+\s\w+)/
7
- $1
8
- elsif time =~ /up\s*(\d+:\d+)/
9
- $1 + " hours"
10
- else
11
- "unknown"
6
+ def self.get_uptime_seconds_unix
7
+ uptime_proc_uptime or uptime_sysctl or uptime_who_dash_b
8
+ end
9
+
10
+ def self.get_uptime_seconds_win
11
+ require 'win32ole'
12
+ wmi = WIN32OLE.connect("winmgmts://")
13
+ query = wmi.ExecQuery("select * from Win32_OperatingSystem")
14
+ last_boot = ""
15
+ query.each { |x| last_boot = x.LastBootupTime}
16
+ self.compute_uptime(Time.parse(last_boot.split('.').first))
17
+ end
18
+
19
+ private
20
+
21
+ def self.uptime_proc_uptime
22
+ if output = Facter::Util::Resolution.exec("/bin/cat #{uptime_file} 2>/dev/null")
23
+ output.chomp.split(" ").first.to_i
24
+ end
25
+ end
26
+
27
+ def self.uptime_sysctl
28
+ if output = Facter::Util::Resolution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
29
+ compute_uptime(Time.at(output.unpack('L').first))
30
+ end
31
+ end
32
+
33
+ def self.uptime_who_dash_b
34
+ if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null")
35
+ compute_uptime(Time.parse(output))
12
36
  end
13
37
  end
14
38
 
15
- def self.get_uptime
16
- r = IO.popen("/bin/cat /proc/uptime")
17
- uptime, idletime = r.readline.split(" ")
18
- r.close
19
- uptime_seconds = uptime.to_i
39
+ def self.compute_uptime(time)
40
+ (Time.now - time).to_i
41
+ end
42
+
43
+ def self.uptime_file
44
+ "/proc/uptime"
45
+ end
46
+
47
+ def self.uptime_sysctl_cmd
48
+ 'sysctl -b kern.boottime'
20
49
  end
21
50
 
22
- def self.get_uptime_period(seconds, label)
23
- case label
24
- when 'days'
25
- value = seconds / 86400
26
- when 'hours'
27
- value = seconds / 3600
28
- when 'seconds'
29
- seconds
30
- end
51
+ def self.uptime_who_cmd
52
+ 'who -b'
31
53
  end
32
- end
54
+ end
@@ -1,6 +1,6 @@
1
1
  module Facter::Util::Virtual
2
2
  def self.openvz?
3
- FileTest.exists?("/proc/vz/veinfo")
3
+ FileTest.directory?("/proc/vz")
4
4
  end
5
5
 
6
6
  def self.openvz_type
@@ -13,6 +13,7 @@ module Facter::Util::Virtual
13
13
  end
14
14
 
15
15
  def self.zone?
16
+ return true if FileTest.directory?("/.SUNWnative")
16
17
  z = Facter::Util::Resolution.exec("/sbin/zonename")
17
18
  return false unless z
18
19
  return z.chomp != 'global'
@@ -40,4 +41,25 @@ module Facter::Util::Virtual
40
41
  FileTest.exists?(f)
41
42
  end
42
43
  end
44
+
45
+ def self.kvm?
46
+ txt = if FileTest.exists?("/proc/cpuinfo")
47
+ File.read("/proc/cpuinfo")
48
+ elsif Facter.value(:kernel)=="FreeBSD"
49
+ Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model")
50
+ end
51
+ (txt =~ /QEMU Virtual CPU/) ? true : false
52
+ end
53
+
54
+ def self.kvm_type
55
+ # TODO Tell the difference between kvm and qemu
56
+ # Can't work out a way to do this at the moment that doesn't
57
+ # require a special binary
58
+ "kvm"
59
+ end
60
+
61
+ def self.jail?
62
+ Facter::Util::Resolution.exec("/sbin/sysctl -n security.jail.jailed") == "1"
63
+ end
64
+
43
65
  end
@@ -0,0 +1,24 @@
1
+ # A module to gather vlan facts
2
+ #
3
+ module Facter::Util::Vlans
4
+ def self.get_vlan_config
5
+ output = ""
6
+ if File.exists?('/proc/net/vlan/config') and File.readable?('/proc/net/vlan/config')
7
+ output = File.open('/proc/net/vlan/config').read
8
+ end
9
+ output
10
+ end
11
+
12
+ def self.get_vlans
13
+ vlans = Array.new
14
+ if self.get_vlan_config
15
+ self.get_vlan_config.each do |line|
16
+ if line =~ /^([0-9A-Za-z]+)\.([0-9]+) /
17
+ vlans.insert(-1, $~[2]) if $~[2]
18
+ end
19
+ end
20
+ end
21
+
22
+ vlans.join(',')
23
+ end
24
+ end
@@ -25,15 +25,23 @@ Facter.add("virtual") do
25
25
  if FileTest.exists?("/sys/bus/xen")
26
26
  result = "xenu"
27
27
  end
28
-
28
+
29
29
  if FileTest.exists?("/proc/xen/capabilities")
30
- txt = File.read("/proc/xen/capabilities")
30
+ txt = Facter::Util::Resolution.exec("cat /proc/xen/capabilities")
31
31
  if txt =~ /control_d/i
32
32
  result = "xen0"
33
33
  end
34
34
  end
35
35
  end
36
36
 
37
+ if Facter::Util::Virtual.kvm?
38
+ result = Facter::Util::Virtual.kvm_type()
39
+ end
40
+
41
+ if Facter.value(:kernel)=="FreeBSD"
42
+ result = "jail" if Facter::Util::Virtual.jail?
43
+ end
44
+
37
45
  if result == "physical"
38
46
  output = Facter::Util::Resolution.exec('lspci')
39
47
  if not output.nil?
@@ -72,7 +80,7 @@ Facter.add("is_virtual") do
72
80
 
73
81
  setcode do
74
82
  case Facter.value(:virtual)
75
- when "xenu", "openvzve", "vmware"
83
+ when "xenu", "openvzve", "vmware", "kvm", "vserver", "jail"
76
84
  true
77
85
  else
78
86
  false
@@ -0,0 +1,8 @@
1
+ require 'facter/util/vlans'
2
+
3
+ Facter.add("vlans") do
4
+ confine :kernel => :linux
5
+ setcode do
6
+ Facter::Util::Vlans.get_vlans
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ 5097686.63 40756306.43
@@ -0,0 +1 @@
1
+ reboot ~ Aug 1 14:13
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  dir = File.expand_path(File.dirname(__FILE__))
2
2
 
3
+ SPECDIR = dir
4
+
3
5
  $LOAD_PATH.unshift("#{dir}/")
4
6
  $LOAD_PATH.unshift("#{dir}/../lib")
5
7
 
@@ -0,0 +1,42 @@
1
+ # dmidecode 2.10
2
+ SMBIOS 2.5 present.
3
+ 5 structures occupying 352 bytes.
4
+ Table at 0x000E1000.
5
+
6
+ Handle 0x0000, DMI type 0, 20 bytes
7
+ BIOS Information
8
+ Vendor: innotek GmbH
9
+ Version: VirtualBox
10
+ Release Date: 12/01/2006
11
+ Address: 0xE0000
12
+ Runtime Size: 128 kB
13
+ ROM Size: 128 kB
14
+ Characteristics:
15
+ ISA is supported
16
+ PCI is supported
17
+ Boot from CD is supported
18
+ Selectable boot is supported
19
+ 8042 keyboard services are supported (int 9h)
20
+ CGA/mono video services are supported (int 10h)
21
+ ACPI is supported
22
+
23
+ Handle 0x0001, DMI type 1, 27 bytes
24
+ System Information
25
+ Manufacturer: innotek GmbH
26
+ Product Name: VirtualBox
27
+ Version: 1.2
28
+ Serial Number: 0
29
+ UUID: 3BD58031-AE9E-4F06-8A57-941942861939
30
+ Wake-up Type: Power Switch
31
+ SKU Number: Not Specified
32
+ Family: Virtual Machine
33
+
34
+ Handle 0x0003, DMI type 126, 13 bytes
35
+ Inactive
36
+
37
+ Handle 0x0002, DMI type 126, 7 bytes
38
+ Inactive
39
+
40
+ Handle 0xFEFF, DMI type 127, 147 bytes
41
+ End Of Table
42
+
@@ -0,0 +1,3 @@
1
+ lan0: flags=1843<UP,BROADCAST,RUNNING,MULTICAST,CKO>
2
+ inet 168.24.80.71 netmask ffffff00 broadcast 168.24.80.255
3
+ 00:13:21:BD:9C:B7
@@ -0,0 +1,3 @@
1
+ lan0: flags=1843<UP,BROADCAST,RUNNING,MULTICAST,CKO>
2
+ inet 168.24.80.71 netmask ffffff00 broadcast 168.24.80.255
3
+ 00:13:21:BD:9C:B7
@@ -0,0 +1,4 @@
1
+ Hardware Station Crd Hdw Net-Interface NM MAC HP-DLPI DLPI
2
+ Path Address In# State NamePPA ID Type Support Mjr#
3
+ 0/1/2/0 0x001321BD9CB7 0 UP lan0 snap0 1 ETHER Yes 119
4
+ 0/6/1/0 0x001321BDACDB 1 UP lan1 snap1 2 ETHER Yes 119
@@ -0,0 +1,6 @@
1
+ Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll
2
+ lan1 1500 15.12.0.0 host1.default.com
3
+ 572527659 0 1129421249 0 0
4
+ lan0 1500 172.54.85.0 host2.default.com
5
+ 519222647 0 329127145 0 0
6
+ lo0 4136 loopback localhost 14281117 0 14281125 0 0
@@ -0,0 +1,60 @@
1
+ # dmidecode 2.2
2
+ SMBIOS 2.3 present.
3
+ 32 structures occupying 994 bytes.
4
+ Table at 0x000F0800.
5
+ Handle 0x0000
6
+ DMI type 0, 20 bytes.
7
+ BIOS Information
8
+ Vendor: Award Software International, Inc.
9
+ Version: 6.00 PG
10
+ Release Date: 01/03/2003
11
+ Address: 0xE0000
12
+ Runtime Size: 128 kB
13
+ ROM Size: 256 kB
14
+ Characteristics:
15
+ ISA is supported
16
+ PCI is supported
17
+ PNP is supported
18
+ APM is supported
19
+ BIOS is upgradeable
20
+ BIOS shadowing is allowed
21
+ ESCD support is available
22
+ Boot from CD is supported
23
+ Selectable boot is supported
24
+ BIOS ROM is socketed
25
+ EDD is supported
26
+ 5.25"/360 KB floppy services are supported (int 13h)
27
+ 5.25"/1.2 MB floppy services are supported (int 13h)
28
+ 3.5"/720 KB floppy services are supported (int 13h)
29
+ 3.5"/2.88 MB floppy services are supported (int 13h)
30
+ Print screen service is supported (int 5h)
31
+ 8042 keyboard services are supported (int 9h)
32
+ Serial services are supported (int 14h)
33
+ Printer services are supported (int 17h)
34
+ CGA/mono video services are supported (int 10h)
35
+ ACPI is supported
36
+ USB legacy is supported
37
+ AGP is supported
38
+ LS-120 boot is supported
39
+ ATAPI Zip drive boot is supported
40
+ Handle 0x0001
41
+ DMI type 1, 25 bytes.
42
+ System Information
43
+ Manufacturer: MICRO-STAR INTERNATIONAL CO., LTD
44
+ Product Name: MS-6754
45
+ Version:
46
+ Serial Number:
47
+ UUID: Not Present
48
+ Wake-up Type: Power Switch
49
+ Handle 0x0002
50
+ DMI type 2, 8 bytes.
51
+ Base Board Information
52
+ Manufacturer: MICRO-STAR INTERNATIONAL CO., LTD
53
+ Product Name: MS-6754
54
+ Version:
55
+ Serial Number:
56
+
57
+ Handle 0x001F
58
+ DMI type 127, 4 bytes.
59
+ End Of Table
60
+