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
@@ -10,20 +10,20 @@
10
10
  #
11
11
 
12
12
  Facter.add(:iphostnumber) do
13
- confine :kernel => :darwin, :kernelrelease => "R6"
14
- setcode do
15
- %x{/usr/sbin/scutil --get LocalHostName}
16
- end
13
+ confine :kernel => :darwin, :kernelrelease => "R6"
14
+ setcode do
15
+ %x{/usr/sbin/scutil --get LocalHostName}
16
+ end
17
17
  end
18
18
  Facter.add(:iphostnumber) do
19
- confine :kernel => :darwin, :kernelrelease => "R6"
20
- setcode do
21
- ether = nil
22
- output = %x{/sbin/ifconfig}
19
+ confine :kernel => :darwin, :kernelrelease => "R6"
20
+ setcode do
21
+ ether = nil
22
+ output = %x{/sbin/ifconfig}
23
23
 
24
- output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
25
- ether = $1
24
+ output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
25
+ ether = $1
26
26
 
27
- ether
28
- end
27
+ ether
28
+ end
29
29
  end
@@ -10,13 +10,13 @@
10
10
  #
11
11
 
12
12
  Facter.add(:kernel) do
13
- setcode do
14
- require 'facter/util/config'
13
+ setcode do
14
+ require 'facter/util/config'
15
15
 
16
- if Facter::Util::Config.is_windows?
17
- 'windows'
18
- else
19
- Facter::Util::Resolution.exec("uname -s")
20
- end
16
+ if Facter::Util::Config.is_windows?
17
+ 'windows'
18
+ else
19
+ Facter::Util::Resolution.exec("uname -s")
21
20
  end
21
+ end
22
22
  end
@@ -9,7 +9,7 @@
9
9
  #
10
10
 
11
11
  Facter.add("kernelmajversion") do
12
- setcode do
13
- Facter.value(:kernelversion).split('.')[0..1].join('.')
14
- end
12
+ setcode do
13
+ Facter.value(:kernelversion).split('.')[0..1].join('.')
14
+ end
15
15
  end
@@ -12,23 +12,23 @@
12
12
  #
13
13
 
14
14
  Facter.add(:kernelrelease) do
15
- setcode 'uname -r'
15
+ setcode 'uname -r'
16
16
  end
17
17
 
18
18
  Facter.add(:kernelrelease) do
19
- confine :kernel => :aix
20
- setcode 'oslevel -s'
19
+ confine :kernel => :aix
20
+ setcode 'oslevel -s'
21
21
  end
22
22
 
23
23
  Facter.add(:kernelrelease) do
24
- confine :kernel => %{windows}
25
- setcode do
26
- require 'facter/util/wmi'
27
- version = ""
28
- Facter::Util::WMI.execquery("SELECT Version from Win32_OperatingSystem").each do |ole|
29
- version = "#{ole.Version}"
30
- break
31
- end
32
- version
24
+ confine :kernel => %{windows}
25
+ setcode do
26
+ require 'facter/util/wmi'
27
+ version = ""
28
+ Facter::Util::WMI.execquery("SELECT Version from Win32_OperatingSystem").each do |ole|
29
+ version = "#{ole.Version}"
30
+ break
33
31
  end
32
+ version
33
+ end
34
34
  end
@@ -11,12 +11,12 @@
11
11
  #
12
12
 
13
13
  Facter.add("kernelversion") do
14
- setcode do
15
- Facter['kernelrelease'].value.split('-')[0]
16
- end
14
+ setcode do
15
+ Facter['kernelrelease'].value.split('-')[0]
16
+ end
17
17
  end
18
18
 
19
19
  Facter.add("kernelversion") do
20
- confine :kernel => :sunos
21
- setcode 'uname -v'
20
+ confine :kernel => :sunos
21
+ setcode 'uname -v'
22
22
  end
@@ -20,20 +20,20 @@
20
20
  "LSBDistDescription" => %r{^Description:\t(.*)$},
21
21
  "LSBDistCodeName" => %r{^Codename:\t(.*)$}
22
22
  }.each do |fact, pattern|
23
- Facter.add(fact) do
24
- confine :kernel => [ :linux, :"gnu/kfreebsd" ]
25
- setcode do
26
- unless defined?(lsbdata) and defined?(lsbtime) and (Time.now.to_i - lsbtime.to_i < 5)
27
- type = nil
28
- lsbtime = Time.now
29
- lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
30
- end
23
+ Facter.add(fact) do
24
+ confine :kernel => [ :linux, :"gnu/kfreebsd" ]
25
+ setcode do
26
+ unless defined?(lsbdata) and defined?(lsbtime) and (Time.now.to_i - lsbtime.to_i < 5)
27
+ type = nil
28
+ lsbtime = Time.now
29
+ lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
30
+ end
31
31
 
32
- if pattern.match(lsbdata)
33
- $1
34
- else
35
- nil
36
- end
37
- end
32
+ if pattern.match(lsbdata)
33
+ $1
34
+ else
35
+ nil
36
+ end
38
37
  end
38
+ end
39
39
  end
@@ -15,13 +15,13 @@
15
15
  require 'facter'
16
16
 
17
17
  Facter.add("lsbmajdistrelease") do
18
- confine :operatingsystem => %w{Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo OEL OracleLinux OVS GNU/kFreeBSD}
19
- setcode do
20
- if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
21
- result=$1
22
- else
23
- result=Facter.value(:lsbdistrelease)
24
- end
25
- result
18
+ confine :operatingsystem => %w{Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo OEL OracleLinux OVS GNU/kFreeBSD}
19
+ setcode do
20
+ if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
21
+ result=$1
22
+ else
23
+ result=Facter.value(:lsbdistrelease)
26
24
  end
25
+ result
26
+ end
27
27
  end
@@ -10,69 +10,69 @@
10
10
  require 'facter/util/macaddress'
11
11
 
12
12
  Facter.add(:macaddress) do
13
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Gentoo Ubuntu OEL OracleLinux OVS GNU/kFreeBSD}
14
- setcode do
15
- ether = []
16
- output = Facter::Util::Resolution.exec("/sbin/ifconfig -a")
17
- output.each_line do |s|
18
- 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})/
19
- end
20
- Facter::Util::Macaddress.standardize(ether[0])
13
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Gentoo Ubuntu OEL OracleLinux OVS GNU/kFreeBSD}
14
+ setcode do
15
+ ether = []
16
+ output = Facter::Util::Resolution.exec("/sbin/ifconfig -a")
17
+ output.each_line do |s|
18
+ 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})/
21
19
  end
20
+ Facter::Util::Macaddress.standardize(ether[0])
21
+ end
22
22
  end
23
23
 
24
24
  Facter.add(:macaddress) do
25
- confine :operatingsystem => "Solaris"
26
- setcode do
27
- ether = []
28
- output = Facter::Util::Resolution.exec("/usr/bin/netstat -np")
29
- output.each_line do |s|
30
- ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/
31
- end
32
- Facter::Util::Macaddress.standardize(ether[0])
25
+ confine :operatingsystem => "Solaris"
26
+ setcode do
27
+ ether = []
28
+ output = Facter::Util::Resolution.exec("/usr/bin/netstat -np")
29
+ output.each_line do |s|
30
+ ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/
33
31
  end
32
+ Facter::Util::Macaddress.standardize(ether[0])
33
+ end
34
34
  end
35
35
 
36
36
  Facter.add(:macaddress) do
37
- confine :operatingsystem => %w{FreeBSD OpenBSD}
38
- setcode do
37
+ confine :operatingsystem => %w{FreeBSD OpenBSD DragonFly}
38
+ setcode do
39
39
  ether = []
40
- output = Facter::Util::Resolution.exec("/sbin/ifconfig")
41
- output.each_line do |s|
42
- if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
43
- ether.push($1)
44
- end
45
- end
46
- Facter::Util::Macaddress.standardize(ether[0])
40
+ output = Facter::Util::Resolution.exec("/sbin/ifconfig")
41
+ output.each_line do |s|
42
+ if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
43
+ ether.push($1)
44
+ end
47
45
  end
46
+ Facter::Util::Macaddress.standardize(ether[0])
47
+ end
48
48
  end
49
49
 
50
50
  Facter.add(:macaddress) do
51
- confine :kernel => :darwin
52
- setcode { Facter::Util::Macaddress::Darwin.macaddress }
51
+ confine :kernel => :darwin
52
+ setcode { Facter::Util::Macaddress::Darwin.macaddress }
53
53
  end
54
54
 
55
55
  Facter.add(:macaddress) do
56
- confine :kernel => %w{AIX}
57
- setcode do
58
- ether = []
59
- ip = nil
60
- output = %x{/usr/sbin/ifconfig -a}
61
- output.each_line do |str|
62
- if str =~ /([a-z]+\d+): flags=/
63
- devname = $1
64
- unless devname =~ /lo0/
65
- output2 = %x{/usr/bin/entstat #{devname}}
66
- output2.each_line do |str2|
67
- if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
68
- ether.push($1)
69
- end
70
- end
71
- end
56
+ confine :kernel => %w{AIX}
57
+ setcode do
58
+ ether = []
59
+ ip = nil
60
+ output = %x{/usr/sbin/ifconfig -a}
61
+ output.each_line do |str|
62
+ if str =~ /([a-z]+\d+): flags=/
63
+ devname = $1
64
+ unless devname =~ /lo0/
65
+ output2 = %x{/usr/bin/entstat #{devname}}
66
+ output2.each_line do |str2|
67
+ if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
68
+ ether.push($1)
72
69
  end
70
+ end
73
71
  end
74
- Facter::Util::Macaddress.standardize(ether[0])
72
+ end
75
73
  end
74
+ Facter::Util::Macaddress.standardize(ether[0])
75
+ end
76
76
  end
77
77
 
78
78
  Facter.add(:macaddress) do
@@ -27,30 +27,30 @@
27
27
  require 'facter/util/macosx'
28
28
 
29
29
  if Facter.value(:kernel) == "Darwin"
30
- Facter::Util::Macosx.hardware_overview.each do |fact, value|
31
- Facter.add("sp_#{fact}") do
32
- confine :kernel => :darwin
33
- setcode do
34
- value.to_s
35
- end
36
- end
30
+ Facter::Util::Macosx.hardware_overview.each do |fact, value|
31
+ Facter.add("sp_#{fact}") do
32
+ confine :kernel => :darwin
33
+ setcode do
34
+ value.to_s
35
+ end
37
36
  end
37
+ end
38
38
 
39
- Facter::Util::Macosx.os_overview.each do |fact, value|
40
- Facter.add("sp_#{fact}") do
41
- confine :kernel => :darwin
42
- setcode do
43
- value.to_s
44
- end
45
- end
39
+ Facter::Util::Macosx.os_overview.each do |fact, value|
40
+ Facter.add("sp_#{fact}") do
41
+ confine :kernel => :darwin
42
+ setcode do
43
+ value.to_s
44
+ end
46
45
  end
46
+ end
47
47
 
48
- Facter::Util::Macosx.sw_vers.each do |fact, value|
49
- Facter.add(fact) do
50
- confine :kernel => :darwin
51
- setcode do
52
- value
53
- end
54
- end
48
+ Facter::Util::Macosx.sw_vers.each do |fact, value|
49
+ Facter.add(fact) do
50
+ confine :kernel => :darwin
51
+ setcode do
52
+ value
53
+ end
55
54
  end
55
+ end
56
56
  end
@@ -19,39 +19,39 @@
19
19
  require 'facter/util/manufacturer'
20
20
 
21
21
  if Facter.value(:kernel) == "OpenBSD"
22
- mfg_keys = {
23
- 'hw.vendor' => 'manufacturer',
24
- 'hw.product' => 'productname',
25
- 'hw.serialno' => 'serialnumber'
26
- }
22
+ mfg_keys = {
23
+ 'hw.vendor' => 'manufacturer',
24
+ 'hw.product' => 'productname',
25
+ 'hw.serialno' => 'serialnumber'
26
+ }
27
27
 
28
- Facter::Manufacturer.sysctl_find_system_info(mfg_keys)
28
+ Facter::Manufacturer.sysctl_find_system_info(mfg_keys)
29
29
  elsif Facter.value(:kernel) == "Darwin"
30
- mfg_keys = {
31
- 'hw.model' => 'productname'
32
- }
33
- Facter::Manufacturer.sysctl_find_system_info(mfg_keys)
30
+ mfg_keys = {
31
+ 'hw.model' => 'productname'
32
+ }
33
+ Facter::Manufacturer.sysctl_find_system_info(mfg_keys)
34
34
  elsif Facter.value(:kernel) == "SunOS" and Facter.value(:hardwareisa) == "sparc"
35
- Facter::Manufacturer.prtdiag_sparc_find_system_info()
35
+ Facter::Manufacturer.prtdiag_sparc_find_system_info()
36
36
  elsif Facter.value(:kernel) == "windows"
37
- win32_keys = {
38
- 'manufacturer' => ['Manufacturer', 'Bios'],
39
- 'serialNumber' => ['Serialnumber', 'Bios'],
40
- 'productname' => ['Name', 'ComputerSystemProduct']
41
- }
42
- Facter::Manufacturer.win32_find_system_info(win32_keys)
37
+ win32_keys = {
38
+ 'manufacturer' => ['Manufacturer', 'Bios'],
39
+ 'serialNumber' => ['Serialnumber', 'Bios'],
40
+ 'productname' => ['Name', 'ComputerSystemProduct']
41
+ }
42
+ Facter::Manufacturer.win32_find_system_info(win32_keys)
43
43
  else
44
- query = {
45
- '[Ss]ystem [Ii]nformation' => [
46
- { 'Manufacturer:' => 'manufacturer' },
47
- { 'Product(?: Name)?:' => 'productname' },
48
- { 'Serial Number:' => 'serialnumber' }
49
- ],
50
- '(Chassis Information|system enclosure or chassis)' => [
51
- { '(?:Chassis )?Type:' => 'type' }
52
- ]
53
- }
44
+ query = {
45
+ '[Ss]ystem [Ii]nformation' => [
46
+ { 'Manufacturer:' => 'manufacturer' },
47
+ { 'Product(?: Name)?:' => 'productname' },
48
+ { 'Serial Number:' => 'serialnumber' }
49
+ ],
50
+ '(Chassis Information|system enclosure or chassis)' => [
51
+ { '(?:Chassis )?Type:' => 'type' }
52
+ ]
53
+ }
54
54
 
55
- Facter::Manufacturer.dmi_find_system_info(query)
55
+ Facter::Manufacturer.dmi_find_system_info(query)
56
56
  end
57
57
 
@@ -29,182 +29,180 @@ require 'facter/util/memory'
29
29
  :SwapSize => "SwapTotal",
30
30
  :SwapFree => "SwapFree"
31
31
  }.each do |fact, name|
32
- Facter.add(fact) do
33
- confine :kernel => [ :linux, :"gnu/kfreebsd" ]
34
- setcode do
35
- Facter::Memory.meminfo_number(name)
36
- end
32
+ Facter.add(fact) do
33
+ confine :kernel => [ :linux, :"gnu/kfreebsd" ]
34
+ setcode do
35
+ Facter::Memory.meminfo_number(name)
37
36
  end
37
+ end
38
38
  end
39
39
 
40
40
  Facter.add("SwapSize") do
41
- confine :kernel => :Darwin
42
- setcode do
41
+ confine :kernel => :Darwin
42
+ setcode do
43
43
  swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
44
44
  swaptotal = 0
45
45
  if swap =~ /total = (\S+)/ then swaptotal = $1; end
46
- swaptotal
47
- end
46
+ swaptotal
47
+ end
48
48
  end
49
49
 
50
50
  Facter.add("SwapFree") do
51
- confine :kernel => :Darwin
52
- setcode do
51
+ confine :kernel => :Darwin
52
+ setcode do
53
53
  swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
54
54
  swapfree = 0
55
55
  if swap =~ /free = (\S+)/ then swapfree = $1; end
56
- swapfree
57
- end
56
+ swapfree
57
+ end
58
58
  end
59
59
 
60
60
  Facter.add("SwapEncrypted") do
61
- confine :kernel => :Darwin
62
- setcode do
61
+ confine :kernel => :Darwin
62
+ setcode do
63
63
  swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
64
64
  encrypted = false
65
65
  if swap =~ /\(encrypted\)/ then encrypted = true; end
66
- encrypted
67
- end
66
+ encrypted
67
+ end
68
68
  end
69
69
 
70
70
  if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root"
71
- swap = Facter::Util::Resolution.exec('swap -l')
72
- swapfree, swaptotal = 0, 0
73
- swap.each_line do |dev|
74
- if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/
75
- swaptotal += $1.to_i
76
- swapfree += $2.to_i
77
- end
71
+ swap = Facter::Util::Resolution.exec('swap -l')
72
+ swapfree, swaptotal = 0, 0
73
+ swap.each_line do |dev|
74
+ if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/
75
+ swaptotal += $1.to_i
76
+ swapfree += $2.to_i
78
77
  end
78
+ end
79
79
 
80
- Facter.add("SwapSize") do
81
- confine :kernel => :aix
82
- setcode do
83
- Facter::Memory.scale_number(swaptotal.to_f,"MB")
84
- end
80
+ Facter.add("SwapSize") do
81
+ confine :kernel => :aix
82
+ setcode do
83
+ Facter::Memory.scale_number(swaptotal.to_f,"MB")
85
84
  end
85
+ end
86
86
 
87
- Facter.add("SwapFree") do
88
- confine :kernel => :aix
89
- setcode do
90
- Facter::Memory.scale_number(swapfree.to_f,"MB")
91
- end
87
+ Facter.add("SwapFree") do
88
+ confine :kernel => :aix
89
+ setcode do
90
+ Facter::Memory.scale_number(swapfree.to_f,"MB")
92
91
  end
92
+ end
93
93
  end
94
94
 
95
95
  if Facter.value(:kernel) == "OpenBSD"
96
- swap = Facter::Util::Resolution.exec('swapctl -l | sed 1d')
97
- swapfree, swaptotal = 0, 0
98
- swap.each_line do |dev|
99
- if dev =~ /^\S+\s+(\S+)\s+\S+\s+(\S+)\s+.*$/
100
- swaptotal += $1.to_i
101
- swapfree += $2.to_i
102
- end
103
- end
96
+ swap = Facter::Util::Resolution.exec('swapctl -s')
97
+ swapfree, swaptotal = 0, 0
98
+ if swap =~ /^total: (\d+)k bytes allocated = \d+k used, (\d+)k available$/
99
+ swaptotal = $1.to_i
100
+ swapfree = $2.to_i
101
+ end
104
102
 
105
- Facter.add("SwapSize") do
106
- confine :kernel => :openbsd
107
- setcode do
108
- Facter::Memory.scale_number(swaptotal.to_f,"kB")
109
- end
103
+ Facter.add("SwapSize") do
104
+ confine :kernel => :openbsd
105
+ setcode do
106
+ Facter::Memory.scale_number(swaptotal.to_f,"kB")
110
107
  end
108
+ end
111
109
 
112
- Facter.add("SwapFree") do
113
- confine :kernel => :openbsd
114
- setcode do
115
- Facter::Memory.scale_number(swapfree.to_f,"kB")
116
- end
110
+ Facter.add("SwapFree") do
111
+ confine :kernel => :openbsd
112
+ setcode do
113
+ Facter::Memory.scale_number(swapfree.to_f,"kB")
117
114
  end
115
+ end
118
116
 
119
- Facter::Memory.vmstat_find_free_memory()
117
+ Facter::Memory.vmstat_find_free_memory()
120
118
 
121
- Facter.add("MemoryTotal") do
122
- confine :kernel => :openbsd
123
- memtotal = Facter::Util::Resolution.exec("sysctl hw.physmem | cut -d'=' -f2")
124
- setcode do
125
- Facter::Memory.scale_number(memtotal.to_f,"")
126
- end
119
+ Facter.add("MemoryTotal") do
120
+ confine :kernel => :openbsd
121
+ memtotal = Facter::Util::Resolution.exec("sysctl hw.physmem | cut -d'=' -f2")
122
+ setcode do
123
+ Facter::Memory.scale_number(memtotal.to_f,"")
127
124
  end
125
+ end
128
126
  end
129
127
 
130
128
  if Facter.value(:kernel) == "Darwin"
131
- swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
132
- swapfree, swaptotal = 0, 0
133
- unless swap.empty?
134
- # Parse the line:
135
- # vm.swapusage: total = 128.00M used = 0.37M free = 127.63M (encrypted)
136
- if swap =~ /total\s=\s(\S+)\s+used\s=\s(\S+)\s+free\s=\s(\S+)\s/
137
- swaptotal += $1.to_i
138
- swapfree += $3.to_i
139
- end
129
+ swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
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
140
137
  end
138
+ end
141
139
 
142
- Facter.add("SwapSize") do
143
- confine :kernel => :Darwin
144
- setcode do
145
- Facter::Memory.scale_number(swaptotal.to_f,"MB")
146
- end
140
+ Facter.add("SwapSize") do
141
+ confine :kernel => :Darwin
142
+ setcode do
143
+ Facter::Memory.scale_number(swaptotal.to_f,"MB")
147
144
  end
145
+ end
148
146
 
149
- Facter.add("SwapFree") do
150
- confine :kernel => :Darwin
151
- setcode do
152
- Facter::Memory.scale_number(swapfree.to_f,"MB")
153
- end
147
+ Facter.add("SwapFree") do
148
+ confine :kernel => :Darwin
149
+ setcode do
150
+ Facter::Memory.scale_number(swapfree.to_f,"MB")
154
151
  end
152
+ end
155
153
 
156
- Facter::Memory.vmstat_darwin_find_free_memory()
154
+ Facter::Memory.vmstat_darwin_find_free_memory()
157
155
 
158
- Facter.add("MemoryTotal") do
159
- confine :kernel => :Darwin
160
- memtotal = Facter::Util::Resolution.exec("sysctl hw.memsize | cut -d':' -f2")
161
- setcode do
162
- Facter::Memory.scale_number(memtotal.to_f,"")
163
- end
156
+ Facter.add("MemoryTotal") 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,"")
164
161
  end
162
+ end
165
163
  end
166
164
 
167
165
  if Facter.value(:kernel) == "SunOS"
168
- swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l')
169
- swapfree, swaptotal = 0, 0
170
- swap.each_line do |dev|
171
- if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/
172
- swaptotal += $1.to_i / 2
173
- swapfree += $2.to_i / 2
174
- end
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
175
172
  end
173
+ end
176
174
 
177
- Facter.add("SwapSize") do
178
- confine :kernel => :sunos
179
- setcode do
180
- Facter::Memory.scale_number(swaptotal.to_f,"kB")
181
- end
175
+ Facter.add("SwapSize") do
176
+ confine :kernel => :sunos
177
+ setcode do
178
+ Facter::Memory.scale_number(swaptotal.to_f,"kB")
182
179
  end
180
+ end
183
181
 
184
- Facter.add("SwapFree") do
185
- confine :kernel => :sunos
186
- setcode do
187
- Facter::Memory.scale_number(swapfree.to_f,"kB")
188
- end
182
+ Facter.add("SwapFree") do
183
+ confine :kernel => :sunos
184
+ setcode do
185
+ Facter::Memory.scale_number(swapfree.to_f,"kB")
189
186
  end
187
+ end
190
188
 
191
- # Total memory size available from prtconf
192
- pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf')
193
- phymem = ""
194
- pconf.each_line do |line|
195
- if line =~ /^Memory size:\s+(\d+) Megabytes/
196
- phymem = $1
197
- end
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
198
195
  end
196
+ end
199
197
 
200
- Facter.add("MemorySize") do
201
- confine :kernel => :sunos
202
- setcode do
203
- Facter::Memory.scale_number(phymem.to_f,"MB")
204
- end
198
+ Facter.add("MemorySize") do
199
+ confine :kernel => :sunos
200
+ setcode do
201
+ Facter::Memory.scale_number(phymem.to_f,"MB")
205
202
  end
203
+ end
206
204
 
207
- Facter::Memory.vmstat_find_free_memory()
205
+ Facter::Memory.vmstat_find_free_memory()
208
206
  end
209
207
 
210
208
  if Facter.value(:kernel) == "windows"
@@ -234,3 +232,33 @@ if Facter.value(:kernel) == "windows"
234
232
  end
235
233
  end
236
234
  end
235
+
236
+ Facter.add("SwapSize") do
237
+ confine :kernel => :dragonfly
238
+ setcode do
239
+ page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f
240
+ swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size
241
+ Facter::Memory.scale_number(swaptotal.to_f,"")
242
+ end
243
+ end
244
+
245
+ Facter.add("SwapFree") do
246
+ confine :kernel => :dragonfly
247
+ setcode do
248
+ page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f
249
+ swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size
250
+ swap_anon_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_anon_use").to_f * page_size
251
+ swap_cache_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_cache_use").to_f * page_size
252
+ swapfree = swaptotal - swap_anon_use - swap_cache_use
253
+ Facter::Memory.scale_number(swapfree.to_f,"")
254
+ end
255
+ end
256
+
257
+ Facter.add("MemoryTotal") 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,"")
263
+ end
264
+ end