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.

Files changed (126) hide show
  1. data/Gemfile +23 -8
  2. data/bin/facter +4 -1
  3. data/ext/build_defaults.yaml +1 -1
  4. data/ext/debian/changelog.erb +4 -22
  5. data/ext/debian/control +2 -2
  6. data/ext/project_data.yaml +1 -1
  7. data/ext/redhat/facter.spec.erb +10 -9
  8. data/install.rb +27 -53
  9. data/lib/facter.rb +23 -5
  10. data/lib/facter/application.rb +21 -0
  11. data/lib/facter/blockdevices.rb +105 -0
  12. data/lib/facter/domain.rb +19 -7
  13. data/lib/facter/filesystems.rb +38 -0
  14. data/lib/facter/hardwaremodel.rb +3 -2
  15. data/lib/facter/ipaddress6.rb +1 -2
  16. data/lib/facter/kernelrelease.rb +10 -2
  17. data/lib/facter/ldom.rb +47 -0
  18. data/lib/facter/macaddress.rb +1 -1
  19. data/lib/facter/manufacturer.rb +7 -1
  20. data/lib/facter/memory.rb +58 -160
  21. data/lib/facter/operatingsystem.rb +17 -2
  22. data/lib/facter/operatingsystemmajrelease.rb +33 -0
  23. data/lib/facter/operatingsystemrelease.rb +88 -37
  24. data/lib/facter/osfamily.rb +6 -2
  25. data/lib/facter/processor.rb +2 -2
  26. data/lib/facter/ps.rb +5 -0
  27. data/lib/facter/ssh.rb +50 -12
  28. data/lib/facter/util/cfpropertylist.rb +6 -0
  29. data/lib/facter/util/cfpropertylist/LICENSE +19 -0
  30. data/lib/facter/util/cfpropertylist/README +44 -0
  31. data/lib/facter/util/cfpropertylist/Rakefile +44 -0
  32. data/lib/facter/util/cfpropertylist/THANKS +7 -0
  33. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +6 -0
  34. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +562 -0
  35. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +26 -0
  36. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +402 -0
  37. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +244 -0
  38. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +135 -0
  39. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +140 -0
  40. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +136 -0
  41. data/lib/facter/util/collection.rb +36 -14
  42. data/lib/facter/util/composite_loader.rb +12 -0
  43. data/lib/facter/util/config.rb +36 -0
  44. data/lib/facter/util/confine.rb +1 -6
  45. data/lib/facter/util/directory_loader.rb +83 -0
  46. data/lib/facter/util/fact.rb +49 -42
  47. data/lib/facter/util/file_read.rb +32 -0
  48. data/lib/facter/util/ip.rb +2 -9
  49. data/lib/facter/util/loader.rb +16 -2
  50. data/lib/facter/util/macosx.rb +15 -2
  51. data/lib/facter/util/memory.rb +154 -27
  52. data/lib/facter/util/nothing_loader.rb +15 -0
  53. data/lib/facter/util/parser.rb +141 -0
  54. data/lib/facter/util/processor.rb +27 -35
  55. data/lib/facter/util/resolution.rb +97 -26
  56. data/lib/facter/util/solaris_zones.rb +153 -0
  57. data/lib/facter/util/virtual.rb +32 -3
  58. data/lib/facter/version.rb +72 -2
  59. data/lib/facter/virtual.rb +56 -3
  60. data/lib/facter/zfs_version.rb +10 -0
  61. data/lib/facter/zonename.rb +6 -0
  62. data/lib/facter/zones.rb +17 -0
  63. data/lib/facter/zpool_version.rb +10 -0
  64. data/spec/fixtures/ifconfig/ifconfig_net_tools_1.60.txt +19 -0
  65. data/spec/fixtures/ifconfig/ifconfig_ubuntu_1204.txt +16 -0
  66. data/spec/fixtures/ldom/ldom_v1 +6 -0
  67. data/spec/fixtures/unit/filesystems/linux +28 -0
  68. data/spec/fixtures/unit/util/manufacturer/intel_linux_dmidecode +549 -0
  69. data/spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt +0 -0
  70. data/spec/fixtures/unit/zfs_version/freebsd_8.2 +14 -0
  71. data/spec/fixtures/unit/zfs_version/freebsd_9.0 +13 -0
  72. data/spec/fixtures/unit/zfs_version/linux-fuse_0.6.9 +14 -0
  73. data/spec/fixtures/unit/zfs_version/solaris_10 +10 -0
  74. data/spec/fixtures/unit/zfs_version/solaris_11 +12 -0
  75. data/spec/fixtures/unit/zpool_version/freebsd_8.2 +26 -0
  76. data/spec/fixtures/unit/zpool_version/freebsd_9.0 +38 -0
  77. data/spec/fixtures/unit/zpool_version/linux-fuse_0.6.9 +35 -0
  78. data/spec/fixtures/unit/zpool_version/solaris_10 +31 -0
  79. data/spec/fixtures/unit/zpool_version/solaris_11 +43 -0
  80. data/spec/integration/facter_spec.rb +12 -0
  81. data/spec/spec_helper.rb +9 -0
  82. data/spec/unit/architecture_spec.rb +1 -1
  83. data/spec/unit/blockdevices_spec.rb +109 -0
  84. data/spec/unit/domain_spec.rb +189 -81
  85. data/spec/unit/ec2_spec.rb +15 -8
  86. data/spec/unit/filesystems_spec.rb +50 -0
  87. data/spec/unit/hardwaremodel_spec.rb +8 -1
  88. data/spec/unit/id_spec.rb +6 -5
  89. data/spec/unit/ipaddress6_spec.rb +14 -2
  90. data/spec/unit/ipaddress_spec.rb +1 -1
  91. data/spec/unit/kernel_spec.rb +24 -0
  92. data/spec/unit/kernelmajversion_spec.rb +17 -0
  93. data/spec/unit/kernelrelease_spec.rb +53 -0
  94. data/spec/unit/kernelversion_spec.rb +32 -0
  95. data/spec/unit/ldom_spec.rb +74 -0
  96. data/spec/unit/macaddress_spec.rb +3 -1
  97. data/spec/unit/manufacturer_spec.rb +115 -0
  98. data/spec/unit/memory_spec.rb +442 -75
  99. data/spec/unit/operatingsystem_spec.rb +16 -2
  100. data/spec/unit/operatingsystemmajrelease_spec.rb +16 -0
  101. data/spec/unit/operatingsystemrelease_spec.rb +110 -1
  102. data/spec/unit/processor_spec.rb +22 -7
  103. data/spec/unit/ps_spec.rb +42 -0
  104. data/spec/unit/ssh_spec.rb +76 -0
  105. data/spec/unit/util/collection_spec.rb +94 -118
  106. data/spec/unit/util/config_spec.rb +36 -5
  107. data/spec/unit/util/confine_spec.rb +31 -43
  108. data/spec/unit/util/directory_loader_spec.rb +87 -0
  109. data/spec/unit/util/fact_spec.rb +37 -25
  110. data/spec/unit/util/file_read_spec.rb +29 -0
  111. data/spec/unit/util/ip_spec.rb +4 -2
  112. data/spec/unit/util/loader_spec.rb +102 -45
  113. data/spec/unit/util/macosx_spec.rb +40 -9
  114. data/spec/unit/util/manufacturer_spec.rb +12 -1
  115. data/spec/unit/util/parser_spec.rb +135 -0
  116. data/spec/unit/util/resolution_spec.rb +136 -4
  117. data/spec/unit/util/solaris_zones_spec.rb +127 -0
  118. data/spec/unit/util/virtual_spec.rb +54 -0
  119. data/spec/unit/version_spec.rb +42 -0
  120. data/spec/unit/virtual_spec.rb +102 -27
  121. data/spec/unit/zfs_version_spec.rb +76 -0
  122. data/spec/unit/zonename_spec.rb +14 -0
  123. data/spec/unit/zones_spec.rb +55 -0
  124. data/spec/unit/zpool_version_spec.rb +76 -0
  125. metadata +113 -11
  126. data/lib/facter/arp.rb +0 -28
@@ -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
- if name = Facter::Util::Resolution.exec('hostname') \
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
- next domain if domain
47
- next search if search
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
@@ -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 'x64' # PROCESSOR_ARCHITECTURE_AMD64
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
@@ -39,8 +39,7 @@ Facter.add(:ipaddress6) do
39
39
  confine :kernel => :linux
40
40
  setcode do
41
41
  output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"])
42
-
43
- get_address_after_token(output, 'inet6 addr:')
42
+ get_address_after_token(output, 'inet6(?: addr:)?')
44
43
  end
45
44
  end
46
45
 
@@ -16,12 +16,20 @@ Facter.add(:kernelrelease) do
16
16
  end
17
17
 
18
18
  Facter.add(:kernelrelease) do
19
- confine :kernel => :aix
19
+ confine :kernel => "aix"
20
20
  setcode 'oslevel -s'
21
21
  end
22
22
 
23
23
  Facter.add(:kernelrelease) do
24
- confine :kernel => %{windows}
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 = ""
@@ -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
@@ -49,7 +49,7 @@ Facter.add(:macaddress) do
49
49
  end
50
50
 
51
51
  Facter.add(:macaddress) do
52
- confine :operatingsystem => "Solaris"
52
+ confine :osfamily => "Solaris"
53
53
  setcode do
54
54
  ether = []
55
55
  output = Facter::Util::Resolution.exec("/usr/bin/netstat -np")
@@ -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' }
@@ -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
- { :MemorySize => "MemTotal",
28
- :MemoryFree => "MemFree",
29
- :SwapSize => "SwapTotal",
30
- :SwapFree => "SwapFree"
31
- }.each do |fact, name|
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::Memory.meminfo_number(name)
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("SwapSize") do
41
- confine :kernel => :Darwin
43
+ Facter.add("swapsize_mb") do
42
44
  setcode do
43
- swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
44
- swaptotal = 0
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("SwapFree") do
51
- confine :kernel => :Darwin
50
+ Facter.add("swapfree_mb") do
52
51
  setcode do
53
- swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
54
- swapfree = 0
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("SwapEncrypted") do
61
- confine :kernel => :Darwin
57
+ Facter.add("memorysize_mb") do
62
58
  setcode do
63
- swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
64
- encrypted = false
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
- 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
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
- if Facter.value(:kernel) == "OpenBSD"
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
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.scale_number(memtotal.to_f,"")
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
- 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
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::Memory.scale_number(swapfree.to_f,"MB")
151
- end
152
- end
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("SwapSize") do
99
+ Facter.add("memorysize_mb") do
176
100
  confine :kernel => :sunos
177
- setcode do
178
- Facter::Memory.scale_number(swaptotal.to_f,"kB")
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
- Facter::Memory.scale_number(swapfree.to_f,"kB")
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("MemoryFree") do
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 FreePhysicalMemory from Win32_OperatingSystem").each do |os|
216
- mem = os.FreePhysicalMemory
122
+ Facter::Util::WMI.execquery("select TotalPhysicalMemory from Win32_ComputerSystem").each do |comp|
123
+ mem = comp.TotalPhysicalMemory
217
124
  break
218
125
  end
219
- Facter::Memory.scale_number(mem.to_f, "kB")
126
+ "%.2f" % [(mem.to_f / 1024.0) / 1024.0]
220
127
  end
221
128
  end
222
129
 
223
- Facter.add("memorysize") do
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 TotalPhysicalMemory from Win32_ComputerSystem").each do |comp|
228
- mem = comp.TotalPhysicalMemory
134
+ Facter::Util::WMI.execquery("select FreePhysicalMemory from Win32_OperatingSystem").each do |os|
135
+ mem = os.FreePhysicalMemory
229
136
  break
230
137
  end
231
- Facter::Memory.scale_number(mem.to_f, "")
138
+ "%.2f" % [mem.to_f / 1024.0]
232
139
  end
233
140
  end
234
141
  end
235
142
 
236
- Facter.add("SwapSize") do
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
- Facter::Memory.scale_number(swaptotal.to_f,"")
148
+ "%.2f" % [(swaptotal.to_f / 1024.0) / 1024.0]
242
149
  end
243
150
  end
244
151
 
245
- Facter.add("SwapFree") do
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
- Facter::Memory.scale_number(swapfree.to_f,"")
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