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
@@ -1,12 +1,12 @@
1
1
  Facter.add(:architecture) do
2
- confine :kernel => :linux
2
+ confine :kernel => [:linux, :"gnu/kfreebsd"]
3
3
  setcode do
4
4
  model = Facter.value(:hardwaremodel)
5
5
  case model
6
6
  # most linuxen use "x86_64"
7
7
  when "x86_64"
8
8
  case Facter.value(:operatingsystem)
9
- when "Debian", "Gentoo"
9
+ when "Debian", "Gentoo", "GNU/kFreeBSD"
10
10
  "amd64"
11
11
  else
12
12
  model
@@ -23,3 +23,11 @@ Facter.add(:architecture) do
23
23
  end
24
24
  end
25
25
  end
26
+
27
+ Facter.add(:architecture) do
28
+ confine :kernel => :openbsd
29
+ setcode do
30
+ architecture = Facter.value(:hardwaremodel)
31
+ end
32
+ end
33
+
data/lib/facter/domain.rb CHANGED
@@ -9,9 +9,6 @@ Facter.add(:domain) do
9
9
  domain = Facter::Util::Resolution.exec('dnsdomainname')
10
10
  next domain if domain =~ /.+\..+/
11
11
 
12
- domain = Facter::Util::Resolution.exec('domainname')
13
- next domain if domain =~ /.+\..+/
14
-
15
12
  if FileTest.exists?("/etc/resolv.conf")
16
13
  domain = nil
17
14
  search = nil
@@ -7,7 +7,7 @@ Facter.add(:ipaddress) do
7
7
  output.split(/^\S/).each { |str|
8
8
  if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
9
9
  tmp = $1
10
- unless tmp =~ /127\./
10
+ unless tmp =~ /^127\./
11
11
  ip = tmp
12
12
  break
13
13
  end
@@ -27,7 +27,7 @@ Facter.add(:ipaddress) do
27
27
  output.split(/^\S/).each { |str|
28
28
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
29
29
  tmp = $1
30
- unless tmp =~ /127\./
30
+ unless tmp =~ /^127\./
31
31
  ip = tmp
32
32
  break
33
33
  end
@@ -47,7 +47,7 @@ Facter.add(:ipaddress) do
47
47
  output.split(/^\S/).each { |str|
48
48
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
49
49
  tmp = $1
50
- unless tmp =~ /127\./
50
+ unless tmp =~ /^127\./
51
51
  ip = tmp
52
52
  break
53
53
  end
@@ -78,7 +78,7 @@ Facter.add(:ipaddress) do
78
78
  output.split(/^\S/).each { |str|
79
79
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
80
80
  tmp = $1
81
- unless tmp =~ /127\./
81
+ unless tmp =~ /^127\./
82
82
  ip = tmp
83
83
  break
84
84
  end
@@ -98,7 +98,7 @@ Facter.add(:ipaddress) do
98
98
  output.split(/^\S/).each { |str|
99
99
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
100
100
  tmp = $1
101
- unless tmp =~ /127\./
101
+ unless tmp =~ /^127\./
102
102
  ip = tmp
103
103
  break
104
104
  end
@@ -112,29 +112,26 @@ end
112
112
  Facter.add(:ipaddress) do
113
113
  confine :kernel => %w{windows}
114
114
  setcode do
115
- ip = nil
116
- output = %x{ipconfig}
117
-
118
- output.split(/^\S/).each { |str|
119
- if str =~ /IP Address.*: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
120
- tmp = $1
121
- unless tmp =~ /127\./
122
- ip = tmp
123
- break
124
- end
125
- end
126
- }
127
- ip
115
+ require 'socket'
116
+ IPSocket.getaddress(Socket.gethostname)
128
117
  end
129
118
  end
130
119
 
131
120
  Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
132
121
  setcode do
133
- require 'resolv'
134
-
122
+ if Facter.value(:kernel) == 'windows'
123
+ require 'win32/resolv'
124
+ else
125
+ require 'resolv'
126
+ end
127
+
135
128
  begin
136
129
  if hostname = Facter.value(:hostname)
137
- ip = Resolv.getaddress(hostname)
130
+ if Facter.value(:kernel) == 'windows'
131
+ ip = Win32::Resolv.get_resolv_info.last[0]
132
+ else
133
+ ip = Resolv.getaddress(hostname)
134
+ end
138
135
  unless ip == "127.0.0.1"
139
136
  ip
140
137
  end
data/lib/facter/kernel.rb CHANGED
@@ -2,8 +2,10 @@ Facter.add(:kernel) do
2
2
  setcode do
3
3
  require 'rbconfig'
4
4
  case Config::CONFIG['host_os']
5
- when /mswin/i; 'windows'
6
- else Facter::Util::Resolution.exec("uname -s")
5
+ when /mswin|win32|dos|cygwin|mingw/i
6
+ 'windows'
7
+ else
8
+ Facter::Util::Resolution.exec("uname -s")
7
9
  end
8
10
  end
9
11
  end
@@ -67,13 +67,26 @@ end
67
67
  Facter.add(:macaddress) do
68
68
  confine :kernel => %w(windows)
69
69
  setcode do
70
- ether = []
71
- output = %x{ipconfig /all}
72
- output.split(/\r\n/).each do |str|
73
- if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/
74
- ether.push($1.gsub(/-/, ":"))
75
- end
76
- end
77
- ether[0]
70
+ require 'win32ole'
71
+ require 'socket'
72
+
73
+ ether = nil
74
+ host = Socket.gethostname
75
+ connect_string = "winmgmts://#{host}/root/cimv2"
76
+
77
+ wmi = WIN32OLE.connect(connect_string)
78
+
79
+ query = %Q{
80
+ select *
81
+ from Win32_NetworkAdapterConfiguration
82
+ where IPEnabled = True
83
+ }
84
+
85
+ wmi.ExecQuery(query).each{ |nic|
86
+ ether = nic.MacAddress
87
+ break
88
+ }
89
+
90
+ ether
78
91
  end
79
92
  end
data/lib/facter/memory.rb CHANGED
@@ -20,27 +20,68 @@ require 'facter/util/memory'
20
20
  end
21
21
  end
22
22
 
23
- if Facter.value(:kernel) == "AIX"
23
+ if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root"
24
24
  swap = Facter::Util::Resolution.exec('swap -l')
25
25
  swapfree, swaptotal = 0, 0
26
26
  swap.each do |dev|
27
- if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/
27
+ if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/
28
+ swaptotal += $1.to_i
29
+ swapfree += $2.to_i
30
+ end
31
+ end
32
+
33
+ Facter.add("SwapSize") do
34
+ confine :kernel => :aix
35
+ setcode do
36
+ Facter::Memory.scale_number(swaptotal.to_f,"MB")
37
+ end
38
+ end
39
+
40
+ Facter.add("SwapFree") do
41
+ confine :kernel => :aix
42
+ setcode do
43
+ Facter::Memory.scale_number(swapfree.to_f,"MB")
44
+ end
45
+ end
46
+ end
47
+
48
+ if Facter.value(:kernel) == "OpenBSD"
49
+ swap = Facter::Util::Resolution.exec('swapctl -l | sed 1d')
50
+ swapfree, swaptotal = 0, 0
51
+ swap.each do |dev|
52
+ if dev =~ /^\S+\s+(\S+)\s+\S+\s+(\S+)\s+.*$/
28
53
  swaptotal += $1.to_i
29
54
  swapfree += $2.to_i
30
55
  end
31
56
  end
32
57
 
33
58
  Facter.add("SwapSize") do
34
- confine :kernel => :aix
59
+ confine :kernel => :openbsd
35
60
  setcode do
36
- Facter::Memory.scale_number(swaptotal.to_f,"MB")
61
+ Facter::Memory.scale_number(swaptotal.to_f,"kB")
37
62
  end
38
63
  end
39
64
 
40
65
  Facter.add("SwapFree") do
41
- confine :kernel => :aix
66
+ confine :kernel => :openbsd
42
67
  setcode do
43
- Facter::Memory.scale_number(swapfree.to_f,"MB")
68
+ Facter::Memory.scale_number(swapfree.to_f,"kB")
69
+ end
70
+ end
71
+
72
+ Facter.add("MemoryFree") do
73
+ confine :kernel => :openbsd
74
+ memfree = Facter::Util::Resolution.exec("vmstat | tail -n 1 | awk '{ print $5 }'")
75
+ setcode do
76
+ Facter::Memory.scale_number(memfree.to_f,"kB")
77
+ end
78
+ end
79
+
80
+ Facter.add("MemoryTotal") do
81
+ confine :kernel => :openbsd
82
+ memtotal = Facter::Util::Resolution.exec("sysctl hw.physmem | cut -d'=' -f2")
83
+ setcode do
84
+ Facter::Memory.scale_number(memtotal.to_f,"")
44
85
  end
45
86
  end
46
87
  end
@@ -20,6 +20,8 @@ Facter.add(:operatingsystem) do
20
20
  "Mandriva"
21
21
  elsif FileTest.exists?("/etc/mandrake-release")
22
22
  "Mandrake"
23
+ elsif FileTest.exists?("/etc/meego-release")
24
+ "MeeGo"
23
25
  elsif FileTest.exists?("/etc/arch-release")
24
26
  "Archlinux"
25
27
  elsif FileTest.exists?("/etc/enterprise-release")
@@ -48,6 +50,8 @@ Facter.add(:operatingsystem) do
48
50
  else
49
51
  "SuSE"
50
52
  end
53
+ elsif FileTest.exists?("/etc/slackware-version")
54
+ "Slackware"
51
55
  end
52
56
  end
53
57
  end
@@ -1,14 +1,16 @@
1
1
  Facter.add(:operatingsystemrelease) do
2
- confine :operatingsystem => %w{CentOS Fedora oel ovs RedHat}
2
+ confine :operatingsystem => %w{CentOS Fedora oel ovs RedHat MeeGo}
3
3
  setcode do
4
4
  case Facter.value(:operatingsystem)
5
5
  when "CentOS", "RedHat"
6
6
  releasefile = "/etc/redhat-release"
7
7
  when "Fedora"
8
8
  releasefile = "/etc/fedora-release"
9
- when "oel"
9
+ when "MeeGo"
10
+ releasefile = "/etc/meego-release"
11
+ when "OEL", "oel"
10
12
  releasefile = "/etc/enterprise-release"
11
- when "ovs"
13
+ when "OVS", "ovs"
12
14
  releasefile = "/etc/ovs-release"
13
15
  end
14
16
  File::open(releasefile, "r") do |f|
@@ -59,6 +61,16 @@ Facter.add(:operatingsystemrelease) do
59
61
  end
60
62
  end
61
63
 
64
+ Facter.add(:operatingsystemrelease) do
65
+ confine :operatingsystem => %w{Slackware}
66
+ setcode do
67
+ release = Facter::Util::Resolution.exec('cat /etc/slackware-version')
68
+ if release =~ /Slackware ([0-9.]+)/
69
+ $1
70
+ end
71
+ end
72
+ end
73
+
62
74
  Facter.add(:operatingsystemrelease) do
63
75
  setcode do Facter[:kernelrelease].value end
64
76
  end
@@ -72,3 +72,19 @@ if Facter.value(:kernel) == "AIX"
72
72
  end
73
73
  end
74
74
  end
75
+
76
+ if Facter.value(:kernel) == "OpenBSD"
77
+ Facter.add("Processor") do
78
+ confine :kernel => :openbsd
79
+ setcode do
80
+ Facter::Util::Resolution.exec("uname -p")
81
+ end
82
+ end
83
+
84
+ Facter.add("ProcessorCount") do
85
+ confine :kernel => :openbsd
86
+ setcode do
87
+ Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d'=' -f2")
88
+ end
89
+ end
90
+ end
data/lib/facter/uptime.rb CHANGED
@@ -1,20 +1,23 @@
1
1
  require 'facter/util/uptime'
2
2
 
3
3
  Facter.add(:uptime) do
4
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX}
5
- setcode do
6
- Facter::Util::Uptime.get_uptime_simple
7
- end
8
- end
4
+ setcode do
5
+ seconds = Facter.fact(:uptime_seconds).value
9
6
 
10
- if FileTest.exists?("/proc/uptime")
11
- uptime = Facter::Util::Uptime.get_uptime
7
+ unless seconds
8
+ "unknown"
9
+ else
10
+ days = seconds / (60 * 60 * 24)
11
+ hours = seconds / (60 * 60) % 24
12
+ minutes = seconds / 60 % 60
12
13
 
13
- %w{days hours seconds}.each do |label|
14
- Facter.add("uptime_" + label) do
15
- setcode do
16
- Facter::Util::Uptime.get_uptime_period(uptime, label)
17
- end
18
- end
19
- end
14
+ case days
15
+ when 0 then "#{hours}:#{"%02d" % minutes} hours"
16
+ when 1 then '1 day'
17
+ else "#{days} days"
18
+ end
19
+ end
20
+
21
+ end
20
22
  end
23
+
@@ -0,0 +1,7 @@
1
+ Facter.add(:uptime_days) do
2
+ setcode do
3
+ hours = Facter.value(:uptime_hours)
4
+ hours && hours / 24 # hours in day
5
+ end
6
+ end
7
+
@@ -0,0 +1,7 @@
1
+ Facter.add(:uptime_hours) do
2
+ setcode do
3
+ seconds = Facter.value(:uptime_seconds)
4
+ seconds && seconds / (60 * 60) # seconds in hour
5
+ end
6
+ end
7
+
@@ -0,0 +1,10 @@
1
+ require 'facter/util/uptime'
2
+
3
+ Facter.add(:uptime_seconds) do
4
+ setcode { Facter::Util::Uptime.get_uptime_seconds_unix }
5
+ end
6
+
7
+ Facter.add(:uptime_seconds) do
8
+ confine :kernel => :windows
9
+ setcode { Facter::Util::Uptime.get_uptime_seconds_win }
10
+ end
@@ -16,19 +16,24 @@ module Facter::Util::IP
16
16
  :netmask => /netmask\s+0x(\w{8})/
17
17
  },
18
18
  :sunos => {
19
- :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
19
+ :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
20
20
  :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/,
21
21
  :netmask => /netmask\s+(\w{8})/
22
+ },
23
+ :"hp-ux" => {
24
+ :ipaddress => /\s+inet (\S+)\s.*/,
25
+ :macaddress => /(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/,
26
+ :netmask => /.*\s+netmask (\S+)\s.*/
22
27
  }
23
28
  }
24
29
 
25
30
  # Convert an interface name into purely alpha characters.
26
31
  def self.alphafy(interface)
27
- interface.gsub(/[:.]/, '_')
32
+ interface.gsub(/[-:.]/, '_')
28
33
  end
29
34
 
30
35
  def self.convert_from_hex?(kernel)
31
- kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin]
36
+ kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux"]
32
37
  kernels_to_convert.include?(kernel)
33
38
  end
34
39
 
@@ -51,7 +56,7 @@ module Facter::Util::IP
51
56
  # at the end of interfaces. So, we have to trim those trailing
52
57
  # characters. I tried making the regex better but supporting all
53
58
  # platforms with a single regex is probably a bit too much.
54
- output.scan(/^\w+[.:]?\d+[.:]?\d*[.:]?\w*/).collect { |i| i.sub(/:$/, '') }.uniq
59
+ output.scan(/^[-\w]+[.:]?\d+[.:]?\d*[.:]?\w*/).collect { |i| i.sub(/:$/, '') }.uniq
55
60
  end
56
61
 
57
62
  def self.get_all_interface_output
@@ -60,6 +65,8 @@ module Facter::Util::IP
60
65
  output = %x{/sbin/ifconfig -a}
61
66
  when 'SunOS'
62
67
  output = %x{/usr/sbin/ifconfig -a}
68
+ when 'HP-UX'
69
+ output = %x{/bin/netstat -i}
63
70
  end
64
71
  output
65
72
  end
@@ -71,6 +78,12 @@ module Facter::Util::IP
71
78
  output = %x{/sbin/ifconfig #{interface}}
72
79
  when 'SunOS'
73
80
  output = %x{/usr/sbin/ifconfig #{interface}}
81
+ when 'HP-UX'
82
+ mac = ""
83
+ ifc = %x{/usr/sbin/ifconfig #{interface}}
84
+ %x{/usr/sbin/lanscan}.scan(/(\dx\S+).*UP\s+(\w+\d+)/).each {|i| mac = i[0] if i.include?(interface) }
85
+ mac = mac.sub(/0x(\S+)/,'\1').scan(/../).join(":")
86
+ output = ifc + "\n" + mac
74
87
  end
75
88
  output
76
89
  end
@@ -101,7 +114,6 @@ module Facter::Util::IP
101
114
  device
102
115
  end
103
116
 
104
-
105
117
  def self.get_interface_value(interface, label)
106
118
  tmp1 = []
107
119