facter 1.3.3 → 1.3.7
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.
- data/CHANGELOG +24 -1
- data/COPYING +0 -46
- data/README +2 -1
- data/Rakefile +2 -2
- data/bin/facter +19 -4
- data/lib/facter.rb +224 -111
- data/lib/facter/memory.rb +8 -2
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,7 +1,30 @@
|
|
1
|
+
1.3.7:
|
2
|
+
A couple of small bugfixes, including fixing Facter.flush so it correctly
|
3
|
+
flushes cached values, and the mac address fact only returns one
|
4
|
+
value, not all of them.
|
5
|
+
|
6
|
+
Converted all of the fact names to symbols, rather than the somewhat
|
7
|
+
random case used previously. When the facts are converted to a hash,
|
8
|
+
they still convert the fact name to a string.
|
9
|
+
|
10
|
+
1.3.6:
|
11
|
+
A bugfix release, including fixes for #29, and #30. Also fixed
|
12
|
+
the SSH keys so they only have the key, not the type or description.
|
13
|
+
|
14
|
+
1.3.5:
|
15
|
+
A bugfix release.
|
16
|
+
|
17
|
+
1.3.4:
|
18
|
+
Added many new facts, including LSB facts.
|
19
|
+
|
20
|
+
Fixed a few small bugs, notably the error you could get when asking
|
21
|
+
for a non-existent fact.
|
22
|
+
|
1
23
|
1.3.3:
|
2
24
|
Added thread exclusivity to memory and processor facts.
|
3
25
|
|
4
|
-
Added the ability to retrieve facts by pulling them out of the shell
|
26
|
+
Added the ability to retrieve facts by pulling them out of the shell
|
27
|
+
environment.
|
5
28
|
|
6
29
|
1.3.2:
|
7
30
|
Temporarily disabled memory and processor facts since they might cause hangs.
|
data/COPYING
CHANGED
@@ -456,49 +456,3 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
456
456
|
DAMAGES.
|
457
457
|
|
458
458
|
END OF TERMS AND CONDITIONS
|
459
|
-
|
460
|
-
How to Apply These Terms to Your New Libraries
|
461
|
-
|
462
|
-
If you develop a new library, and you want it to be of the greatest
|
463
|
-
possible use to the public, we recommend making it free software that
|
464
|
-
everyone can redistribute and change. You can do so by permitting
|
465
|
-
redistribution under these terms (or, alternatively, under the terms of the
|
466
|
-
ordinary General Public License).
|
467
|
-
|
468
|
-
To apply these terms, attach the following notices to the library. It is
|
469
|
-
safest to attach them to the start of each source file to most effectively
|
470
|
-
convey the exclusion of warranty; and each file should have at least the
|
471
|
-
"copyright" line and a pointer to where the full notice is found.
|
472
|
-
|
473
|
-
<one line to give the library's name and a brief idea of what it does.>
|
474
|
-
Copyright (C) <year> <name of author>
|
475
|
-
|
476
|
-
This library is free software; you can redistribute it and/or
|
477
|
-
modify it under the terms of the GNU Lesser General Public
|
478
|
-
License as published by the Free Software Foundation; either
|
479
|
-
version 2.1 of the License, or (at your option) any later version.
|
480
|
-
|
481
|
-
This library is distributed in the hope that it will be useful,
|
482
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
483
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
484
|
-
Lesser General Public License for more details.
|
485
|
-
|
486
|
-
You should have received a copy of the GNU Lesser General Public
|
487
|
-
License along with this library; if not, write to the Free Software
|
488
|
-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
489
|
-
|
490
|
-
Also add information on how to contact you by electronic and paper mail.
|
491
|
-
|
492
|
-
You should also get your employer (if you work as a programmer) or your
|
493
|
-
school, if any, to sign a "copyright disclaimer" for the library, if
|
494
|
-
necessary. Here is a sample; alter the names:
|
495
|
-
|
496
|
-
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
497
|
-
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
498
|
-
|
499
|
-
<signature of Ty Coon>, 1 April 1990
|
500
|
-
Ty Coon, President of Vice
|
501
|
-
|
502
|
-
That's all there is to it!
|
503
|
-
|
504
|
-
|
data/README
CHANGED
@@ -6,4 +6,5 @@ processors, etc.
|
|
6
6
|
It currently cannot collect very much information, but it is architected to be
|
7
7
|
both OS and OS version specific.
|
8
8
|
|
9
|
-
See bin/facter or http://
|
9
|
+
See bin/facter or http://reductivelabs.com/project/enhost for an example of the
|
10
|
+
interface.
|
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ project = Rake::RedLabProject.new("facter") do |p|
|
|
26
26
|
|
27
27
|
p.epmhosts = %w{culain}
|
28
28
|
p.rpmhost = "fedora1"
|
29
|
-
p.sunpkghost = "sol10b"
|
29
|
+
#p.sunpkghost = "sol10b"
|
30
30
|
end
|
31
31
|
|
32
32
|
project.mkgemtask do |gem|
|
@@ -43,4 +43,4 @@ if project.has?(:epm)
|
|
43
43
|
task.rubylibs = FileList.new('lib/**/*')
|
44
44
|
end
|
45
45
|
end
|
46
|
-
# $Id: Rakefile
|
46
|
+
# $Id: Rakefile 188 2007-01-19 22:36:53Z luke $
|
data/bin/facter
CHANGED
@@ -47,7 +47,7 @@ $haveusage = true
|
|
47
47
|
|
48
48
|
begin
|
49
49
|
require 'rdoc/usage'
|
50
|
-
rescue
|
50
|
+
rescue Exception
|
51
51
|
$haveusage = false
|
52
52
|
end
|
53
53
|
|
@@ -59,14 +59,21 @@ result = GetoptLong.new(
|
|
59
59
|
[ "--version", "-v", GetoptLong::NO_ARGUMENT ],
|
60
60
|
[ "--help", "-h", GetoptLong::NO_ARGUMENT ],
|
61
61
|
[ "--debug", "-d", GetoptLong::NO_ARGUMENT ],
|
62
|
+
[ "--yaml", "-y", GetoptLong::NO_ARGUMENT ],
|
62
63
|
[ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ]
|
63
64
|
)
|
64
65
|
|
66
|
+
options = {
|
67
|
+
:yaml => false
|
68
|
+
}
|
69
|
+
|
65
70
|
result.each { |opt,arg|
|
66
71
|
case opt
|
67
72
|
when "--version"
|
68
73
|
puts "%s" % Facter.version
|
69
74
|
exit
|
75
|
+
when "--yaml"
|
76
|
+
options[:yaml] = true
|
70
77
|
when "--debug"
|
71
78
|
Facter.debugging(1)
|
72
79
|
when "--help"
|
@@ -105,7 +112,7 @@ if names.empty?
|
|
105
112
|
else
|
106
113
|
names.each { |name|
|
107
114
|
begin
|
108
|
-
facts[name] = Facter
|
115
|
+
facts[name] = Facter.value(name)
|
109
116
|
rescue => error
|
110
117
|
STDERR.puts "Could not retrieve %s: #{error}" % name
|
111
118
|
exit 10
|
@@ -113,9 +120,17 @@ else
|
|
113
120
|
}
|
114
121
|
end
|
115
122
|
|
116
|
-
|
123
|
+
if options[:yaml]
|
124
|
+
require 'yaml'
|
125
|
+
puts YAML.dump(facts)
|
126
|
+
exit(0)
|
127
|
+
end
|
128
|
+
|
129
|
+
facts.sort { |a, b| a[0].to_s <=> b[0].to_s }.each { |name,value|
|
117
130
|
if facts.length == 1
|
118
|
-
|
131
|
+
unless value.nil?
|
132
|
+
puts value
|
133
|
+
end
|
119
134
|
else
|
120
135
|
puts "%s => %s" % [name,value]
|
121
136
|
end
|
data/lib/facter.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# $Id: facter.rb 153 2006-06-28 17:38:18Z luke $
|
2
1
|
#--
|
3
2
|
# Copyright 2006 Luke Kanies <luke@madstop.com>
|
4
3
|
#
|
@@ -22,7 +21,7 @@ class Facter
|
|
22
21
|
include Comparable
|
23
22
|
include Enumerable
|
24
23
|
|
25
|
-
FACTERVERSION = '1.3.
|
24
|
+
FACTERVERSION = '1.3.7'
|
26
25
|
# = Facter
|
27
26
|
# Functions as a hash of 'facts' you might care about about your
|
28
27
|
# system, such as mac address, IP address, Video card, etc.
|
@@ -37,7 +36,14 @@ class Facter
|
|
37
36
|
#
|
38
37
|
|
39
38
|
|
40
|
-
@@facts = {
|
39
|
+
@@facts = Hash.new { |hash, key|
|
40
|
+
key = key.to_s.downcase.intern
|
41
|
+
if hash.include?(key)
|
42
|
+
hash[key]
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
}
|
41
47
|
GREEN = "[0;32m"
|
42
48
|
RESET = "[0m"
|
43
49
|
@@debug = 0
|
@@ -47,12 +53,12 @@ class Facter
|
|
47
53
|
# module methods
|
48
54
|
|
49
55
|
# Return the version of the library.
|
50
|
-
def
|
56
|
+
def self.version
|
51
57
|
return FACTERVERSION
|
52
58
|
end
|
53
59
|
|
54
60
|
# Add some debugging
|
55
|
-
def
|
61
|
+
def self.debug(string)
|
56
62
|
if string.nil?
|
57
63
|
return
|
58
64
|
end
|
@@ -63,22 +69,17 @@ class Facter
|
|
63
69
|
|
64
70
|
# Return a fact object by name. If you use this, you still have to call
|
65
71
|
# 'value' on it to retrieve the actual value.
|
66
|
-
def
|
67
|
-
name = name.to_s.downcase
|
72
|
+
def self.[](name)
|
68
73
|
@@facts[name]
|
69
74
|
end
|
70
75
|
|
71
76
|
# Add a resolution mechanism for a named fact. This does not distinguish
|
72
77
|
# between adding a new fact and adding a new way to resolve a fact.
|
73
|
-
def
|
78
|
+
def self.add(name, &block)
|
74
79
|
fact = nil
|
75
|
-
dcname = name.to_s.downcase
|
76
80
|
|
77
|
-
|
78
|
-
fact =
|
79
|
-
else
|
80
|
-
Facter.new(dcname)
|
81
|
-
fact = @@facts[dcname]
|
81
|
+
unless fact = @@facts[name]
|
82
|
+
fact = Facter.new(name)
|
82
83
|
end
|
83
84
|
|
84
85
|
unless block
|
@@ -98,7 +99,7 @@ class Facter
|
|
98
99
|
if fact.suitable?
|
99
100
|
value = fact.value
|
100
101
|
unless value.nil?
|
101
|
-
yield name, fact.value
|
102
|
+
yield name.to_s, fact.value
|
102
103
|
end
|
103
104
|
end
|
104
105
|
}
|
@@ -113,7 +114,7 @@ class Facter
|
|
113
114
|
name = name.to_s.sub(/\?$/,'')
|
114
115
|
end
|
115
116
|
|
116
|
-
if fact =
|
117
|
+
if fact = @@facts[name]
|
117
118
|
if question
|
118
119
|
value = fact.value.downcase
|
119
120
|
args.each do |arg|
|
@@ -135,14 +136,13 @@ class Facter
|
|
135
136
|
end
|
136
137
|
|
137
138
|
# Clear all facts. Mostly used for testing.
|
138
|
-
def
|
139
|
-
Facter.reset
|
139
|
+
def self.clear
|
140
140
|
Facter.flush
|
141
|
-
|
141
|
+
Facter.reset
|
142
142
|
end
|
143
143
|
|
144
144
|
# Set debugging on or off.
|
145
|
-
def
|
145
|
+
def self.debugging(bit)
|
146
146
|
if bit
|
147
147
|
case bit
|
148
148
|
when TrueClass: @@debug = 1
|
@@ -168,38 +168,37 @@ class Facter
|
|
168
168
|
end
|
169
169
|
|
170
170
|
# Flush all cached values.
|
171
|
-
def
|
172
|
-
@@facts.each { |fact| fact.flush }
|
171
|
+
def self.flush
|
172
|
+
@@facts.each { |name, fact| fact.flush }
|
173
173
|
end
|
174
174
|
|
175
175
|
# Return a list of all of the facts.
|
176
|
-
def
|
176
|
+
def self.list
|
177
177
|
return @@facts.keys
|
178
178
|
end
|
179
179
|
|
180
180
|
# Remove them all.
|
181
|
-
def
|
182
|
-
@@facts.
|
183
|
-
@@facts.delete(name)
|
184
|
-
}
|
181
|
+
def self.reset
|
182
|
+
@@facts.clear
|
185
183
|
end
|
186
184
|
|
187
185
|
# Return a hash of all of our facts.
|
188
|
-
def
|
186
|
+
def self.to_hash(*tags)
|
189
187
|
@@facts.inject({}) do |h, ary|
|
190
188
|
if ary[1].suitable? and (tags.empty? or ary[1].tagged?(*tags))
|
191
189
|
value = ary[1].value
|
192
190
|
if value
|
193
|
-
|
191
|
+
# For backwards compatibility, convert the fact name to a string.
|
192
|
+
h[ary[0].to_s] = value
|
194
193
|
end
|
195
194
|
end
|
196
195
|
h
|
197
196
|
end
|
198
197
|
end
|
199
198
|
|
200
|
-
def
|
201
|
-
if @@facts
|
202
|
-
|
199
|
+
def self.value(name)
|
200
|
+
if fact = @@facts[name]
|
201
|
+
fact.value
|
203
202
|
else
|
204
203
|
nil
|
205
204
|
end
|
@@ -217,9 +216,9 @@ class Facter
|
|
217
216
|
|
218
217
|
# Create a new fact, with no resolution mechanisms.
|
219
218
|
def initialize(name)
|
220
|
-
@name = name.downcase
|
219
|
+
@name = name.to_s.downcase.intern
|
221
220
|
if @@facts.include?(@name)
|
222
|
-
raise ArgumentError, "A fact named %s already exists" % name
|
221
|
+
raise ArgumentError, "A fact named %s already exists" % @name
|
223
222
|
else
|
224
223
|
@@facts[@name] = self
|
225
224
|
end
|
@@ -385,26 +384,37 @@ class Facter
|
|
385
384
|
class Resolution
|
386
385
|
attr_accessor :interpreter, :code, :name, :fact
|
387
386
|
|
387
|
+
def Resolution.have_which
|
388
|
+
if @have_which.nil?
|
389
|
+
%x{which which 2>/dev/null}
|
390
|
+
@have_which = ($? == 0)
|
391
|
+
end
|
392
|
+
@have_which
|
393
|
+
end
|
394
|
+
|
388
395
|
# Execute a chunk of code.
|
389
396
|
def Resolution.exec(code, interpreter = "/bin/sh")
|
390
397
|
if interpreter == "/bin/sh"
|
391
398
|
binary = code.split(/\s+/).shift
|
392
399
|
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
400
|
+
if have_which
|
401
|
+
path = nil
|
402
|
+
if binary !~ /^\//
|
403
|
+
path = %x{which #{binary} 2>/dev/null}.chomp
|
404
|
+
if path == ""
|
405
|
+
# we don't have the binary necessary
|
406
|
+
return nil
|
407
|
+
end
|
408
|
+
else
|
409
|
+
path = binary
|
410
|
+
end
|
411
|
+
|
412
|
+
unless FileTest.exists?(path)
|
413
|
+
# our binary does not exist
|
398
414
|
return nil
|
399
415
|
end
|
400
|
-
else
|
401
|
-
path = binary
|
402
416
|
end
|
403
417
|
|
404
|
-
unless FileTest.exists?(path)
|
405
|
-
# our binary does not exist
|
406
|
-
return nil
|
407
|
-
end
|
408
418
|
out = nil
|
409
419
|
begin
|
410
420
|
out = %x{#{code}}.chomp
|
@@ -571,16 +581,16 @@ class Facter
|
|
571
581
|
end
|
572
582
|
|
573
583
|
# Load all of the default facts
|
574
|
-
def
|
575
|
-
Facter.add(
|
584
|
+
def self.loadfacts
|
585
|
+
Facter.add(:facterversion) do
|
576
586
|
setcode { FACTERVERSION.to_s }
|
577
587
|
end
|
578
588
|
|
579
|
-
Facter.add(
|
589
|
+
Facter.add(:rubyversion) do
|
580
590
|
setcode { RUBY_VERSION.to_s }
|
581
591
|
end
|
582
592
|
|
583
|
-
Facter.add(
|
593
|
+
Facter.add(:puppetversion) do
|
584
594
|
setcode {
|
585
595
|
begin
|
586
596
|
require 'puppet'
|
@@ -600,31 +610,47 @@ class Facter
|
|
600
610
|
end
|
601
611
|
end
|
602
612
|
|
603
|
-
Facter.add(
|
613
|
+
Facter.add(:kernel) do
|
604
614
|
setcode 'uname -s'
|
605
615
|
end
|
606
616
|
|
607
|
-
Facter.add(
|
617
|
+
Facter.add(:kernelrelease) do
|
608
618
|
setcode 'uname -r'
|
609
619
|
end
|
610
620
|
|
611
|
-
|
621
|
+
{ "LSBRelease" => "^LSB Version:\t(.*)$",
|
622
|
+
"LSBDistId" => "^Distributor ID:\t(.*)$",
|
623
|
+
"LSBDistRelease" => "^Release:\t(.*)$",
|
624
|
+
"LSBDistDescription" => "^Description:\t(.*)$",
|
625
|
+
"LSBDistCodeName" => "^Codename:\t(.*)$"
|
626
|
+
}.each do |fact, pattern|
|
627
|
+
Facter.add(fact) do
|
628
|
+
setcode do
|
629
|
+
output = Resolution.exec('lsb_release -a 2>/dev/null')
|
630
|
+
if output =~ /#{pattern}/
|
631
|
+
$1
|
632
|
+
else
|
633
|
+
nil
|
634
|
+
end
|
635
|
+
end
|
636
|
+
end
|
637
|
+
end
|
638
|
+
|
639
|
+
Facter.add(:operatingsystem) do
|
612
640
|
# Default to just returning the kernel as the operating system
|
613
|
-
setcode do Facter[
|
641
|
+
setcode do Facter[:kernel].value end
|
614
642
|
end
|
615
643
|
|
616
|
-
Facter.add(
|
617
|
-
setcode do Facter[
|
644
|
+
Facter.add(:operatingsystemrelease) do
|
645
|
+
setcode do Facter[:kernelrelease].value end
|
618
646
|
end
|
619
647
|
|
620
|
-
Facter.add(
|
621
|
-
#obj.os = "Linux"
|
648
|
+
Facter.add(:operatingsystem) do
|
622
649
|
confine :kernel => :sunos
|
623
650
|
setcode do "Solaris" end
|
624
651
|
end
|
625
652
|
|
626
|
-
Facter.add(
|
627
|
-
#obj.os = "Linux"
|
653
|
+
Facter.add(:operatingsystem) do
|
628
654
|
confine :kernel => :linux
|
629
655
|
setcode do
|
630
656
|
if FileTest.exists?("/etc/debian_version")
|
@@ -646,16 +672,18 @@ class Facter
|
|
646
672
|
end
|
647
673
|
end
|
648
674
|
|
649
|
-
Facter.add(
|
675
|
+
Facter.add(:hardwaremodel) do
|
650
676
|
setcode 'uname -m'
|
651
677
|
end
|
652
678
|
|
653
|
-
Facter.add(
|
654
|
-
confine :
|
679
|
+
Facter.add(:architecture) do
|
680
|
+
confine :kernel => :linux
|
655
681
|
setcode do
|
656
682
|
model = Facter.hardwaremodel
|
657
683
|
case model
|
658
|
-
|
684
|
+
# most linuxen use "x86_64"
|
685
|
+
when 'x86_64':
|
686
|
+
Facter.operatingsystem == "Debian" ? "amd64" : model;
|
659
687
|
when /(i[3456]86|pentium)/: "i386"
|
660
688
|
else
|
661
689
|
model
|
@@ -663,13 +691,15 @@ class Facter
|
|
663
691
|
end
|
664
692
|
end
|
665
693
|
|
666
|
-
Facter.add(
|
694
|
+
Facter.add(:Cfkey) do
|
667
695
|
setcode do
|
668
696
|
value = nil
|
669
697
|
["/usr/local/etc/cfkey.pub",
|
670
698
|
"/etc/cfkey.pub",
|
671
699
|
"/var/cfng/keys/localhost.pub",
|
672
|
-
"/var/cfengine/ppkeys/localhost.pub"
|
700
|
+
"/var/cfengine/ppkeys/localhost.pub",
|
701
|
+
"/var/lib/cfengine/ppkeys/localhost.pub",
|
702
|
+
"/var/lib/cfengine2/ppkeys/localhost.pub"
|
673
703
|
].each { |file|
|
674
704
|
if FileTest.file?(file)
|
675
705
|
File.open(file) { |openfile|
|
@@ -689,8 +719,12 @@ class Facter
|
|
689
719
|
end
|
690
720
|
end
|
691
721
|
|
692
|
-
Facter.add(
|
722
|
+
Facter.add(:domain) do
|
693
723
|
setcode do
|
724
|
+
# First force the hostname to be checked
|
725
|
+
Facter.hostname
|
726
|
+
|
727
|
+
# Now check to see if it set the domain
|
694
728
|
if defined? $domain and ! $domain.nil?
|
695
729
|
$domain
|
696
730
|
else
|
@@ -699,7 +733,7 @@ class Facter
|
|
699
733
|
end
|
700
734
|
end
|
701
735
|
# Look for the DNS domain name command first.
|
702
|
-
Facter.add(
|
736
|
+
Facter.add(:domain) do
|
703
737
|
setcode do
|
704
738
|
domain = Resolution.exec('dnsdomainname') or nil
|
705
739
|
# make sure it's a real domain
|
@@ -710,7 +744,7 @@ class Facter
|
|
710
744
|
end
|
711
745
|
end
|
712
746
|
end
|
713
|
-
Facter.add(
|
747
|
+
Facter.add(:domain) do
|
714
748
|
setcode do
|
715
749
|
domain = Resolution.exec('domainname') or nil
|
716
750
|
# make sure it's a real domain
|
@@ -721,7 +755,7 @@ class Facter
|
|
721
755
|
end
|
722
756
|
end
|
723
757
|
end
|
724
|
-
Facter.add(
|
758
|
+
Facter.add(:domain) do
|
725
759
|
setcode do
|
726
760
|
value = nil
|
727
761
|
if FileTest.exists?("/etc/resolv.conf")
|
@@ -749,7 +783,7 @@ class Facter
|
|
749
783
|
end
|
750
784
|
end
|
751
785
|
end
|
752
|
-
Facter.add(
|
786
|
+
Facter.add(:hostname) do
|
753
787
|
setldapname "cn"
|
754
788
|
setcode do
|
755
789
|
hostname = nil
|
@@ -769,13 +803,25 @@ class Facter
|
|
769
803
|
end
|
770
804
|
end
|
771
805
|
|
772
|
-
Facter.add(
|
806
|
+
Facter.add(:fqdn) do
|
807
|
+
setcode do
|
808
|
+
host = Facter.value(:hostname)
|
809
|
+
domain = Facter.value(:domain)
|
810
|
+
if host and domain
|
811
|
+
[host, domain].join(".")
|
812
|
+
else
|
813
|
+
nil
|
814
|
+
end
|
815
|
+
end
|
816
|
+
end
|
817
|
+
|
818
|
+
Facter.add(:ipaddress) do
|
773
819
|
setldapname "iphostnumber"
|
774
820
|
setcode do
|
775
821
|
require 'resolv'
|
776
822
|
|
777
823
|
begin
|
778
|
-
if hostname = Facter
|
824
|
+
if hostname = Facter.hostname
|
779
825
|
ip = Resolv.getaddress(hostname)
|
780
826
|
unless ip == "127.0.0.1"
|
781
827
|
ip
|
@@ -790,12 +836,13 @@ class Facter
|
|
790
836
|
end
|
791
837
|
end
|
792
838
|
end
|
793
|
-
Facter.add(
|
839
|
+
Facter.add(:ipaddress) do
|
794
840
|
setcode do
|
795
|
-
if hostname = Facter
|
841
|
+
if hostname = Facter.hostname
|
796
842
|
# we need Hostname to exist for this to work
|
797
|
-
|
798
|
-
|
843
|
+
host = nil
|
844
|
+
if host = Resolution.exec("host #{hostname}")
|
845
|
+
host = host.chomp.split(/\s/)
|
799
846
|
if defined? list[-1] and
|
800
847
|
list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
|
801
848
|
list[-1]
|
@@ -818,7 +865,7 @@ class Facter
|
|
818
865
|
filepath = File.join(dir,file)
|
819
866
|
if FileTest.file?(filepath)
|
820
867
|
begin
|
821
|
-
value = File.open(filepath).read.chomp
|
868
|
+
value = File.open(filepath).read.chomp.split(/\s+/)[1]
|
822
869
|
rescue
|
823
870
|
value = nil
|
824
871
|
end
|
@@ -829,30 +876,29 @@ class Facter
|
|
829
876
|
} # end of hash each
|
830
877
|
} # end of dir each
|
831
878
|
|
832
|
-
Facter.add(
|
879
|
+
Facter.add(:uniqueid) do
|
833
880
|
setcode 'hostid', '/bin/sh'
|
834
|
-
confine :operatingsystem =>
|
881
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
|
835
882
|
end
|
836
883
|
|
837
|
-
Facter.add(
|
884
|
+
Facter.add(:hardwareisa) do
|
838
885
|
setcode 'uname -p', '/bin/sh'
|
839
|
-
confine :operatingsystem =>
|
886
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
|
840
887
|
end
|
841
888
|
|
842
|
-
Facter.add(
|
843
|
-
confine :operatingsystem =>
|
889
|
+
Facter.add(:macaddress) do
|
890
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
|
844
891
|
setcode do
|
845
|
-
ether =
|
892
|
+
ether = []
|
846
893
|
output = %x{/sbin/ifconfig -a}
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
ether
|
894
|
+
output.each {|s|
|
895
|
+
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})/
|
896
|
+
}
|
897
|
+
ether[0]
|
852
898
|
end
|
853
899
|
end
|
854
900
|
|
855
|
-
Facter.add(
|
901
|
+
Facter.add(:macaddress) do
|
856
902
|
confine :kernel => :darwin
|
857
903
|
setcode do
|
858
904
|
ether = nil
|
@@ -868,12 +914,62 @@ class Facter
|
|
868
914
|
ether
|
869
915
|
end
|
870
916
|
end
|
871
|
-
|
872
|
-
|
917
|
+
|
918
|
+
Facter.add(:ipaddress) do
|
919
|
+
confine :kernel => :linux
|
873
920
|
setcode do
|
874
921
|
ip = nil
|
875
922
|
output = %x{/sbin/ifconfig}
|
876
923
|
|
924
|
+
output.split(/^\S/).each { |str|
|
925
|
+
if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
926
|
+
tmp = $1
|
927
|
+
unless tmp =~ /127\./
|
928
|
+
ip = tmp
|
929
|
+
break
|
930
|
+
end
|
931
|
+
end
|
932
|
+
}
|
933
|
+
|
934
|
+
ip
|
935
|
+
end
|
936
|
+
end
|
937
|
+
Facter.add(:ipaddress) do
|
938
|
+
confine :kernel => %w{FreeBSD NetBSD OpenBSD solaris}
|
939
|
+
setcode do
|
940
|
+
ip = nil
|
941
|
+
output = %x{/sbin/ifconfig}
|
942
|
+
|
943
|
+
output.split(/^\S/).each { |str|
|
944
|
+
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
945
|
+
tmp = $1
|
946
|
+
unless tmp =~ /127\./
|
947
|
+
ip = tmp
|
948
|
+
break
|
949
|
+
end
|
950
|
+
end
|
951
|
+
}
|
952
|
+
|
953
|
+
ip
|
954
|
+
end
|
955
|
+
end
|
956
|
+
Facter.add(:ipaddress) do
|
957
|
+
confine :kernel => %w{darwin}
|
958
|
+
setcode do
|
959
|
+
ip = nil
|
960
|
+
iface = ""
|
961
|
+
output = %x{/usr/sbin/netstat -rn}
|
962
|
+
if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/
|
963
|
+
iface = $1
|
964
|
+
else
|
965
|
+
warn "Could not find a default route. Using first non-loopback interface"
|
966
|
+
end
|
967
|
+
if(iface != "")
|
968
|
+
output = %x{/sbin/ifconfig #{iface}}
|
969
|
+
else
|
970
|
+
output = %x{/sbin/ifconfig}
|
971
|
+
end
|
972
|
+
|
877
973
|
output.split(/^\S/).each { |str|
|
878
974
|
if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
|
879
975
|
tmp = $1
|
@@ -887,19 +983,19 @@ class Facter
|
|
887
983
|
ip
|
888
984
|
end
|
889
985
|
end
|
890
|
-
Facter.add(
|
986
|
+
Facter.add(:hostname) do
|
891
987
|
confine :kernel => :darwin, :kernelrelease => "R7"
|
892
988
|
setcode do
|
893
989
|
%x{/usr/sbin/scutil --get LocalHostName}
|
894
990
|
end
|
895
991
|
end
|
896
|
-
Facter.add(
|
992
|
+
Facter.add(:iphostnumber) do
|
897
993
|
confine :kernel => :darwin, :kernelrelease => "R6"
|
898
994
|
setcode do
|
899
995
|
%x{/usr/sbin/scutil --get LocalHostName}
|
900
996
|
end
|
901
997
|
end
|
902
|
-
Facter.add(
|
998
|
+
Facter.add(:iphostnumber) do
|
903
999
|
confine :kernel => :darwin, :kernelrelease => "R6"
|
904
1000
|
setcode do
|
905
1001
|
ether = nil
|
@@ -912,40 +1008,55 @@ class Facter
|
|
912
1008
|
end
|
913
1009
|
end
|
914
1010
|
|
915
|
-
Facter.add(
|
1011
|
+
Facter.add(:ps) do
|
916
1012
|
setcode do 'ps -ef' end
|
917
1013
|
end
|
918
1014
|
|
919
|
-
Facter.add(
|
1015
|
+
Facter.add(:ps) do
|
920
1016
|
confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin}
|
921
1017
|
setcode do 'ps -auxwww' end
|
922
1018
|
end
|
923
1019
|
|
924
|
-
Facter.add(
|
925
|
-
confine :
|
1020
|
+
Facter.add(:id) do
|
1021
|
+
#confine :kernel => %w{Solaris Linux}
|
1022
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo}
|
926
1023
|
setcode "whoami"
|
927
1024
|
end
|
928
1025
|
|
929
1026
|
locals = []
|
930
1027
|
|
931
|
-
# Now
|
1028
|
+
# Now find all our loadable facts
|
1029
|
+
factdirs = [] # All the places to check for facts
|
1030
|
+
|
1031
|
+
# See if we can find any other facts in the regular Ruby lib
|
1032
|
+
# paths
|
932
1033
|
$:.each do |dir|
|
933
1034
|
fdir = File.join(dir, "facter")
|
934
1035
|
if FileTest.exists?(fdir) and FileTest.directory?(fdir)
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
1036
|
+
factdirs.push(fdir)
|
1037
|
+
end
|
1038
|
+
end
|
1039
|
+
# Also check anything in 'FACTERLIB'
|
1040
|
+
if ENV['FACTERLIB']
|
1041
|
+
ENV['FACTERLIB'].split(":").each do |fdir|
|
1042
|
+
factdirs.push(fdir)
|
1043
|
+
end
|
1044
|
+
end
|
1045
|
+
factdirs.each do |fdir|
|
1046
|
+
Dir.glob("#{fdir}/*.rb").each do |file|
|
1047
|
+
# Load here, rather than require, because otherwise
|
1048
|
+
# the facts won't get reloaded if someone calls
|
1049
|
+
# "loadfacts". Really only important in testing, but,
|
1050
|
+
# well, it's important in testing.
|
1051
|
+
begin
|
1052
|
+
load file
|
1053
|
+
rescue => detail
|
1054
|
+
warn "Could not load %s: %s" %
|
1055
|
+
[file, detail]
|
946
1056
|
end
|
947
1057
|
end
|
948
1058
|
end
|
1059
|
+
|
949
1060
|
|
950
1061
|
# Now try to get facts from the environment
|
951
1062
|
ENV.each do |name, value|
|
@@ -959,3 +1070,5 @@ class Facter
|
|
959
1070
|
|
960
1071
|
Facter.loadfacts
|
961
1072
|
end
|
1073
|
+
|
1074
|
+
# $Id: facter.rb 202 2007-03-21 16:44:44Z luke $
|
data/lib/facter/memory.rb
CHANGED
@@ -22,11 +22,17 @@ module Facter::Memory
|
|
22
22
|
def self.meminfo_number(tag)
|
23
23
|
memsize = ""
|
24
24
|
Thread::exclusive do
|
25
|
+
size, scale = [0, ""]
|
25
26
|
File.readlines("/proc/meminfo").each do |l|
|
26
|
-
if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/
|
27
|
-
|
27
|
+
size, scale = [$1.to_f, $2] if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/
|
28
|
+
# MemoryFree == memfree + cached + buffers
|
29
|
+
# (assume scales are all the same as memfree)
|
30
|
+
if tag == "MemFree" &&
|
31
|
+
l =~ /^(?:Buffers|Cached):\s+(\d+)\s+(?:\S+)/
|
32
|
+
size += $1.to_f
|
28
33
|
end
|
29
34
|
end
|
35
|
+
memsize = scale_number(size, scale)
|
30
36
|
end
|
31
37
|
|
32
38
|
memsize
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: facter
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.3.
|
7
|
-
date:
|
6
|
+
version: 1.3.7
|
7
|
+
date: 2007-03-21 00:00:00 -05:00
|
8
8
|
summary: Facter collects Operating system facts.
|
9
9
|
require_paths:
|
10
10
|
- lib
|