facter 1.6.1 → 1.6.2

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 (88) hide show
  1. data/CHANGELOG +31 -0
  2. data/Rakefile +41 -36
  3. data/conf/redhat/facter.spec +11 -4
  4. data/conf/solaris/pkginfo +1 -1
  5. data/install.rb +286 -286
  6. data/lib/facter.rb +211 -211
  7. data/lib/facter/Cfkey.rb +24 -24
  8. data/lib/facter/application.rb +1 -0
  9. data/lib/facter/architecture.rb +21 -29
  10. data/lib/facter/domain.rb +34 -34
  11. data/lib/facter/facterversion.rb +1 -1
  12. data/lib/facter/fqdn.rb +8 -8
  13. data/lib/facter/hardwareisa.rb +2 -2
  14. data/lib/facter/hardwaremodel.rb +12 -12
  15. data/lib/facter/hostname.rb +14 -14
  16. data/lib/facter/id.rb +3 -3
  17. data/lib/facter/interfaces.rb +13 -13
  18. data/lib/facter/ipaddress.rb +101 -101
  19. data/lib/facter/iphostnumber.rb +12 -12
  20. data/lib/facter/kernel.rb +7 -7
  21. data/lib/facter/kernelmajversion.rb +3 -3
  22. data/lib/facter/kernelrelease.rb +12 -12
  23. data/lib/facter/kernelversion.rb +5 -5
  24. data/lib/facter/lsb.rb +14 -14
  25. data/lib/facter/lsbmajdistrelease.rb +8 -8
  26. data/lib/facter/macaddress.rb +44 -44
  27. data/lib/facter/macosx.rb +21 -21
  28. data/lib/facter/manufacturer.rb +28 -28
  29. data/lib/facter/memory.rb +143 -115
  30. data/lib/facter/netmask.rb +4 -4
  31. data/lib/facter/network.rb +4 -4
  32. data/lib/facter/operatingsystem.rb +73 -69
  33. data/lib/facter/operatingsystemrelease.rb +85 -79
  34. data/lib/facter/osfamily.rb +31 -0
  35. data/lib/facter/path.rb +3 -3
  36. data/lib/facter/physicalprocessorcount.rb +8 -0
  37. data/lib/facter/processor.rb +91 -72
  38. data/lib/facter/ps.rb +3 -3
  39. data/lib/facter/puppetversion.rb +7 -7
  40. data/lib/facter/rubysitedir.rb +5 -5
  41. data/lib/facter/rubyversion.rb +1 -1
  42. data/lib/facter/ssh.rb +16 -16
  43. data/lib/facter/timezone.rb +3 -3
  44. data/lib/facter/uniqueid.rb +2 -2
  45. data/lib/facter/util/collection.rb +96 -96
  46. data/lib/facter/util/confine.rb +30 -30
  47. data/lib/facter/util/fact.rb +95 -95
  48. data/lib/facter/util/ip.rb +173 -173
  49. data/lib/facter/util/loader.rb +88 -88
  50. data/lib/facter/util/macosx.rb +46 -46
  51. data/lib/facter/util/manufacturer.rb +78 -78
  52. data/lib/facter/util/memory.rb +63 -63
  53. data/lib/facter/util/netmask.rb +34 -34
  54. data/lib/facter/util/plist.rb +1 -1
  55. data/lib/facter/util/plist/generator.rb +177 -177
  56. data/lib/facter/util/plist/parser.rb +166 -166
  57. data/lib/facter/util/processor.rb +88 -0
  58. data/lib/facter/util/resolution.rb +154 -154
  59. data/lib/facter/util/uptime.rb +42 -42
  60. data/lib/facter/util/values.rb +9 -9
  61. data/lib/facter/util/virtual.rb +68 -58
  62. data/lib/facter/util/vlans.rb +17 -17
  63. data/lib/facter/virtual.rb +105 -110
  64. data/lib/facter/vlans.rb +6 -6
  65. data/spec/fixtures/cpuinfo/amd64dual +57 -0
  66. data/spec/fixtures/cpuinfo/amd64quad +79 -0
  67. data/spec/fixtures/cpuinfo/amd64solo +23 -0
  68. data/spec/fixtures/cpuinfo/amd64tri +86 -0
  69. data/spec/fixtures/cpuinfo/bbg3-armel +12 -0
  70. data/spec/fixtures/cpuinfo/beaglexm-armel +12 -0
  71. data/spec/fixtures/cpuinfo/panda-armel +17 -0
  72. data/spec/fixtures/cpuinfo/ppc64 +19 -0
  73. data/spec/fixtures/cpuinfo/sparc +10 -0
  74. data/spec/fixtures/processorcount/solaris-sparc-kstat-cpu-info +1216 -0
  75. data/spec/fixtures/processorcount/solaris-x86_64-kstat-cpu-info +225 -0
  76. data/spec/integration/facter_spec.rb +18 -18
  77. data/spec/spec_helper.rb +10 -1
  78. data/spec/unit/architecture_spec.rb +54 -0
  79. data/spec/unit/domain_spec.rb +23 -0
  80. data/spec/unit/memory_spec.rb +78 -1
  81. data/spec/unit/physicalprocessorcount_spec.rb +41 -35
  82. data/spec/unit/processor_spec.rb +183 -2
  83. data/spec/unit/util/processor_spec.rb +62 -0
  84. data/spec/unit/util/uptime_spec.rb +4 -4
  85. data/spec/unit/util/virtual_spec.rb +26 -5
  86. data/spec/unit/virtual_spec.rb +47 -2
  87. data/spec/watchr.rb +125 -0
  88. metadata +20 -4
@@ -35,6 +35,7 @@ module Facter
35
35
  # Print the facts as JSON and exit
36
36
  if options[:json]
37
37
  begin
38
+ require 'rubygems'
38
39
  require 'json'
39
40
  puts JSON.dump(facts)
40
41
  exit(0)
@@ -12,35 +12,27 @@
12
12
  #
13
13
 
14
14
  Facter.add(:architecture) do
15
- confine :kernel => [:linux, :"gnu/kfreebsd"]
16
- setcode do
17
- model = Facter.value(:hardwaremodel)
18
- case model
19
- # most linuxen use "x86_64"
20
- when "x86_64"
21
- case Facter.value(:operatingsystem)
22
- when "Debian", "Gentoo", "GNU/kFreeBSD"
23
- "amd64"
24
- else
25
- model
26
- end
27
- when /(i[3456]86|pentium)/
28
- case Facter.value(:operatingsystem)
29
- when "Gentoo"
30
- "x86"
31
- else
32
- "i386"
33
- end
34
- else
35
- model
36
- end
37
- end
38
- end
39
-
40
- Facter.add(:architecture) do
41
- confine :kernel => :openbsd
42
- setcode do
43
- architecture = Facter.value(:hardwaremodel)
15
+ setcode do
16
+ model = Facter.value(:hardwaremodel)
17
+ case model
18
+ # most linuxen use "x86_64"
19
+ when "x86_64"
20
+ case Facter.value(:operatingsystem)
21
+ when "Debian", "Gentoo", "GNU/kFreeBSD", "Ubuntu"
22
+ "amd64"
23
+ else
24
+ model
25
+ end
26
+ when /(i[3456]86|pentium)/
27
+ case Facter.value(:operatingsystem)
28
+ when "Gentoo"
29
+ "x86"
30
+ else
31
+ "i386"
32
+ end
33
+ else
34
+ model
44
35
  end
36
+ end
45
37
  end
46
38
 
@@ -19,45 +19,45 @@
19
19
  #
20
20
 
21
21
  Facter.add(:domain) do
22
- setcode do
23
- # Get the domain from various sources; the order of these
24
- # steps is important
22
+ setcode do
23
+ # Get the domain from various sources; the order of these
24
+ # steps is important
25
25
 
26
- if name = Facter::Util::Resolution.exec('hostname') and
27
- name =~ /.*?\.(.+$)/
26
+ if name = Facter::Util::Resolution.exec('hostname') and
27
+ name =~ /.*?\.(.+$)/
28
28
 
29
- $1
30
- elsif domain = Facter::Util::Resolution.exec('dnsdomainname') and
31
- domain =~ /.+\..+/
29
+ $1
30
+ elsif domain = Facter::Util::Resolution.exec('dnsdomainname') and
31
+ domain =~ /.+\..+/
32
32
 
33
- domain
34
- elsif FileTest.exists?("/etc/resolv.conf")
35
- domain = nil
36
- search = nil
37
- File.open("/etc/resolv.conf") { |file|
38
- file.each { |line|
39
- if line =~ /domain\s+(\S+)/
40
- domain = $1
41
- elsif line =~ /search\s+(\S+)/
42
- search = $1
43
- end
44
- }
45
- }
46
- next domain if domain
47
- next search if search
48
- end
33
+ domain
34
+ elsif FileTest.exists?("/etc/resolv.conf")
35
+ domain = nil
36
+ search = nil
37
+ File.open("/etc/resolv.conf") { |file|
38
+ file.each { |line|
39
+ if line =~ /^\s*domain\s+(\S+)/
40
+ domain = $1
41
+ elsif line =~ /^\s*search\s+(\S+)/
42
+ search = $1
43
+ end
44
+ }
45
+ }
46
+ next domain if domain
47
+ next search if search
49
48
  end
49
+ end
50
50
  end
51
51
 
52
52
  Facter.add(:domain) do
53
- confine :kernel => :windows
54
- setcode do
55
- require 'facter/util/wmi'
56
- domain = ""
57
- Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
58
- domain = nic.DNSDomain
59
- break
60
- }
61
- domain
62
- end
53
+ confine :kernel => :windows
54
+ setcode do
55
+ require 'facter/util/wmi'
56
+ domain = ""
57
+ Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
58
+ domain = nic.DNSDomain
59
+ break
60
+ }
61
+ domain
62
+ end
63
63
  end
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  Facter.add(:facterversion) do
11
- setcode { Facter::FACTERVERSION.to_s }
11
+ setcode { Facter::FACTERVERSION.to_s }
12
12
  end
@@ -10,13 +10,13 @@
10
10
  #
11
11
 
12
12
  Facter.add(:fqdn) do
13
- setcode do
14
- host = Facter.value(:hostname)
15
- domain = Facter.value(:domain)
16
- if host and domain
17
- [host, domain].join(".")
18
- else
19
- nil
20
- end
13
+ setcode do
14
+ host = Facter.value(:hostname)
15
+ domain = Facter.value(:domain)
16
+ if host and domain
17
+ [host, domain].join(".")
18
+ else
19
+ nil
21
20
  end
21
+ end
22
22
  end
@@ -11,6 +11,6 @@
11
11
  #
12
12
 
13
13
  Facter.add(:hardwareisa) do
14
- setcode 'uname -p'
15
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OracleLinux OVS GNU/kFreeBSD}
14
+ setcode 'uname -p'
15
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD DragonFly OEL OracleLinux OVS GNU/kFreeBSD}
16
16
  end
@@ -12,23 +12,23 @@
12
12
  #
13
13
 
14
14
  Facter.add(:hardwaremodel) do
15
- setcode 'uname -m'
15
+ setcode 'uname -m'
16
16
  end
17
17
 
18
18
  Facter.add(:hardwaremodel) do
19
- confine :operatingsystem => :aix
20
- setcode do
21
- model = Facter::Util::Resolution.exec('lsattr -El sys0 -a modelname')
22
- if model =~ /modelname\s(\S+)\s/
23
- $1
24
- end
19
+ confine :operatingsystem => :aix
20
+ setcode do
21
+ model = Facter::Util::Resolution.exec('lsattr -El sys0 -a modelname')
22
+ if model =~ /modelname\s(\S+)\s/
23
+ $1
25
24
  end
25
+ end
26
26
  end
27
27
 
28
28
  Facter.add(:hardwaremodel) do
29
- confine :operatingsystem => :windows
30
- setcode do
31
- require 'rbconfig'
32
- Config::CONFIG['host_cpu']
33
- end
29
+ confine :operatingsystem => :windows
30
+ setcode do
31
+ require 'rbconfig'
32
+ Config::CONFIG['host_cpu']
33
+ end
34
34
  end
@@ -12,22 +12,22 @@
12
12
  #
13
13
 
14
14
  Facter.add(:hostname, :ldapname => "cn") do
15
- setcode do
16
- hostname = nil
17
- if name = Facter::Util::Resolution.exec('hostname')
18
- if name =~ /(.*?)\./
19
- hostname = $1
20
- else
21
- hostname = name
22
- end
23
- end
24
- hostname
15
+ setcode do
16
+ hostname = nil
17
+ if name = Facter::Util::Resolution.exec('hostname')
18
+ if name =~ /(.*?)\./
19
+ hostname = $1
20
+ else
21
+ hostname = name
22
+ end
25
23
  end
24
+ hostname
25
+ end
26
26
  end
27
27
 
28
28
  Facter.add(:hostname) do
29
- confine :kernel => :darwin, :kernelrelease => "R7"
30
- setcode do
31
- Facter::Util::Resolution.exec('/usr/sbin/scutil --get LocalHostName')
32
- end
29
+ confine :kernel => :darwin, :kernelrelease => "R7"
30
+ setcode do
31
+ Facter::Util::Resolution.exec('/usr/sbin/scutil --get LocalHostName')
32
+ end
33
33
  end
@@ -12,10 +12,10 @@
12
12
  #
13
13
 
14
14
  Facter.add(:id) do
15
- setcode "whoami"
15
+ setcode "whoami"
16
16
  end
17
17
 
18
18
  Facter.add(:id) do
19
- confine :kernel => :SunOS
20
- setcode "/usr/xpg4/bin/id -un"
19
+ confine :kernel => :SunOS
20
+ setcode "/usr/xpg4/bin/id -un"
21
21
  end
@@ -20,22 +20,22 @@ require 'facter/util/ip'
20
20
  # is missing.
21
21
 
22
22
  Facter.add(:interfaces) do
23
- confine :kernel => Facter::Util::IP.supported_platforms
24
- setcode do
25
- Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",")
26
- end
23
+ confine :kernel => Facter::Util::IP.supported_platforms
24
+ setcode do
25
+ Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",")
26
+ end
27
27
  end
28
28
 
29
29
  Facter::Util::IP.get_interfaces.each do |interface|
30
30
 
31
- # Make a fact for each detail of each interface. Yay.
32
- # There's no point in confining these facts, since we wouldn't be able to create
33
- # them if we weren't running on a supported platform.
34
- %w{ipaddress ipaddress6 macaddress netmask}.each do |label|
35
- Facter.add(label + "_" + Facter::Util::IP.alphafy(interface)) do
36
- setcode do
37
- Facter::Util::IP.get_interface_value(interface, label)
38
- end
39
- end
31
+ # Make a fact for each detail of each interface. Yay.
32
+ # There's no point in confining these facts, since we wouldn't be able to create
33
+ # them if we weren't running on a supported platform.
34
+ %w{ipaddress ipaddress6 macaddress netmask}.each do |label|
35
+ Facter.add(label + "_" + Facter::Util::IP.alphafy(interface)) do
36
+ setcode do
37
+ Facter::Util::IP.get_interface_value(interface, label)
38
+ end
40
39
  end
40
+ end
41
41
  end
@@ -23,138 +23,138 @@
23
23
  #
24
24
 
25
25
  Facter.add(:ipaddress) do
26
- confine :kernel => :linux
27
- setcode do
28
- ip = nil
29
- output = %x{/sbin/ifconfig}
26
+ confine :kernel => :linux
27
+ setcode do
28
+ ip = nil
29
+ output = %x{/sbin/ifconfig}
30
30
 
31
- output.split(/^\S/).each { |str|
32
- if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
33
- tmp = $1
34
- unless tmp =~ /^127\./
35
- ip = tmp
36
- break
37
- end
38
- end
39
- }
31
+ output.split(/^\S/).each { |str|
32
+ if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
33
+ tmp = $1
34
+ unless tmp =~ /^127\./
35
+ ip = tmp
36
+ break
37
+ end
38
+ end
39
+ }
40
40
 
41
- ip
42
- end
41
+ ip
42
+ end
43
43
  end
44
44
 
45
45
  Facter.add(:ipaddress) do
46
- confine :kernel => %w{FreeBSD OpenBSD Darwin}
47
- setcode do
48
- ip = nil
49
- output = %x{/sbin/ifconfig}
46
+ confine :kernel => %w{FreeBSD OpenBSD Darwin DragonFly}
47
+ setcode do
48
+ ip = nil
49
+ output = %x{/sbin/ifconfig}
50
50
 
51
- output.split(/^\S/).each { |str|
52
- if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
53
- tmp = $1
54
- unless tmp =~ /^127\./
55
- ip = tmp
56
- break
57
- end
58
- end
59
- }
51
+ output.split(/^\S/).each { |str|
52
+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
53
+ tmp = $1
54
+ unless tmp =~ /^127\./
55
+ ip = tmp
56
+ break
57
+ end
58
+ end
59
+ }
60
60
 
61
- ip
62
- end
61
+ ip
62
+ end
63
63
  end
64
64
 
65
65
  Facter.add(:ipaddress) do
66
- confine :kernel => %w{NetBSD SunOS}
67
- setcode do
68
- ip = nil
69
- output = %x{/sbin/ifconfig -a}
66
+ confine :kernel => %w{NetBSD SunOS}
67
+ setcode do
68
+ ip = nil
69
+ output = %x{/sbin/ifconfig -a}
70
70
 
71
- output.split(/^\S/).each { |str|
72
- if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
73
- tmp = $1
74
- unless tmp =~ /^127\./ or tmp == "0.0.0.0"
75
- ip = tmp
76
- break
77
- end
78
- end
79
- }
71
+ output.split(/^\S/).each { |str|
72
+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
73
+ tmp = $1
74
+ unless tmp =~ /^127\./ or tmp == "0.0.0.0"
75
+ ip = tmp
76
+ break
77
+ end
78
+ end
79
+ }
80
80
 
81
- ip
82
- end
81
+ ip
82
+ end
83
83
  end
84
84
 
85
85
  Facter.add(:ipaddress) do
86
- confine :kernel => %w{AIX}
87
- setcode do
88
- ip = nil
89
- output = %x{/usr/sbin/ifconfig -a}
86
+ confine :kernel => %w{AIX}
87
+ setcode do
88
+ ip = nil
89
+ output = %x{/usr/sbin/ifconfig -a}
90
90
 
91
- output.split(/^\S/).each { |str|
92
- if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
93
- tmp = $1
94
- unless tmp =~ /^127\./
95
- ip = tmp
96
- break
97
- end
98
- end
99
- }
91
+ output.split(/^\S/).each { |str|
92
+ if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
93
+ tmp = $1
94
+ unless tmp =~ /^127\./
95
+ ip = tmp
96
+ break
97
+ end
98
+ end
99
+ }
100
100
 
101
- ip
102
- end
101
+ ip
102
+ end
103
103
  end
104
104
 
105
105
  Facter.add(:ipaddress) do
106
- confine :kernel => %w{windows}
107
- setcode do
108
- require 'socket'
109
- IPSocket.getaddress(Socket.gethostname)
110
- end
106
+ confine :kernel => %w{windows}
107
+ setcode do
108
+ require 'socket'
109
+ IPSocket.getaddress(Socket.gethostname)
110
+ end
111
111
  end
112
112
 
113
113
  Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
114
- setcode do
114
+ setcode do
115
+ if Facter.value(:kernel) == 'windows'
116
+ require 'win32/resolv'
117
+ else
118
+ require 'resolv'
119
+ end
120
+
121
+ begin
122
+ if hostname = Facter.value(:hostname)
115
123
  if Facter.value(:kernel) == 'windows'
116
- require 'win32/resolv'
124
+ ip = Win32::Resolv.get_resolv_info.last[0]
117
125
  else
118
- require 'resolv'
126
+ ip = Resolv.getaddress(hostname)
119
127
  end
120
-
121
- begin
122
- if hostname = Facter.value(:hostname)
123
- if Facter.value(:kernel) == 'windows'
124
- ip = Win32::Resolv.get_resolv_info.last[0]
125
- else
126
- ip = Resolv.getaddress(hostname)
127
- end
128
- unless ip == "127.0.0.1"
129
- ip
130
- end
131
- else
132
- nil
133
- end
134
- rescue Resolv::ResolvError
135
- nil
136
- rescue NoMethodError # i think this is a bug in resolv.rb?
137
- nil
128
+ unless ip == "127.0.0.1"
129
+ ip
138
130
  end
131
+ else
132
+ nil
133
+ end
134
+ rescue Resolv::ResolvError
135
+ nil
136
+ rescue NoMethodError # i think this is a bug in resolv.rb?
137
+ nil
139
138
  end
139
+ end
140
140
  end
141
141
 
142
142
  Facter.add(:ipaddress, :timeout => 2) do
143
- setcode do
144
- if hostname = Facter.value(:hostname)
145
- # we need Hostname to exist for this to work
146
- host = nil
147
- if host = Facter::Util::Resolution.exec("host #{hostname}")
148
- list = host.chomp.split(/\s/)
149
- if defined? list[-1] and
150
- list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
151
- list[-1]
152
- end
153
- else
154
- nil
155
- end
156
- else
157
- nil
143
+ setcode do
144
+ if hostname = Facter.value(:hostname)
145
+ # we need Hostname to exist for this to work
146
+ host = nil
147
+ if host = Facter::Util::Resolution.exec("host #{hostname}")
148
+ list = host.chomp.split(/\s/)
149
+ if defined? list[-1] and
150
+ list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
151
+ list[-1]
158
152
  end
153
+ else
154
+ nil
155
+ end
156
+ else
157
+ nil
159
158
  end
159
+ end
160
160
  end