facter 1.6.18 → 1.7.0.rc1
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/Gemfile +23 -8
- data/bin/facter +4 -1
- data/ext/build_defaults.yaml +1 -1
- data/ext/debian/changelog.erb +4 -22
- data/ext/debian/control +2 -2
- data/ext/project_data.yaml +1 -1
- data/ext/redhat/facter.spec.erb +10 -9
- data/install.rb +27 -53
- data/lib/facter.rb +23 -5
- data/lib/facter/application.rb +21 -0
- data/lib/facter/blockdevices.rb +105 -0
- data/lib/facter/domain.rb +19 -7
- data/lib/facter/filesystems.rb +38 -0
- data/lib/facter/hardwaremodel.rb +3 -2
- data/lib/facter/ipaddress6.rb +1 -2
- data/lib/facter/kernelrelease.rb +10 -2
- data/lib/facter/ldom.rb +47 -0
- data/lib/facter/macaddress.rb +1 -1
- data/lib/facter/manufacturer.rb +7 -1
- data/lib/facter/memory.rb +58 -160
- data/lib/facter/operatingsystem.rb +17 -2
- data/lib/facter/operatingsystemmajrelease.rb +33 -0
- data/lib/facter/operatingsystemrelease.rb +88 -37
- data/lib/facter/osfamily.rb +6 -2
- data/lib/facter/processor.rb +2 -2
- data/lib/facter/ps.rb +5 -0
- data/lib/facter/ssh.rb +50 -12
- data/lib/facter/util/cfpropertylist.rb +6 -0
- data/lib/facter/util/cfpropertylist/LICENSE +19 -0
- data/lib/facter/util/cfpropertylist/README +44 -0
- data/lib/facter/util/cfpropertylist/Rakefile +44 -0
- data/lib/facter/util/cfpropertylist/THANKS +7 -0
- data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +6 -0
- data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +562 -0
- data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +26 -0
- data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +402 -0
- data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +244 -0
- data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +135 -0
- data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +140 -0
- data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +136 -0
- data/lib/facter/util/collection.rb +36 -14
- data/lib/facter/util/composite_loader.rb +12 -0
- data/lib/facter/util/config.rb +36 -0
- data/lib/facter/util/confine.rb +1 -6
- data/lib/facter/util/directory_loader.rb +83 -0
- data/lib/facter/util/fact.rb +49 -42
- data/lib/facter/util/file_read.rb +32 -0
- data/lib/facter/util/ip.rb +2 -9
- data/lib/facter/util/loader.rb +16 -2
- data/lib/facter/util/macosx.rb +15 -2
- data/lib/facter/util/memory.rb +154 -27
- data/lib/facter/util/nothing_loader.rb +15 -0
- data/lib/facter/util/parser.rb +141 -0
- data/lib/facter/util/processor.rb +27 -35
- data/lib/facter/util/resolution.rb +97 -26
- data/lib/facter/util/solaris_zones.rb +153 -0
- data/lib/facter/util/virtual.rb +32 -3
- data/lib/facter/version.rb +72 -2
- data/lib/facter/virtual.rb +56 -3
- data/lib/facter/zfs_version.rb +10 -0
- data/lib/facter/zonename.rb +6 -0
- data/lib/facter/zones.rb +17 -0
- data/lib/facter/zpool_version.rb +10 -0
- data/spec/fixtures/ifconfig/ifconfig_net_tools_1.60.txt +19 -0
- data/spec/fixtures/ifconfig/ifconfig_ubuntu_1204.txt +16 -0
- data/spec/fixtures/ldom/ldom_v1 +6 -0
- data/spec/fixtures/unit/filesystems/linux +28 -0
- data/spec/fixtures/unit/util/manufacturer/intel_linux_dmidecode +549 -0
- data/spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt +0 -0
- data/spec/fixtures/unit/zfs_version/freebsd_8.2 +14 -0
- data/spec/fixtures/unit/zfs_version/freebsd_9.0 +13 -0
- data/spec/fixtures/unit/zfs_version/linux-fuse_0.6.9 +14 -0
- data/spec/fixtures/unit/zfs_version/solaris_10 +10 -0
- data/spec/fixtures/unit/zfs_version/solaris_11 +12 -0
- data/spec/fixtures/unit/zpool_version/freebsd_8.2 +26 -0
- data/spec/fixtures/unit/zpool_version/freebsd_9.0 +38 -0
- data/spec/fixtures/unit/zpool_version/linux-fuse_0.6.9 +35 -0
- data/spec/fixtures/unit/zpool_version/solaris_10 +31 -0
- data/spec/fixtures/unit/zpool_version/solaris_11 +43 -0
- data/spec/integration/facter_spec.rb +12 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/unit/architecture_spec.rb +1 -1
- data/spec/unit/blockdevices_spec.rb +109 -0
- data/spec/unit/domain_spec.rb +189 -81
- data/spec/unit/ec2_spec.rb +15 -8
- data/spec/unit/filesystems_spec.rb +50 -0
- data/spec/unit/hardwaremodel_spec.rb +8 -1
- data/spec/unit/id_spec.rb +6 -5
- data/spec/unit/ipaddress6_spec.rb +14 -2
- data/spec/unit/ipaddress_spec.rb +1 -1
- data/spec/unit/kernel_spec.rb +24 -0
- data/spec/unit/kernelmajversion_spec.rb +17 -0
- data/spec/unit/kernelrelease_spec.rb +53 -0
- data/spec/unit/kernelversion_spec.rb +32 -0
- data/spec/unit/ldom_spec.rb +74 -0
- data/spec/unit/macaddress_spec.rb +3 -1
- data/spec/unit/manufacturer_spec.rb +115 -0
- data/spec/unit/memory_spec.rb +442 -75
- data/spec/unit/operatingsystem_spec.rb +16 -2
- data/spec/unit/operatingsystemmajrelease_spec.rb +16 -0
- data/spec/unit/operatingsystemrelease_spec.rb +110 -1
- data/spec/unit/processor_spec.rb +22 -7
- data/spec/unit/ps_spec.rb +42 -0
- data/spec/unit/ssh_spec.rb +76 -0
- data/spec/unit/util/collection_spec.rb +94 -118
- data/spec/unit/util/config_spec.rb +36 -5
- data/spec/unit/util/confine_spec.rb +31 -43
- data/spec/unit/util/directory_loader_spec.rb +87 -0
- data/spec/unit/util/fact_spec.rb +37 -25
- data/spec/unit/util/file_read_spec.rb +29 -0
- data/spec/unit/util/ip_spec.rb +4 -2
- data/spec/unit/util/loader_spec.rb +102 -45
- data/spec/unit/util/macosx_spec.rb +40 -9
- data/spec/unit/util/manufacturer_spec.rb +12 -1
- data/spec/unit/util/parser_spec.rb +135 -0
- data/spec/unit/util/resolution_spec.rb +136 -4
- data/spec/unit/util/solaris_zones_spec.rb +127 -0
- data/spec/unit/util/virtual_spec.rb +54 -0
- data/spec/unit/version_spec.rb +42 -0
- data/spec/unit/virtual_spec.rb +102 -27
- data/spec/unit/zfs_version_spec.rb +76 -0
- data/spec/unit/zonename_spec.rb +14 -0
- data/spec/unit/zones_spec.rb +55 -0
- data/spec/unit/zpool_version_spec.rb +76 -0
- metadata +113 -11
- data/lib/facter/arp.rb +0 -28
data/lib/facter/domain.rb
CHANGED
@@ -23,14 +23,24 @@ Facter.add(:domain) do
|
|
23
23
|
# Get the domain from various sources; the order of these
|
24
24
|
# steps is important
|
25
25
|
|
26
|
-
|
26
|
+
# In some OS 'hostname -f' will change the hostname to '-f'
|
27
|
+
# We know that Solaris and HP-UX exhibit this behavior
|
28
|
+
# On good OS, 'hostname -f' will return the FQDN which is preferable
|
29
|
+
# Due to dangerous behavior of 'hostname -f' on old OS, we will explicitly opt-in
|
30
|
+
# 'hostname -f' --hkenney May 9, 2012
|
31
|
+
hostname_command = 'hostname'
|
32
|
+
can_do_hostname_f = Regexp.union /Linux/i, /FreeBSD/i, /Darwin/i
|
33
|
+
hostname_command = 'hostname -f' if Facter.value(:kernel) =~ can_do_hostname_f
|
34
|
+
|
35
|
+
|
36
|
+
if name = Facter::Util::Resolution.exec(hostname_command) \
|
27
37
|
and name =~ /.*?\.(.+$)/
|
28
38
|
|
29
|
-
$1
|
39
|
+
return_value = $1
|
30
40
|
elsif domain = Facter::Util::Resolution.exec('dnsdomainname') \
|
31
|
-
and domain =~
|
41
|
+
and domain =~ /.+/
|
32
42
|
|
33
|
-
domain
|
43
|
+
return_value = domain
|
34
44
|
elsif FileTest.exists?("/etc/resolv.conf")
|
35
45
|
domain = nil
|
36
46
|
search = nil
|
@@ -43,9 +53,11 @@ Facter.add(:domain) do
|
|
43
53
|
end
|
44
54
|
}
|
45
55
|
}
|
46
|
-
|
47
|
-
|
56
|
+
return_value ||= domain
|
57
|
+
return_value ||= search
|
48
58
|
end
|
59
|
+
return_value = '' if return_value.nil?
|
60
|
+
return_value.gsub(/\.$/, '')
|
49
61
|
end
|
50
62
|
end
|
51
63
|
|
@@ -63,6 +75,6 @@ Facter.add(:domain) do
|
|
63
75
|
break
|
64
76
|
}
|
65
77
|
end
|
66
|
-
domain
|
78
|
+
domain.gsub(/\.$/, '')
|
67
79
|
end
|
68
80
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# filesystems.rb
|
3
|
+
#
|
4
|
+
# This fact provides an alphabetic list of usable file systems that can
|
5
|
+
# be used for block devices like hard drives, media cards and so on ...
|
6
|
+
#
|
7
|
+
Facter.add('filesystems') do
|
8
|
+
confine :kernel => :linux
|
9
|
+
setcode do
|
10
|
+
# fuseblk can't be created and arguably isn't usable here. If you feel this
|
11
|
+
# doesn't match your use-case please raise a bug.
|
12
|
+
exclude = %w(fuseblk)
|
13
|
+
|
14
|
+
# Make regular expression form our patterns ...
|
15
|
+
exclude = Regexp.union(*exclude.collect { |i| Regexp.new(i) })
|
16
|
+
|
17
|
+
# We utilise rely on "cat" for reading values from entries under "/proc".
|
18
|
+
# This is due to some problems with IO#read in Ruby and reading content of
|
19
|
+
# the "proc" file system that was reported more than once in the past ...
|
20
|
+
file_systems = []
|
21
|
+
Facter::Util::Resolution.exec('cat /proc/filesystems 2> /dev/null').each_line do |line|
|
22
|
+
# Remove bloat ...
|
23
|
+
line.strip!
|
24
|
+
|
25
|
+
# Line of interest should not start with "nodev" ...
|
26
|
+
next if line.empty? or line.match(/^nodev/)
|
27
|
+
|
28
|
+
# We have something, so let us apply our device type filter ...
|
29
|
+
next if line.match(exclude)
|
30
|
+
|
31
|
+
file_systems << line
|
32
|
+
end
|
33
|
+
file_systems.sort.join(',')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# vim: set ts=2 sw=2 et :
|
38
|
+
# encoding: utf-8
|
data/lib/facter/hardwaremodel.rb
CHANGED
@@ -36,12 +36,13 @@ Facter.add(:hardwaremodel) do
|
|
36
36
|
# windows 8 release. --jeffweiss 23 May 2012
|
37
37
|
require 'facter/util/wmi'
|
38
38
|
model = ""
|
39
|
-
Facter::Util::WMI.execquery("select Architecture, Level from Win32_Processor").each do |cpu|
|
39
|
+
Facter::Util::WMI.execquery("select Architecture, Level, AddressWidth from Win32_Processor").each do |cpu|
|
40
40
|
model =
|
41
41
|
case cpu.Architecture
|
42
42
|
when 11 then 'neutral' # PROCESSOR_ARCHITECTURE_NEUTRAL
|
43
43
|
when 10 then 'i686' # PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
|
44
|
-
when 9 then
|
44
|
+
when 9 then # PROCESSOR_ARCHITECTURE_AMD64
|
45
|
+
cpu.AddressWidth == 32 ? "i#{cpu.Level}86" : 'x64' # 32 bit OS on 64 bit CPU
|
45
46
|
when 8 then 'msil' # PROCESSOR_ARCHITECTURE_MSIL
|
46
47
|
when 7 then 'alpha64' # PROCESSOR_ARCHITECTURE_ALPHA64
|
47
48
|
when 6 then 'ia64' # PROCESSOR_ARCHITECTURE_IA64
|
data/lib/facter/ipaddress6.rb
CHANGED
data/lib/facter/kernelrelease.rb
CHANGED
@@ -16,12 +16,20 @@ Facter.add(:kernelrelease) do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Facter.add(:kernelrelease) do
|
19
|
-
confine :kernel =>
|
19
|
+
confine :kernel => "aix"
|
20
20
|
setcode 'oslevel -s'
|
21
21
|
end
|
22
22
|
|
23
23
|
Facter.add(:kernelrelease) do
|
24
|
-
confine :kernel =>
|
24
|
+
confine :kernel => "hp-ux"
|
25
|
+
setcode do
|
26
|
+
version = Facter::Util::Resolution.exec('uname -r')
|
27
|
+
version[2..-1]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Facter.add(:kernelrelease) do
|
32
|
+
confine :kernel => "windows"
|
25
33
|
setcode do
|
26
34
|
require 'facter/util/wmi'
|
27
35
|
version = ""
|
data/lib/facter/ldom.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
if Facter.value(:kernel) == 'SunOS'
|
2
|
+
virtinfo = Facter::Util::Resolution.exec('virtinfo -ap')
|
3
|
+
|
4
|
+
# Convert virtinfo parseable output format to array of arrays.
|
5
|
+
# DOMAINROLE|impl=LDoms|control=true|io=true|service=true|root=true
|
6
|
+
# DOMAINNAME|name=primary
|
7
|
+
# DOMAINUUID|uuid=8e0d6ec5-cd55-e57f-ae9f-b4cc050999a4
|
8
|
+
# DOMAINCONTROL|name=san-t2k-6
|
9
|
+
# DOMAINCHASSIS|serialno=0704RB0280
|
10
|
+
#
|
11
|
+
# For keys containing multiple value such as domain role:
|
12
|
+
# ldom_{key}_{subkey} = value
|
13
|
+
# Otherwise the fact will simply be:
|
14
|
+
# ldom_{key} = value
|
15
|
+
unless virtinfo.nil?
|
16
|
+
virt_array = virtinfo.split("\n").select{|l| l =~ /^DOMAIN/ }.
|
17
|
+
collect{|l| l.split('|')}
|
18
|
+
virt_array.each do |x|
|
19
|
+
key = x[0]
|
20
|
+
value = x[1..x.size]
|
21
|
+
|
22
|
+
if value.size == 1
|
23
|
+
Facter.add("ldom_#{key.downcase}") do
|
24
|
+
setcode { value.first.split('=')[1] }
|
25
|
+
end
|
26
|
+
else
|
27
|
+
value.each do |y|
|
28
|
+
k = y.split('=')[0]
|
29
|
+
v = y.split('=')[1]
|
30
|
+
Facter.add("ldom_#{key.downcase}_#{k.downcase}") do
|
31
|
+
setcode { v }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# When ldom domainrole control = false, the system is a guest, so we mark it
|
38
|
+
# as a virtual system:
|
39
|
+
Facter.add("virtual") do
|
40
|
+
confine :ldom_domainrole_control => 'false'
|
41
|
+
has_weight 10
|
42
|
+
setcode do
|
43
|
+
Facter.value(:ldom_domainrole_impl)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/facter/macaddress.rb
CHANGED
data/lib/facter/manufacturer.rb
CHANGED
@@ -47,10 +47,16 @@ else
|
|
47
47
|
{ 'Product(?: Name)?:' => 'boardproductname' },
|
48
48
|
{ 'Serial Number:' => 'boardserialnumber' }
|
49
49
|
],
|
50
|
+
'[Bb][Ii][Oo][Ss] [Ii]nformation' => [
|
51
|
+
{ '[Vv]endor:' => 'bios_vendor' },
|
52
|
+
{ '[Vv]ersion:' => 'bios_version' },
|
53
|
+
{ '[Rr]elease [Dd]ate:' => 'bios_release_date' }
|
54
|
+
],
|
50
55
|
'[Ss]ystem [Ii]nformation' => [
|
51
56
|
{ 'Manufacturer:' => 'manufacturer' },
|
52
57
|
{ 'Product(?: Name)?:' => 'productname' },
|
53
|
-
{ 'Serial Number:' => 'serialnumber' }
|
58
|
+
{ 'Serial Number:' => 'serialnumber' },
|
59
|
+
{ 'UUID:' => 'uuid' }
|
54
60
|
],
|
55
61
|
'(Chassis Information|system enclosure or chassis)' => [
|
56
62
|
{ '(?:Chassis )?Type:' => 'type' }
|
data/lib/facter/memory.rb
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
# On AIX, parses "swap -l" for swap values only.
|
9
9
|
# On OpenBSD, it parses "swapctl -l" for swap values, vmstat via a module for
|
10
10
|
# free memory, and "sysctl hw.physmem" for maximum memory.
|
11
|
+
# On FreeBSD, it parses "swapinfo -k" for swap values, and parses sysctl for
|
12
|
+
# maximum memory.
|
11
13
|
# On Solaris, use "swap -l" for swap values, and parsing prtconf for maximum
|
12
14
|
# memory, and again, the vmstat module for free memory.
|
13
15
|
#
|
@@ -22,227 +24,132 @@
|
|
22
24
|
# Author: Matthew Palmer <matt@solutionsfirst.com.au>
|
23
25
|
#
|
24
26
|
#
|
27
|
+
|
25
28
|
require 'facter/util/memory'
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
[ "memorysize",
|
31
|
+
"memoryfree",
|
32
|
+
"swapsize",
|
33
|
+
"swapfree"
|
34
|
+
].each do |fact|
|
32
35
|
Facter.add(fact) do
|
33
|
-
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
34
36
|
setcode do
|
35
|
-
Facter
|
37
|
+
name = Facter.fact(fact + "_mb").value
|
38
|
+
Facter::Memory.scale_number(name.to_f, "MB") if name
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
|
-
Facter.add("
|
41
|
-
confine :kernel => :Darwin
|
43
|
+
Facter.add("swapsize_mb") do
|
42
44
|
setcode do
|
43
|
-
|
44
|
-
swaptotal
|
45
|
-
if swap =~ /total = (\S+)/ then swaptotal = $1; end
|
46
|
-
swaptotal
|
45
|
+
swaptotal = Facter::Memory.swap_size
|
46
|
+
"%.2f" % [swaptotal] if swaptotal
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
Facter.add("
|
51
|
-
confine :kernel => :Darwin
|
50
|
+
Facter.add("swapfree_mb") do
|
52
51
|
setcode do
|
53
|
-
|
54
|
-
swapfree
|
55
|
-
if swap =~ /free = (\S+)/ then swapfree = $1; end
|
56
|
-
swapfree
|
52
|
+
swapfree = Facter::Memory.swap_free
|
53
|
+
"%.2f" % [swapfree] if swapfree
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
60
|
-
Facter.add("
|
61
|
-
confine :kernel => :Darwin
|
57
|
+
Facter.add("memorysize_mb") do
|
62
58
|
setcode do
|
63
|
-
|
64
|
-
|
65
|
-
if swap =~ /\(encrypted\)/ then encrypted = true; end
|
66
|
-
encrypted
|
59
|
+
memtotal = Facter::Memory.mem_size
|
60
|
+
"%.2f" % [memtotal] if memtotal
|
67
61
|
end
|
68
62
|
end
|
69
63
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/
|
75
|
-
swaptotal += $1.to_i
|
76
|
-
swapfree += $2.to_i
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
Facter.add("SwapSize") do
|
81
|
-
confine :kernel => :aix
|
82
|
-
setcode do
|
83
|
-
Facter::Memory.scale_number(swaptotal.to_f,"MB")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
Facter.add("SwapFree") do
|
88
|
-
confine :kernel => :aix
|
89
|
-
setcode do
|
90
|
-
Facter::Memory.scale_number(swapfree.to_f,"MB")
|
91
|
-
end
|
64
|
+
Facter.add("memoryfree_mb") do
|
65
|
+
setcode do
|
66
|
+
memfree = Facter::Memory.mem_free
|
67
|
+
"%.2f" % [memfree] if memfree
|
92
68
|
end
|
93
69
|
end
|
94
70
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
Facter.add("SwapSize") do
|
104
|
-
confine :kernel => :openbsd
|
105
|
-
setcode do
|
106
|
-
Facter::Memory.scale_number(swaptotal.to_f,"kB")
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
Facter.add("SwapFree") do
|
111
|
-
confine :kernel => :openbsd
|
112
|
-
setcode do
|
113
|
-
Facter::Memory.scale_number(swapfree.to_f,"kB")
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
Facter::Memory.vmstat_find_free_memory()
|
118
|
-
|
119
|
-
Facter.add("memorysize") do
|
120
|
-
confine :kernel => :openbsd
|
121
|
-
memtotal = Facter::Util::Resolution.exec("sysctl hw.physmem | cut -d'=' -f2")
|
71
|
+
{ :memorysize_mb => "MemTotal",
|
72
|
+
:memoryfree_mb => "MemFree",
|
73
|
+
:swapsize_mb => "SwapTotal",
|
74
|
+
:swapfree_mb => "SwapFree"
|
75
|
+
}.each do |fact, name|
|
76
|
+
Facter.add(fact) do
|
77
|
+
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
122
78
|
setcode do
|
123
|
-
Facter::Memory.
|
79
|
+
meminfo = Facter::Memory.meminfo_number(name)
|
80
|
+
"%.2f" % [meminfo]
|
124
81
|
end
|
125
82
|
end
|
126
83
|
end
|
127
84
|
|
128
85
|
if Facter.value(:kernel) == "Darwin"
|
129
|
-
|
130
|
-
swapfree, swaptotal = 0, 0
|
131
|
-
unless swap.empty?
|
132
|
-
# Parse the line:
|
133
|
-
# vm.swapusage: total = 128.00M used = 0.37M free = 127.63M (encrypted)
|
134
|
-
if swap =~ /total\s=\s(\S+)\s+used\s=\s(\S+)\s+free\s=\s(\S+)\s/
|
135
|
-
swaptotal += $1.to_i
|
136
|
-
swapfree += $3.to_i
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
Facter.add("SwapSize") do
|
141
|
-
confine :kernel => :Darwin
|
142
|
-
setcode do
|
143
|
-
Facter::Memory.scale_number(swaptotal.to_f,"MB")
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
Facter.add("SwapFree") do
|
86
|
+
Facter.add("SwapEncrypted") do
|
148
87
|
confine :kernel => :Darwin
|
149
88
|
setcode do
|
150
|
-
Facter::
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
Facter::Memory.vmstat_darwin_find_free_memory()
|
155
|
-
|
156
|
-
Facter.add("memorysize") do
|
157
|
-
confine :kernel => :Darwin
|
158
|
-
memtotal = Facter::Util::Resolution.exec("sysctl hw.memsize | cut -d':' -f2")
|
159
|
-
setcode do
|
160
|
-
Facter::Memory.scale_number(memtotal.to_f,"")
|
89
|
+
swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
|
90
|
+
encrypted = false
|
91
|
+
if swap =~ /\(encrypted\)/ then encrypted = true; end
|
92
|
+
encrypted
|
161
93
|
end
|
162
94
|
end
|
163
95
|
end
|
164
96
|
|
165
97
|
if Facter.value(:kernel) == "SunOS"
|
166
|
-
swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l')
|
167
|
-
swapfree, swaptotal = 0, 0
|
168
|
-
swap.each_line do |dev|
|
169
|
-
if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/
|
170
|
-
swaptotal += $1.to_i / 2
|
171
|
-
swapfree += $2.to_i / 2
|
172
|
-
end
|
173
|
-
end
|
174
98
|
|
175
|
-
Facter.add("
|
99
|
+
Facter.add("memorysize_mb") do
|
176
100
|
confine :kernel => :sunos
|
177
|
-
|
178
|
-
|
101
|
+
# Total memory size available from prtconf
|
102
|
+
pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf 2>/dev/null')
|
103
|
+
phymem = ""
|
104
|
+
pconf.each_line do |line|
|
105
|
+
if line =~ /^Memory size:\s+(\d+) Megabytes/
|
106
|
+
phymem = $1
|
107
|
+
end
|
179
108
|
end
|
180
|
-
end
|
181
|
-
|
182
|
-
Facter.add("SwapFree") do
|
183
|
-
confine :kernel => :sunos
|
184
109
|
setcode do
|
185
|
-
|
110
|
+
"%.2f" % [phymem.to_f]
|
186
111
|
end
|
187
112
|
end
|
188
|
-
|
189
|
-
# Total memory size available from prtconf
|
190
|
-
pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf 2>/dev/null')
|
191
|
-
phymem = ""
|
192
|
-
pconf.each_line do |line|
|
193
|
-
if line =~ /^Memory size:\s+(\d+) Megabytes/
|
194
|
-
phymem = $1
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
Facter.add("MemorySize") do
|
199
|
-
confine :kernel => :sunos
|
200
|
-
setcode do
|
201
|
-
Facter::Memory.scale_number(phymem.to_f,"MB")
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
Facter::Memory.vmstat_find_free_memory()
|
206
113
|
end
|
207
114
|
|
208
115
|
if Facter.value(:kernel) == "windows"
|
209
116
|
require 'facter/util/wmi'
|
210
117
|
|
211
|
-
Facter.add("
|
118
|
+
Facter.add("memorysize_mb") do
|
212
119
|
confine :kernel => :windows
|
213
120
|
setcode do
|
214
121
|
mem = 0
|
215
|
-
Facter::Util::WMI.execquery("select
|
216
|
-
mem =
|
122
|
+
Facter::Util::WMI.execquery("select TotalPhysicalMemory from Win32_ComputerSystem").each do |comp|
|
123
|
+
mem = comp.TotalPhysicalMemory
|
217
124
|
break
|
218
125
|
end
|
219
|
-
|
126
|
+
"%.2f" % [(mem.to_f / 1024.0) / 1024.0]
|
220
127
|
end
|
221
128
|
end
|
222
129
|
|
223
|
-
Facter.add("
|
130
|
+
Facter.add("memoryfree_mb") do
|
224
131
|
confine :kernel => :windows
|
225
132
|
setcode do
|
226
133
|
mem = 0
|
227
|
-
Facter::Util::WMI.execquery("select
|
228
|
-
mem =
|
134
|
+
Facter::Util::WMI.execquery("select FreePhysicalMemory from Win32_OperatingSystem").each do |os|
|
135
|
+
mem = os.FreePhysicalMemory
|
229
136
|
break
|
230
137
|
end
|
231
|
-
|
138
|
+
"%.2f" % [mem.to_f / 1024.0]
|
232
139
|
end
|
233
140
|
end
|
234
141
|
end
|
235
142
|
|
236
|
-
Facter.add("
|
143
|
+
Facter.add("swapsize_mb") do
|
237
144
|
confine :kernel => :dragonfly
|
238
145
|
setcode do
|
239
146
|
page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f
|
240
147
|
swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size
|
241
|
-
|
148
|
+
"%.2f" % [(swaptotal.to_f / 1024.0) / 1024.0]
|
242
149
|
end
|
243
150
|
end
|
244
151
|
|
245
|
-
Facter.add("
|
152
|
+
Facter.add("swapfree_mb") do
|
246
153
|
confine :kernel => :dragonfly
|
247
154
|
setcode do
|
248
155
|
page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f
|
@@ -250,16 +157,7 @@ Facter.add("SwapFree") do
|
|
250
157
|
swap_anon_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_anon_use").to_f * page_size
|
251
158
|
swap_cache_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_cache_use").to_f * page_size
|
252
159
|
swapfree = swaptotal - swap_anon_use - swap_cache_use
|
253
|
-
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
Facter.add("memorysize") do
|
258
|
-
confine :kernel => :dragonfly
|
259
|
-
setcode do
|
260
|
-
Facter::Memory.vmstat_find_free_memory()
|
261
|
-
memtotal = Facter::Util::Resolution.exec("sysctl -n hw.physmem")
|
262
|
-
Facter::Memory.scale_number(memtotal.to_f,"")
|
160
|
+
"%.2f" % [(swapfree.to_f / 1024.0) / 1024.0]
|
263
161
|
end
|
264
162
|
end
|
265
163
|
|