ohai 8.10.0 → 8.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (256) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -2
  3. data/Rakefile +13 -4
  4. data/bin/ohai +3 -4
  5. data/lib/ohai.rb +4 -4
  6. data/lib/ohai/application.rb +7 -6
  7. data/lib/ohai/common/dmi.rb +56 -56
  8. data/lib/ohai/config.rb +12 -8
  9. data/lib/ohai/dsl.rb +3 -3
  10. data/lib/ohai/dsl/plugin.rb +5 -5
  11. data/lib/ohai/dsl/plugin/versionvi.rb +0 -1
  12. data/lib/ohai/dsl/plugin/versionvii.rb +1 -0
  13. data/lib/ohai/hints.rb +1 -1
  14. data/lib/ohai/loader.rb +7 -7
  15. data/lib/ohai/log.rb +1 -1
  16. data/lib/ohai/mash.rb +3 -2
  17. data/lib/ohai/mixin/command.rb +25 -23
  18. data/lib/ohai/mixin/dmi_decode.rb +10 -10
  19. data/lib/ohai/mixin/ec2_metadata.rb +40 -39
  20. data/lib/ohai/mixin/gce_metadata.rb +9 -9
  21. data/lib/ohai/mixin/network_constants.rb +1 -1
  22. data/lib/ohai/mixin/os.rb +3 -3
  23. data/lib/ohai/mixin/seconds_to_human.rb +0 -2
  24. data/lib/ohai/mixin/softlayer_metadata.rb +10 -10
  25. data/lib/ohai/mixin/string.rb +2 -2
  26. data/lib/ohai/plugin_config.rb +1 -1
  27. data/lib/ohai/plugins/aix/cpu.rb +2 -2
  28. data/lib/ohai/plugins/aix/filesystem.rb +2 -2
  29. data/lib/ohai/plugins/aix/memory.rb +2 -2
  30. data/lib/ohai/plugins/aix/network.rb +9 -10
  31. data/lib/ohai/plugins/aix/os.rb +2 -2
  32. data/lib/ohai/plugins/aix/uptime.rb +3 -3
  33. data/lib/ohai/plugins/aix/virtualization.rb +23 -23
  34. data/lib/ohai/plugins/azure.rb +32 -5
  35. data/lib/ohai/plugins/bsd/virtualization.rb +22 -22
  36. data/lib/ohai/plugins/c.rb +3 -3
  37. data/lib/ohai/plugins/chef.rb +1 -1
  38. data/lib/ohai/plugins/cloud.rb +59 -60
  39. data/lib/ohai/plugins/cloud_v2.rb +37 -39
  40. data/lib/ohai/plugins/darwin/cpu.rb +1 -1
  41. data/lib/ohai/plugins/darwin/filesystem2.rb +5 -5
  42. data/lib/ohai/plugins/darwin/memory.rb +5 -6
  43. data/lib/ohai/plugins/darwin/network.rb +7 -7
  44. data/lib/ohai/plugins/darwin/system_profiler.rb +32 -33
  45. data/lib/ohai/plugins/darwin/virtualization.rb +9 -9
  46. data/lib/ohai/plugins/digital_ocean.rb +16 -16
  47. data/lib/ohai/plugins/dmi.rb +6 -6
  48. data/lib/ohai/plugins/dragonflybsd/cpu.rb +2 -2
  49. data/lib/ohai/plugins/dragonflybsd/memory.rb +0 -1
  50. data/lib/ohai/plugins/dragonflybsd/network.rb +4 -4
  51. data/lib/ohai/plugins/dragonflybsd/os.rb +1 -1
  52. data/lib/ohai/plugins/ec2.rb +39 -15
  53. data/lib/ohai/plugins/elixir.rb +1 -1
  54. data/lib/ohai/plugins/erlang.rb +3 -3
  55. data/lib/ohai/plugins/eucalyptus.rb +16 -12
  56. data/lib/ohai/plugins/freebsd/cpu.rb +2 -2
  57. data/lib/ohai/plugins/freebsd/memory.rb +0 -1
  58. data/lib/ohai/plugins/freebsd/network.rb +4 -4
  59. data/lib/ohai/plugins/freebsd/os.rb +1 -1
  60. data/lib/ohai/plugins/gce.rb +6 -6
  61. data/lib/ohai/plugins/hostname.rb +7 -7
  62. data/lib/ohai/plugins/init_package.rb +1 -1
  63. data/lib/ohai/plugins/ip_scopes.rb +9 -9
  64. data/lib/ohai/plugins/java.rb +1 -1
  65. data/lib/ohai/plugins/joyent.rb +7 -7
  66. data/lib/ohai/plugins/kernel.rb +8 -8
  67. data/lib/ohai/plugins/linode.rb +7 -4
  68. data/lib/ohai/plugins/linux/cpu.rb +5 -5
  69. data/lib/ohai/plugins/linux/filesystem.rb +16 -16
  70. data/lib/ohai/plugins/linux/filesystem2.rb +15 -15
  71. data/lib/ohai/plugins/linux/mdadm.rb +3 -3
  72. data/lib/ohai/plugins/linux/network.rb +85 -51
  73. data/lib/ohai/plugins/linux/platform.rb +24 -24
  74. data/lib/ohai/plugins/linux/virtualization.rb +8 -8
  75. data/lib/ohai/plugins/mono.rb +1 -1
  76. data/lib/ohai/plugins/netbsd/cpu.rb +1 -1
  77. data/lib/ohai/plugins/netbsd/network.rb +2 -2
  78. data/lib/ohai/plugins/network.rb +11 -11
  79. data/lib/ohai/plugins/network_listeners.rb +30 -26
  80. data/lib/ohai/plugins/ohai.rb +3 -3
  81. data/lib/ohai/plugins/openbsd/cpu.rb +4 -4
  82. data/lib/ohai/plugins/openbsd/memory.rb +4 -4
  83. data/lib/ohai/plugins/openbsd/network.rb +3 -3
  84. data/lib/ohai/plugins/openstack.rb +12 -12
  85. data/lib/ohai/plugins/os.rb +2 -2
  86. data/lib/ohai/plugins/packages.rb +22 -22
  87. data/lib/ohai/plugins/passwd.rb +4 -4
  88. data/lib/ohai/plugins/powershell.rb +9 -9
  89. data/lib/ohai/plugins/ps.rb +2 -2
  90. data/lib/ohai/plugins/python.rb +1 -1
  91. data/lib/ohai/plugins/rackspace.rb +13 -13
  92. data/lib/ohai/plugins/root_group.rb +4 -4
  93. data/lib/ohai/plugins/ruby.rb +6 -6
  94. data/lib/ohai/plugins/rust.rb +1 -1
  95. data/lib/ohai/plugins/sigar/cpu.rb +1 -1
  96. data/lib/ohai/plugins/sigar/filesystem.rb +1 -1
  97. data/lib/ohai/plugins/sigar/network.rb +13 -13
  98. data/lib/ohai/plugins/sigar/network_route.rb +34 -29
  99. data/lib/ohai/plugins/softlayer.rb +8 -7
  100. data/lib/ohai/plugins/solaris2/cpu.rb +19 -19
  101. data/lib/ohai/plugins/solaris2/dmi.rb +63 -63
  102. data/lib/ohai/plugins/solaris2/filesystem.rb +13 -13
  103. data/lib/ohai/plugins/solaris2/memory.rb +2 -2
  104. data/lib/ohai/plugins/solaris2/network.rb +5 -5
  105. data/lib/ohai/plugins/solaris2/virtualization.rb +18 -18
  106. data/lib/ohai/plugins/solaris2/zpools.rb +1 -1
  107. data/lib/ohai/plugins/ssh_host_key.rb +2 -2
  108. data/lib/ohai/plugins/uptime.rb +4 -5
  109. data/lib/ohai/plugins/virtualbox.rb +2 -2
  110. data/lib/ohai/plugins/virtualization.rb +17 -17
  111. data/lib/ohai/plugins/vmware.rb +2 -2
  112. data/lib/ohai/plugins/windows/cpu.rb +14 -14
  113. data/lib/ohai/plugins/windows/drivers.rb +8 -8
  114. data/lib/ohai/plugins/windows/filesystem.rb +4 -4
  115. data/lib/ohai/plugins/windows/memory.rb +1 -1
  116. data/lib/ohai/plugins/windows/network.rb +10 -10
  117. data/lib/ohai/plugins/windows/platform.rb +1 -2
  118. data/lib/ohai/plugins/windows/virtualization.rb +17 -17
  119. data/lib/ohai/provides_map.rb +7 -7
  120. data/lib/ohai/runner.rb +3 -3
  121. data/lib/ohai/system.rb +21 -20
  122. data/lib/ohai/util/file_helper.rb +1 -2
  123. data/lib/ohai/util/ip_helper.rb +4 -4
  124. data/lib/ohai/util/win32.rb +5 -5
  125. data/lib/ohai/util/win32/group_helper.rb +4 -5
  126. data/lib/ohai/version.rb +1 -1
  127. data/ohai.gemspec +7 -5
  128. data/spec/functional/application_spec.rb +23 -23
  129. data/spec/functional/loader_spec.rb +1 -1
  130. data/spec/functional/plugins/powershell_spec.rb +13 -13
  131. data/spec/functional/plugins/root_group_spec.rb +5 -5
  132. data/spec/ohai_spec.rb +1 -1
  133. data/spec/spec_helper.rb +9 -9
  134. data/spec/support/integration_helper.rb +7 -7
  135. data/spec/support/platform_helpers.rb +1 -1
  136. data/spec/unit/application_spec.rb +17 -17
  137. data/spec/unit/config_spec.rb +2 -2
  138. data/spec/unit/dsl/plugin_spec.rb +28 -28
  139. data/spec/unit/hints_spec.rb +3 -3
  140. data/spec/unit/loader_spec.rb +9 -9
  141. data/spec/unit/mixin/command_spec.rb +5 -5
  142. data/spec/unit/mixin/ec2_metadata_spec.rb +6 -6
  143. data/spec/unit/mixin/softlayer_metadata_spec.rb +19 -23
  144. data/spec/unit/plugin_config_spec.rb +5 -5
  145. data/spec/unit/plugins/abort_spec.rb +3 -3
  146. data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
  147. data/spec/unit/plugins/aix/filesystem_spec.rb +25 -25
  148. data/spec/unit/plugins/aix/hostname_spec.rb +1 -2
  149. data/spec/unit/plugins/aix/kernel_spec.rb +3 -3
  150. data/spec/unit/plugins/aix/memory_spec.rb +8 -8
  151. data/spec/unit/plugins/aix/network_spec.rb +38 -38
  152. data/spec/unit/plugins/aix/os_spec.rb +1 -2
  153. data/spec/unit/plugins/aix/platform_spec.rb +1 -1
  154. data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
  155. data/spec/unit/plugins/aix/virtualization_spec.rb +11 -11
  156. data/spec/unit/plugins/azure_spec.rb +118 -20
  157. data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
  158. data/spec/unit/plugins/bsd/virtualization_spec.rb +4 -4
  159. data/spec/unit/plugins/c_spec.rb +12 -12
  160. data/spec/unit/plugins/chef_spec.rb +2 -2
  161. data/spec/unit/plugins/cloud_spec.rb +37 -37
  162. data/spec/unit/plugins/cloud_v2_spec.rb +64 -65
  163. data/spec/unit/plugins/darwin/cpu_spec.rb +1 -2
  164. data/spec/unit/plugins/darwin/filesystem2_spec.rb +7 -7
  165. data/spec/unit/plugins/darwin/filesystem_spec.rb +5 -5
  166. data/spec/unit/plugins/darwin/hostname_spec.rb +1 -4
  167. data/spec/unit/plugins/darwin/kernel_spec.rb +6 -10
  168. data/spec/unit/plugins/darwin/memory_spec.rb +5 -5
  169. data/spec/unit/plugins/darwin/network_spec.rb +352 -353
  170. data/spec/unit/plugins/darwin/platform_spec.rb +1 -2
  171. data/spec/unit/plugins/darwin/system_profiler_spec.rb +3 -3
  172. data/spec/unit/plugins/darwin/virtualization_spec.rb +6 -6
  173. data/spec/unit/plugins/digital_ocean_spec.rb +38 -37
  174. data/spec/unit/plugins/dmi_spec.rb +3 -3
  175. data/spec/unit/plugins/ec2_spec.rb +97 -88
  176. data/spec/unit/plugins/elixir_spec.rb +1 -2
  177. data/spec/unit/plugins/erlang_spec.rb +2 -2
  178. data/spec/unit/plugins/eucalyptus_spec.rb +19 -19
  179. data/spec/unit/plugins/fail_spec.rb +2 -2
  180. data/spec/unit/plugins/freebsd/cpu_spec.rb +14 -14
  181. data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -2
  182. data/spec/unit/plugins/freebsd/kernel_spec.rb +2 -3
  183. data/spec/unit/plugins/freebsd/os_spec.rb +4 -5
  184. data/spec/unit/plugins/freebsd/platform_spec.rb +1 -2
  185. data/spec/unit/plugins/gce_spec.rb +9 -9
  186. data/spec/unit/plugins/go_spec.rb +1 -1
  187. data/spec/unit/plugins/groovy_spec.rb +1 -2
  188. data/spec/unit/plugins/hostname_spec.rb +1 -2
  189. data/spec/unit/plugins/init_package_spec.rb +1 -1
  190. data/spec/unit/plugins/ip_scopes_spec.rb +38 -38
  191. data/spec/unit/plugins/java_spec.rb +52 -1
  192. data/spec/unit/plugins/joyent_spec.rb +9 -11
  193. data/spec/unit/plugins/kernel_spec.rb +11 -12
  194. data/spec/unit/plugins/linode_spec.rb +29 -29
  195. data/spec/unit/plugins/linux/block_device_spec.rb +21 -21
  196. data/spec/unit/plugins/linux/cpu_spec.rb +3 -3
  197. data/spec/unit/plugins/linux/filesystem2_spec.rb +7 -7
  198. data/spec/unit/plugins/linux/filesystem_spec.rb +85 -86
  199. data/spec/unit/plugins/linux/hostname_spec.rb +1 -3
  200. data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
  201. data/spec/unit/plugins/linux/lsb_spec.rb +1 -2
  202. data/spec/unit/plugins/linux/mdadm_spec.rb +4 -4
  203. data/spec/unit/plugins/linux/memory_spec.rb +29 -33
  204. data/spec/unit/plugins/linux/network_spec.rb +463 -245
  205. data/spec/unit/plugins/linux/platform_spec.rb +64 -65
  206. data/spec/unit/plugins/linux/uptime_spec.rb +1 -2
  207. data/spec/unit/plugins/linux/virtualization_spec.rb +42 -42
  208. data/spec/unit/plugins/lua_spec.rb +1 -2
  209. data/spec/unit/plugins/mono_spec.rb +1 -2
  210. data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -2
  211. data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -2
  212. data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
  213. data/spec/unit/plugins/network_spec.rb +118 -118
  214. data/spec/unit/plugins/nodejs_spec.rb +1 -1
  215. data/spec/unit/plugins/ohai_spec.rb +1 -1
  216. data/spec/unit/plugins/ohai_time_spec.rb +1 -2
  217. data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -2
  218. data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -2
  219. data/spec/unit/plugins/openbsd/platform_spec.rb +1 -2
  220. data/spec/unit/plugins/openstack_spec.rb +35 -37
  221. data/spec/unit/plugins/os_spec.rb +7 -8
  222. data/spec/unit/plugins/packages_spec.rb +118 -118
  223. data/spec/unit/plugins/passwd_spec.rb +18 -18
  224. data/spec/unit/plugins/perl_spec.rb +1 -1
  225. data/spec/unit/plugins/php_spec.rb +4 -4
  226. data/spec/unit/plugins/platform_spec.rb +8 -9
  227. data/spec/unit/plugins/powershell_spec.rb +3 -3
  228. data/spec/unit/plugins/python_spec.rb +1 -1
  229. data/spec/unit/plugins/rackspace_spec.rb +66 -68
  230. data/spec/unit/plugins/root_group_spec.rb +26 -26
  231. data/spec/unit/plugins/ruby_spec.rb +14 -15
  232. data/spec/unit/plugins/rust_spec.rb +2 -2
  233. data/spec/unit/plugins/sigar/network_route_spec.rb +36 -36
  234. data/spec/unit/plugins/softlayer_spec.rb +10 -10
  235. data/spec/unit/plugins/solaris2/cpu_spec.rb +20 -21
  236. data/spec/unit/plugins/solaris2/dmi_spec.rb +5 -6
  237. data/spec/unit/plugins/solaris2/filesystem.rb +5 -5
  238. data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
  239. data/spec/unit/plugins/solaris2/kernel_spec.rb +3 -3
  240. data/spec/unit/plugins/solaris2/memory_spec.rb +5 -5
  241. data/spec/unit/plugins/solaris2/network_spec.rb +7 -8
  242. data/spec/unit/plugins/solaris2/platform_spec.rb +1 -1
  243. data/spec/unit/plugins/solaris2/virtualization_spec.rb +3 -5
  244. data/spec/unit/plugins/solaris2/zpools_spec.rb +6 -6
  245. data/spec/unit/plugins/ssh_host_keys_spec.rb +1 -1
  246. data/spec/unit/plugins/virtualbox_spec.rb +19 -19
  247. data/spec/unit/plugins/vmware_spec.rb +28 -28
  248. data/spec/unit/plugins/windows/cpu_spec.rb +46 -48
  249. data/spec/unit/plugins/windows/memory_spec.rb +5 -5
  250. data/spec/unit/plugins/windows/virtualization_spec.rb +163 -163
  251. data/spec/unit/provides_map_spec.rb +10 -10
  252. data/spec/unit/runner_spec.rb +10 -10
  253. data/spec/unit/system_spec.rb +19 -19
  254. data/spec/unit/util/file_helper_spec.rb +5 -6
  255. data/spec/unit/util/ip_helper_spec.rb +39 -39
  256. metadata +31 -4
@@ -20,6 +20,6 @@ Ohai.plugin(:InitPackage) do
20
20
  provides "init_package"
21
21
 
22
22
  collect_data(:linux) do
23
- init_package File.exists?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : 'init'
23
+ init_package File.exists?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : "init"
24
24
  end
25
25
  end
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,15 +22,15 @@ Ohai.plugin(:IpScopes) do
22
22
 
23
23
  collect_data do
24
24
  begin
25
- require 'ipaddr_extensions'
25
+ require "ipaddr_extensions"
26
26
 
27
- network['interfaces'].keys.sort.each do |ifName|
28
- next if network['interfaces'][ifName]['addresses'].nil?
27
+ network["interfaces"].keys.sort.each do |ifName|
28
+ next if network["interfaces"][ifName]["addresses"].nil?
29
29
 
30
- interface = network['interfaces'][ifName]
31
- interface['addresses'].each do |address,attrs|
30
+ interface = network["interfaces"][ifName]
31
+ interface["addresses"].each do |address, attrs|
32
32
  begin
33
- attrs.merge! 'ip_scope' => address.to_ip.scope
33
+ attrs.merge! "ip_scope" => address.to_ip.scope
34
34
 
35
35
  if private_addr?(address) && !tunnel_iface?(interface)
36
36
  privateaddress(address)
@@ -52,6 +52,6 @@ Ohai.plugin(:IpScopes) do
52
52
  end
53
53
 
54
54
  def tunnel_iface?(interface)
55
- interface['type'] == 'ppp'
55
+ interface["type"] == "ppp"
56
56
  end
57
57
  end
@@ -26,7 +26,7 @@ Ohai.plugin(:Java) do
26
26
  if so.exitstatus == 0
27
27
  so.stderr.split(/\r?\n/).each do |line|
28
28
  case line
29
- when /java version \"([0-9\.\_]+)\"/
29
+ when /(?:java|openjdk) version \"([0-9\.\_]+)\"/
30
30
  java[:version] = $1
31
31
  when /^(.+Runtime Environment.*) \((build)\s*(.+)\)$/
32
32
  java[:runtime] = { "name" => $1, "build" => $3 }
@@ -20,9 +20,9 @@
20
20
  # Reference from: sm-summary command
21
21
 
22
22
  Ohai.plugin(:Joyent) do
23
- provides 'joyent'
24
- provides 'virtualization/guest_id'
25
- depends 'os', 'platform', 'virtualization'
23
+ provides "joyent"
24
+ provides "virtualization/guest_id"
25
+ depends "os", "platform", "virtualization"
26
26
 
27
27
  def collect_product_file
28
28
  lines = []
@@ -37,7 +37,7 @@ Ohai.plugin(:Joyent) do
37
37
  end
38
38
 
39
39
  def collect_pkgsrc
40
- if File.exist?('/opt/local/etc/pkg_install.conf')
40
+ if File.exist?("/opt/local/etc/pkg_install.conf")
41
41
  sm_pkgsrc = ::File.read("/opt/local/etc/pkg_install.conf").split("=")
42
42
  sm_pkgsrc[1].chomp
43
43
  else
@@ -46,7 +46,7 @@ Ohai.plugin(:Joyent) do
46
46
  end
47
47
 
48
48
  def is_smartos?
49
- platform == 'smartos'
49
+ platform == "smartos"
50
50
  end
51
51
 
52
52
  collect_data do
@@ -58,14 +58,14 @@ Ohai.plugin(:Joyent) do
58
58
 
59
59
  # get zone id unless globalzone
60
60
  unless joyent[:sm_uuid] == "global"
61
- joyent[:sm_id] = virtualization[:guest_id]
61
+ joyent[:sm_id] = virtualization[:guest_id]
62
62
  end
63
63
 
64
64
  # retrieve image name and pkgsrc
65
65
  collect_product_file.each do |line|
66
66
  case line
67
67
  when /^Image/
68
- sm_image = line.split(" ")
68
+ sm_image = line.split(" ")
69
69
  joyent[:sm_image_id] = sm_image[1]
70
70
  joyent[:sm_image_ver] = sm_image[2]
71
71
  when /^Base Image/
@@ -80,7 +80,7 @@ Ohai.plugin(:Kernel) do
80
80
 
81
81
  so = shell_out("sysctl -n hw.optional.x86_64")
82
82
  if so.stdout.split($/)[0].to_i == 1
83
- kernel[:machine] = 'x86_64'
83
+ kernel[:machine] = "x86_64"
84
84
  end
85
85
 
86
86
  modules = Mash.new
@@ -157,10 +157,10 @@ Ohai.plugin(:Kernel) do
157
157
  # EXAMPLE:
158
158
  # Id Loadaddr Size Info Rev Module Name
159
159
  # 6 1180000 4623 1 1 specfs (filesystem for specfs)
160
- module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
160
+ module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
161
161
  so.stdout.lines do |line|
162
162
  if mod = module_description.match(line)
163
- modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]}
163
+ modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5] }
164
164
  end
165
165
  end
166
166
 
@@ -168,8 +168,8 @@ Ohai.plugin(:Kernel) do
168
168
  end
169
169
 
170
170
  collect_data(:windows) do
171
- require 'win32ole'
172
- require 'wmi-lite/wmi'
171
+ require "win32ole"
172
+ require "wmi-lite/wmi"
173
173
 
174
174
  WIN32OLE.codepage = WIN32OLE::CP_UTF8
175
175
 
@@ -177,7 +177,7 @@ Ohai.plugin(:Kernel) do
177
177
 
178
178
  kernel Mash.new
179
179
 
180
- host = wmi.first_of('Win32_OperatingSystem')
180
+ host = wmi.first_of("Win32_OperatingSystem")
181
181
  kernel[:os_info] = Mash.new
182
182
  host.wmi_ole_object.properties_.each do |p|
183
183
  kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
@@ -188,10 +188,10 @@ Ohai.plugin(:Kernel) do
188
188
  kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
189
189
  kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
190
190
 
191
- host = wmi.first_of('Win32_ComputerSystem')
191
+ host = wmi.first_of("Win32_ComputerSystem")
192
192
  kernel[:cs_info] = Mash.new
193
193
  cs_info_blacklist = [
194
- 'oem_logo_bitmap'
194
+ "oem_logo_bitmap"
195
195
  ]
196
196
  host.wmi_ole_object.properties_.each do |p|
197
197
  if !cs_info_blacklist.include?(p.name.wmi_underscore)
@@ -25,7 +25,7 @@ Ohai.plugin(:Linode) do
25
25
  # Returns true or false
26
26
  def has_linode_kernel?
27
27
  if kernel_data = kernel
28
- kernel_data[:release].split('-').last =~ /linode/
28
+ kernel_data[:release].split("-").last =~ /linode/
29
29
  end
30
30
  end
31
31
 
@@ -33,7 +33,7 @@ Ohai.plugin(:Linode) do
33
33
  #
34
34
  # Returns true or false
35
35
  def looks_like_linode?
36
- hint?('linode') || has_linode_kernel?
36
+ hint?("linode") || has_linode_kernel?
37
37
  end
38
38
 
39
39
  # Names linode ip address
@@ -45,7 +45,7 @@ Ohai.plugin(:Linode) do
45
45
  def get_ip_address(name, eth)
46
46
  if eth_iface = network[:interfaces][eth]
47
47
  eth_iface[:addresses].each do |key, info|
48
- linode[name] = key if info['family'] == 'inet'
48
+ linode[name] = key if info["family"] == "inet"
49
49
  end
50
50
  end
51
51
  end
@@ -53,10 +53,13 @@ Ohai.plugin(:Linode) do
53
53
  collect_data do
54
54
  # Setup linode mash if it is a linode system
55
55
  if looks_like_linode?
56
+ Ohai::Log.debug("linode plugin: looks_like_linode? == true")
56
57
  linode Mash.new
57
58
  get_ip_address(:public_ip, :eth0)
58
59
  get_ip_address(:private_ip, "eth0:1")
59
- hint?('linode').each{|k,v| linode[k] = v } if hint?('linode').kind_of?(Hash)
60
+ hint?("linode").each { |k, v| linode[k] = v } if hint?("linode").kind_of?(Hash)
61
+ else
62
+ Ohai::Log.debug("linode plugin: looks_like_linode? == false")
60
63
  end
61
64
  end
62
65
  end
@@ -58,18 +58,18 @@ Ohai.plugin(:CPU) do
58
58
  when /cache size\s+:\s(.+)/
59
59
  cpuinfo[current_cpu]["cache_size"] = $1
60
60
  when /flags\s+:\s(.+)/
61
- cpuinfo[current_cpu]["flags"] = $1.split(' ')
61
+ cpuinfo[current_cpu]["flags"] = $1.split(" ")
62
62
  when /bogomips per cpu:\s(.+)/
63
63
  cpuinfo["bogomips_per_cpu"] = $1
64
64
  when /features\s+:\s(.+)/
65
- cpuinfo["features"] = $1.split(' ')
65
+ cpuinfo["features"] = $1.split(" ")
66
66
  when /processor\s(\d):\s(.+)/
67
67
  current_cpu = $1
68
68
  cpu_number += 1
69
69
  cpuinfo[current_cpu] = Mash.new
70
- current_cpu_info = $2.split(',')
71
- for i in current_cpu_info
72
- name_value = i.split('=')
70
+ current_cpu_info = $2.split(",")
71
+ current_cpu_info.each do |i|
72
+ name_value = i.split("=")
73
73
  name = name_value[0].strip
74
74
  value = name_value[1].strip
75
75
  cpuinfo[current_cpu][name] = value
@@ -21,7 +21,7 @@ Ohai.plugin(:Filesystem) do
21
21
 
22
22
  def get_blk_cmd(attr, have_lsblk)
23
23
  if have_lsblk
24
- attr = 'FSTYPE' if attr == 'TYPE'
24
+ attr = "FSTYPE" if attr == "TYPE"
25
25
  "lsblk -P -n -o NAME,#{attr}"
26
26
  else
27
27
  "blkid -s #{attr}"
@@ -30,7 +30,7 @@ Ohai.plugin(:Filesystem) do
30
30
 
31
31
  def get_blk_regex(attr, have_lsblk)
32
32
  if have_lsblk
33
- attr = 'FSTYPE' if attr == 'TYPE'
33
+ attr = "FSTYPE" if attr == "TYPE"
34
34
  /^NAME="(\S+).*?" #{attr}="(\S+)"/
35
35
  else
36
36
  /^(\S+): #{attr}="(\S+)"/
@@ -47,7 +47,7 @@ Ohai.plugin(:Filesystem) do
47
47
 
48
48
  collect_data(:linux) do
49
49
  fs = Mash.new
50
- have_lsblk = File.executable?('/bin/lsblk')
50
+ have_lsblk = File.executable?("/bin/lsblk")
51
51
 
52
52
  # Grab filesystem data from df
53
53
  so = shell_out("df -P")
@@ -95,56 +95,56 @@ Ohai.plugin(:Filesystem) do
95
95
  end
96
96
  end
97
97
 
98
- have_lsblk = File.exist?('/bin/lsblk')
98
+ have_lsblk = File.exist?("/bin/lsblk")
99
99
 
100
100
  # Gather more filesystem types via libuuid, even devices that's aren't mounted
101
- cmd = get_blk_cmd('TYPE', have_lsblk)
102
- regex = get_blk_regex('TYPE', have_lsblk)
101
+ cmd = get_blk_cmd("TYPE", have_lsblk)
102
+ regex = get_blk_regex("TYPE", have_lsblk)
103
103
  so = shell_out(cmd)
104
104
  so.stdout.lines do |line|
105
105
  if line =~ regex
106
106
  filesystem = $1
107
107
  type = $2
108
- filesystem = find_device(filesystem) unless filesystem.start_with?('/')
108
+ filesystem = find_device(filesystem) unless filesystem.start_with?("/")
109
109
  fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
110
110
  fs[filesystem][:fs_type] = type
111
111
  end
112
112
  end
113
113
 
114
114
  # Gather device UUIDs via libuuid
115
- cmd = get_blk_cmd('UUID', have_lsblk)
116
- regex = get_blk_regex('UUID', have_lsblk)
115
+ cmd = get_blk_cmd("UUID", have_lsblk)
116
+ regex = get_blk_regex("UUID", have_lsblk)
117
117
  so = shell_out(cmd)
118
118
  so.stdout.lines do |line|
119
119
  if line =~ regex
120
120
  filesystem = $1
121
121
  uuid = $2
122
- filesystem = find_device(filesystem) unless filesystem.start_with?('/')
122
+ filesystem = find_device(filesystem) unless filesystem.start_with?("/")
123
123
  fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
124
124
  fs[filesystem][:uuid] = uuid
125
125
  end
126
126
  end
127
127
 
128
128
  # Gather device labels via libuuid
129
- cmd = get_blk_cmd('LABEL', have_lsblk)
130
- regex = get_blk_regex('LABEL', have_lsblk)
129
+ cmd = get_blk_cmd("LABEL", have_lsblk)
130
+ regex = get_blk_regex("LABEL", have_lsblk)
131
131
  so = shell_out(cmd)
132
132
  so.stdout.lines do |line|
133
133
  if line =~ regex
134
134
  filesystem = $1
135
135
  label = $2
136
- filesystem = find_device(filesystem) unless filesystem.start_with?('/')
136
+ filesystem = find_device(filesystem) unless filesystem.start_with?("/")
137
137
  fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
138
138
  fs[filesystem][:label] = label
139
139
  end
140
140
  end
141
141
 
142
142
  # Grab any missing mount information from /proc/mounts
143
- if File.exist?('/proc/mounts')
144
- mounts = ''
143
+ if File.exist?("/proc/mounts")
144
+ mounts = ""
145
145
  # Due to https://tickets.opscode.com/browse/OHAI-196
146
146
  # we have to non-block read dev files. Ew.
147
- f = File.open('/proc/mounts')
147
+ f = File.open("/proc/mounts")
148
148
  loop do
149
149
  begin
150
150
  data = f.read_nonblock(4096)
@@ -34,16 +34,16 @@ Ohai.plugin(:Filesystem2) do
34
34
  regex = /NAME="(\S+).*?" UUID="(\S*)" LABEL="(\S*)" FSTYPE="(\S*)"/
35
35
  if line =~ regex
36
36
  dev = $1
37
- dev = find_device(dev) unless dev.start_with?('/')
37
+ dev = find_device(dev) unless dev.start_with?("/")
38
38
  uuid = $2
39
39
  label = $3
40
40
  fs_type = $4
41
- return {:dev => dev, :uuid => uuid, :label => label, :fs_type => fs_type}
41
+ return { :dev => dev, :uuid => uuid, :label => label, :fs_type => fs_type }
42
42
  end
43
43
  else
44
44
  bits = line.split
45
- dev = bits.shift.split(':')[0]
46
- f = {:dev => dev}
45
+ dev = bits.shift.split(":")[0]
46
+ f = { :dev => dev }
47
47
  bits.each do |keyval|
48
48
  if keyval =~ /(\S+)="(\S+)"/
49
49
  key = $1.downcase.to_sym
@@ -61,7 +61,7 @@ Ohai.plugin(:Filesystem2) do
61
61
  fs.each_value do |entry|
62
62
  view[entry[:device]] = Mash.new unless view[entry[:device]]
63
63
  entry.each do |key, val|
64
- next if ['device', 'mount'].include?(key)
64
+ next if %w{device mount}.include?(key)
65
65
  view[entry[:device]][key] = val
66
66
  end
67
67
  view[entry[:device]][:mounts] ||= []
@@ -78,7 +78,7 @@ Ohai.plugin(:Filesystem2) do
78
78
  next unless entry[:mount]
79
79
  view[entry[:mount]] = Mash.new unless view[entry[:mount]]
80
80
  entry.each do |key, val|
81
- next if ['mount', 'device'].include?(key)
81
+ next if %w{mount device}.include?(key)
82
82
  view[entry[:mount]][key] = val
83
83
  end
84
84
  view[entry[:mount]][:devices] ||= []
@@ -141,12 +141,12 @@ Ohai.plugin(:Filesystem2) do
141
141
  end
142
142
  end
143
143
 
144
- have_lsblk = File.exist?('/bin/lsblk')
144
+ have_lsblk = File.exist?("/bin/lsblk")
145
145
  if have_lsblk
146
- cmd = 'lsblk -n -P -o NAME,UUID,LABEL,FSTYPE'
146
+ cmd = "lsblk -n -P -o NAME,UUID,LABEL,FSTYPE"
147
147
  else
148
148
  # CentOS5 and other platforms don't have lsblk
149
- cmd = 'blkid'
149
+ cmd = "blkid"
150
150
  end
151
151
 
152
152
  so = shell_out(cmd)
@@ -177,11 +177,11 @@ Ohai.plugin(:Filesystem2) do
177
177
  end
178
178
 
179
179
  # Grab any missing mount information from /proc/mounts
180
- if File.exist?('/proc/mounts')
181
- mounts = ''
180
+ if File.exist?("/proc/mounts")
181
+ mounts = ""
182
182
  # Due to https://tickets.opscode.com/browse/OHAI-196
183
183
  # we have to non-block read dev files. Ew.
184
- f = File.open('/proc/mounts')
184
+ f = File.open("/proc/mounts")
185
185
  loop do
186
186
  begin
187
187
  data = f.read_nonblock(4096)
@@ -213,9 +213,9 @@ Ohai.plugin(:Filesystem2) do
213
213
  by_mountpoint = generate_mountpoint_view(fs)
214
214
 
215
215
  fs2 = Mash.new
216
- fs2['by_device'] = by_device
217
- fs2['by_mountpoint'] = by_mountpoint
218
- fs2['by_pair'] = by_pair
216
+ fs2["by_device"] = by_device
217
+ fs2["by_mountpoint"] = by_mountpoint
218
+ fs2["by_pair"] = by_pair
219
219
 
220
220
  # Set the filesystem data
221
221
  filesystem2 fs2
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  Ohai.plugin(:Mdadm) do
20
- provides 'mdadm'
20
+ provides "mdadm"
21
21
 
22
22
  def create_raid_device_mash(stdout)
23
23
  device_mash = Mash.new
@@ -51,9 +51,9 @@ Ohai.plugin(:Mdadm) do
51
51
 
52
52
  collect_data(:linux) do
53
53
  # gather a list of all raid arrays
54
- if File.exist?('/proc/mdstat')
54
+ if File.exist?("/proc/mdstat")
55
55
  devices = []
56
- File.open('/proc/mdstat').each do |line|
56
+ File.open("/proc/mdstat").each do |line|
57
57
  devices << Regexp.last_match[1] if line =~ /(md[0-9]+)/
58
58
  end
59
59
 
@@ -46,11 +46,11 @@ Ohai.plugin(:Network) do
46
46
  end
47
47
 
48
48
  def is_openvz?
49
- ::File.directory?('/proc/vz')
49
+ ::File.directory?("/proc/vz")
50
50
  end
51
51
 
52
52
  def is_openvz_host?
53
- is_openvz? && ::File.directory?('/proc/bc')
53
+ is_openvz? && ::File.directory?("/proc/bc")
54
54
  end
55
55
 
56
56
  def extract_neighbors(family, iface, neigh_attr)
@@ -98,7 +98,7 @@ Ohai.plugin(:Network) do
98
98
  Ohai::Log.debug("Skipping route entry without a device: '#{line}'")
99
99
  next
100
100
  end
101
- route_int = 'venet0:0' if is_openvz? && !is_openvz_host? && route_int == 'venet0' && iface['venet0:0']
101
+ route_int = "venet0:0" if is_openvz? && !is_openvz_host? && route_int == "venet0" && iface["venet0:0"]
102
102
 
103
103
  unless iface[route_int]
104
104
  Ohai::Log.debug("Skipping previously unseen interface from 'ip route show': #{route_int}")
@@ -107,13 +107,21 @@ Ohai.plugin(:Network) do
107
107
 
108
108
  route_entry = Mash.new(:destination => route_dest,
109
109
  :family => family[:name])
110
- %w[via scope metric proto src].each do |k|
110
+ %w{via scope metric proto src}.each do |k|
111
111
  route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)\b/
112
112
  end
113
113
 
114
114
  # a sanity check, especially for Linux-VServer, OpenVZ and LXC:
115
115
  # don't report the route entry if the src address isn't set on the node
116
- next if route_entry[:src] and not iface[route_int][:addresses].has_key? route_entry[:src]
116
+ # unless the interface has no addresses of this type at all
117
+ if route_entry[:src]
118
+ addr = iface[route_int][:addresses]
119
+ unless addr.nil? || addr.has_key?(route_entry[:src]) ||
120
+ addr.values.all? { |a| a["family"] != family[:name] }
121
+ Ohai::Log.debug("Skipping route entry whose src does not match the interface IP")
122
+ next
123
+ end
124
+ end
117
125
 
118
126
  iface[route_int][:routes] = Array.new unless iface[route_int][:routes]
119
127
  iface[route_int][:routes] << route_entry
@@ -126,6 +134,7 @@ Ohai.plugin(:Network) do
126
134
  # for information, default routes can be of this form :
127
135
  # - default via 10.0.2.4 dev br0
128
136
  # - default dev br0 scope link
137
+ # - default dev eth0 scope link src 1.1.1.1
129
138
  # - default via 10.0.3.1 dev eth1 src 10.0.3.2 metric 10
130
139
  # - default via 10.0.4.1 dev eth2 src 10.0.4.2 metric 20
131
140
 
@@ -141,19 +150,19 @@ Ohai.plugin(:Network) do
141
150
  # determine layer 1 details for the interface using ethtool
142
151
  def ethernet_layer_one(iface)
143
152
  return iface unless ethtool_binary = find_ethtool_binary
144
- keys = %w[ Speed Duplex Port Transceiver Auto-negotiation MDI-X ]
153
+ keys = %w{ Speed Duplex Port Transceiver Auto-negotiation MDI-X }
145
154
  iface.each_key do |tmp_int|
146
- next unless iface[tmp_int][:encapsulation] == 'Ethernet'
155
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
147
156
  so = shell_out("#{ethtool_binary} #{tmp_int}")
148
157
  so.stdout.lines do |line|
149
158
  line.chomp!
150
159
  Ohai::Log.debug("Parsing ethtool output: #{line}")
151
160
  line.lstrip!
152
- k, v = line.split(': ')
161
+ k, v = line.split(": ")
153
162
  next unless keys.include? k
154
- k.downcase!.tr!('-', '_')
155
- if k == 'speed'
156
- k = 'link_speed' # This is not necessarily the maximum speed the NIC supports
163
+ k.downcase!.tr!("-", "_")
164
+ if k == "speed"
165
+ k = "link_speed" # This is not necessarily the maximum speed the NIC supports
157
166
  v = v[/\d+/].to_i
158
167
  end
159
168
  iface[tmp_int][k] = v
@@ -181,7 +190,7 @@ Ohai.plugin(:Network) do
181
190
  net_counters[tmp_int][int][:packets] = $2
182
191
  net_counters[tmp_int][int][:errors] = $3
183
192
  net_counters[tmp_int][int][:drop] = $4
184
- if (int == :rx)
193
+ if int == :rx
185
194
  net_counters[tmp_int][int][:overrun] = $5
186
195
  else
187
196
  net_counters[tmp_int][int][:carrier] = $5
@@ -214,7 +223,7 @@ Ohai.plugin(:Network) do
214
223
  end
215
224
 
216
225
  if line =~ /state (\w+)/
217
- iface[tmp_int]['state'] = $1.downcase
226
+ iface[tmp_int]["state"] = $1.downcase
218
227
  end
219
228
  end
220
229
  iface
@@ -258,7 +267,7 @@ Ohai.plugin(:Network) do
258
267
  iface[cint][:encapsulation] = linux_encaps_lookup($1)
259
268
  unless $2 == "00:00:00:00:00:00"
260
269
  iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
261
- iface[cint][:addresses][$2.upcase] = {"family" => "lladdr"}
270
+ iface[cint][:addresses][$2.upcase] = { "family" => "lladdr" }
262
271
  end
263
272
  end
264
273
  end
@@ -279,7 +288,7 @@ Ohai.plugin(:Network) do
279
288
 
280
289
  iface[cint] = Mash.new unless iface[cint] # Create the fake alias interface if needed
281
290
  iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
282
- iface[cint][:addresses][tmp_addr] = {"family" => "inet", "prefixlen" => tmp_prefix}
291
+ iface[cint][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix }
283
292
  iface[cint][:addresses][tmp_addr][:netmask] = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
284
293
 
285
294
  if line =~ /peer (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
@@ -304,52 +313,77 @@ Ohai.plugin(:Network) do
304
313
  if line =~ /inet6 ([a-f0-9\:]+)\/(\d+) scope (\w+)/
305
314
  iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
306
315
  tmp_addr = $1
307
- iface[cint][:addresses][tmp_addr] = {"family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("host") ? "Node" : $3.capitalize)}
316
+ iface[cint][:addresses][tmp_addr] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("host") ? "Node" : $3.capitalize) }
308
317
  end
309
318
  end
310
319
 
311
320
  # returns the macaddress for interface from a hash of interfaces (iface elsewhere in this file)
312
321
  def get_mac_for_interface(interfaces, interface)
313
- interfaces[interface][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless interfaces[interface][:flags].include? "NOARP"
322
+ interfaces[interface][:addresses].select { |k, v| v["family"] == "lladdr" }.first.first unless interfaces[interface][:addresses].nil? || interfaces[interface][:flags].include?("NOARP")
314
323
  end
315
324
 
316
325
  # returns the default route with the lowest metric (unspecified metric is 0)
317
326
  def choose_default_route(routes)
318
- default_route = routes.select do |r|
327
+ routes.select do |r|
319
328
  r[:destination] == "default"
320
- end.sort do |x,y|
329
+ end.sort do |x, y|
321
330
  (x[:metric].nil? ? 0 : x[:metric].to_i) <=> (y[:metric].nil? ? 0 : y[:metric].to_i)
322
331
  end.first
323
332
  end
324
333
 
334
+ def interface_has_no_addresses_in_family?(iface, family)
335
+ return true if iface[:addresses].nil?
336
+ iface[:addresses].values.all? { |addr| addr["family"] != family }
337
+ end
338
+
339
+ def interface_have_address?(iface, address)
340
+ return false if iface[:addresses].nil?
341
+ iface[:addresses].key?(address)
342
+ end
343
+
344
+ def interface_address_not_link_level?(iface, address)
345
+ iface[:addresses][address][:scope].downcase != "link"
346
+ end
347
+
348
+ def interface_valid_for_route?(iface, address, family)
349
+ return true if interface_has_no_addresses_in_family?(iface, family)
350
+
351
+ interface_have_address?(iface, address) && interface_address_not_link_level?(iface, address)
352
+ end
353
+
354
+ def route_is_valid_default_route?(route, default_route)
355
+ # if the route destination is a default route, it's good
356
+ return true if route[:destination] == "default"
357
+
358
+ # the default route has a gateway and the route matches the gateway
359
+ !default_route[:via].nil? && IPAddress(route[:destination]).include?(IPAddress(default_route[:via]))
360
+ end
361
+
325
362
  # ipv4/ipv6 routes are different enough that having a single algorithm to select the favored route for both creates unnecessary complexity
326
363
  # this method attempts to deduce the route that is most important to the user, which is later used to deduce the favored values for {ip,mac,ip6}address
327
364
  # we only consider routes that are default routes, or those routes that get us to the gateway for a default route
328
365
  def favored_default_route(routes, iface, default_route, family)
329
366
  routes.select do |r|
330
367
  if family[:name] == "inet"
331
- # selecting routes for ipv4
332
- # using the source field when it's specified :
333
- # 1) in the default route
334
- # 2) in the route entry used to reach the default gateway
335
- r[:src] and # it has a src field
336
- iface[r[:dev]] and # the iface exists
337
- iface[r[:dev]][:addresses].has_key? r[:src] and # the src ip is set on the node
338
- iface[r[:dev]][:addresses][r[:src]][:scope].downcase != "link" and # this isn't a link level addresse
339
- ( r[:destination] == "default" or
340
- ( default_route[:via] and # the default route has a gateway
341
- IPAddress(r[:destination]).include? IPAddress(default_route[:via]) # the route matches the gateway
342
- )
343
- )
368
+ # the route must have a source address
369
+ next if r[:src].nil? || r[:src].empty?
370
+
371
+ # the interface specified in the route must exist
372
+ route_interface = iface[r[:dev]]
373
+ next if route_interface.nil? # the interface specified in the route must exist
374
+
375
+ # the interface must have no addresses, or if it has the source address, the address must not
376
+ # be a link-level address
377
+ next unless interface_valid_for_route?(route_interface, r[:src], "inet")
378
+
379
+ # the route must either be a default route, or it must have a gateway which is accessible via the route
380
+ next unless route_is_valid_default_route?(r, default_route)
381
+
382
+ true
344
383
  elsif family[:name] == "inet6"
345
- # selecting routes for ipv6
346
- iface[r[:dev]] and # the iface exists
347
- iface[r[:dev]][:state] == "up" and # the iface is up
348
- ( r[:destination] == "default" or
349
- ( default_route[:via] and # the default route has a gateway
350
- IPAddress(r[:destination]).include? IPAddress(default_route[:via]) # the route matches the gateway
351
- )
352
- )
384
+ iface[r[:dev]] &&
385
+ iface[r[:dev]][:state] == "up" &&
386
+ route_is_valid_default_route?(r, default_route)
353
387
  end
354
388
  end.sort_by do |r|
355
389
  # sorting the selected routes:
@@ -365,7 +399,7 @@ Ohai.plugin(:Network) do
365
399
  IPAddress( r[:destination] == "default" ? family[:default_route] : r[:destination] ).prefix
366
400
  rescue
367
401
  0
368
- end
402
+ end,
369
403
  ]
370
404
  end.first
371
405
  end
@@ -374,7 +408,7 @@ Ohai.plugin(:Network) do
374
408
  # If the 'ip' binary is available, this plugin may set {ip,mac,ip6}address. The network plugin should not overwrite these.
375
409
  # The older code section below that relies on the deprecated net-tools, e.g. netstat and ifconfig, provides less functionality.
376
410
  collect_data(:linux) do
377
- require 'ipaddr'
411
+ require "ipaddr"
378
412
 
379
413
  iface = Mash.new
380
414
  net_counters = Mash.new
@@ -386,7 +420,7 @@ Ohai.plugin(:Network) do
386
420
 
387
421
  # ohai.plugin[:network][:default_route_table] = 'default'
388
422
  if configuration(:default_route_table).nil? || configuration(:default_route_table).empty?
389
- default_route_table = 'main'
423
+ default_route_table = "main"
390
424
  else
391
425
  default_route_table = configuration(:default_route_table)
392
426
  end
@@ -403,14 +437,14 @@ Ohai.plugin(:Network) do
403
437
  :name => "inet",
404
438
  :default_route => "0.0.0.0/0",
405
439
  :default_prefix => :default,
406
- :neighbour_attribute => :arp
440
+ :neighbour_attribute => :arp,
407
441
  }]
408
442
 
409
443
  families << {
410
444
  :name => "inet6",
411
445
  :default_route => "::/0",
412
446
  :default_prefix => :default_inet6,
413
- :neighbour_attribute => :neighbour_inet6
447
+ :neighbour_attribute => :neighbour_inet6,
414
448
  } if ipv6_enabled?
415
449
 
416
450
  parse_ip_addr(iface)
@@ -430,11 +464,11 @@ Ohai.plugin(:Network) do
430
464
  default_route = choose_default_route(routes)
431
465
 
432
466
  if default_route.nil? or default_route.empty?
433
- attribute_name == if family[:name] == "inet"
434
- "default_interface"
435
- else
436
- "default_#{family[:name]}_interface"
437
- end
467
+ attribute_name = if family[:name] == "inet"
468
+ "default_interface"
469
+ else
470
+ "default_#{family[:name]}_interface"
471
+ end
438
472
  Ohai::Log.debug("Unable to determine '#{attribute_name}' as no default routes were found for that interface family")
439
473
  else
440
474
  network["#{default_prefix}_interface"] = default_route[:dev]
@@ -476,7 +510,7 @@ Ohai.plugin(:Network) do
476
510
  begin
477
511
  so = shell_out("route -n")
478
512
  route_result = so.stdout.split($/).grep( /^0.0.0.0/ )[0].split( /[ \t]+/ )
479
- network[:default_gateway], network[:default_interface] = route_result.values_at(1,7)
513
+ network[:default_gateway], network[:default_interface] = route_result.values_at(1, 7)
480
514
  rescue Ohai::Exceptions::Exec
481
515
  Ohai::Log.debug("Unable to determine default interface")
482
516
  end