ohai 8.8.1 → 8.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/README.md +1 -1
  4. data/Rakefile +6 -0
  5. data/bin/ohai +2 -2
  6. data/lib/ohai.rb +4 -4
  7. data/lib/ohai/config.rb +2 -2
  8. data/lib/ohai/dsl.rb +2 -2
  9. data/lib/ohai/dsl/plugin.rb +3 -3
  10. data/lib/ohai/dsl/plugin/versionvi.rb +3 -3
  11. data/lib/ohai/dsl/plugin/versionvii.rb +2 -2
  12. data/lib/ohai/exception.rb +2 -2
  13. data/lib/ohai/hints.rb +2 -2
  14. data/lib/ohai/loader.rb +1 -1
  15. data/lib/ohai/log.rb +2 -2
  16. data/lib/ohai/mixin/command.rb +2 -2
  17. data/lib/ohai/mixin/constant_helper.rb +2 -2
  18. data/lib/ohai/mixin/dmi_decode.rb +1 -1
  19. data/lib/ohai/mixin/ec2_metadata.rb +3 -3
  20. data/lib/ohai/mixin/network_constants.rb +4 -4
  21. data/lib/ohai/mixin/os.rb +2 -2
  22. data/lib/ohai/mixin/seconds_to_human.rb +4 -4
  23. data/lib/ohai/mixin/string.rb +4 -4
  24. data/lib/ohai/plugin_config.rb +1 -1
  25. data/lib/ohai/plugins/aix/cpu.rb +35 -29
  26. data/lib/ohai/plugins/aix/filesystem.rb +58 -40
  27. data/lib/ohai/plugins/aix/kernel.rb +3 -2
  28. data/lib/ohai/plugins/aix/memory.rb +4 -3
  29. data/lib/ohai/plugins/aix/network.rb +6 -4
  30. data/lib/ohai/plugins/aix/os.rb +30 -0
  31. data/lib/ohai/plugins/aix/platform.rb +3 -2
  32. data/lib/ohai/plugins/aix/uptime.rb +3 -2
  33. data/lib/ohai/plugins/aix/virtualization.rb +115 -5
  34. data/lib/ohai/plugins/azure.rb +1 -1
  35. data/lib/ohai/plugins/bsd/filesystem.rb +1 -1
  36. data/lib/ohai/plugins/command.rb +4 -4
  37. data/lib/ohai/plugins/darwin/cpu.rb +5 -3
  38. data/lib/ohai/plugins/darwin/filesystem.rb +4 -4
  39. data/lib/ohai/plugins/darwin/filesystem2.rb +4 -4
  40. data/lib/ohai/plugins/darwin/memory.rb +6 -5
  41. data/lib/ohai/plugins/darwin/network.rb +2 -2
  42. data/lib/ohai/plugins/darwin/platform.rb +2 -2
  43. data/lib/ohai/plugins/darwin/system_profiler.rb +2 -2
  44. data/lib/ohai/plugins/dragonflybsd/os.rb +2 -2
  45. data/lib/ohai/plugins/ec2.rb +3 -3
  46. data/lib/ohai/plugins/erlang.rb +3 -3
  47. data/lib/ohai/plugins/eucalyptus.rb +3 -3
  48. data/lib/ohai/plugins/freebsd/cpu.rb +8 -4
  49. data/lib/ohai/plugins/freebsd/os.rb +2 -2
  50. data/lib/ohai/plugins/hostname.rb +12 -4
  51. data/lib/ohai/plugins/init_package.rb +2 -8
  52. data/lib/ohai/plugins/java.rb +2 -2
  53. data/lib/ohai/plugins/kernel.rb +5 -4
  54. data/lib/ohai/plugins/keys.rb +3 -3
  55. data/lib/ohai/plugins/languages.rb +4 -4
  56. data/lib/ohai/plugins/linux/block_device.rb +3 -3
  57. data/lib/ohai/plugins/linux/cpu.rb +2 -2
  58. data/lib/ohai/plugins/linux/filesystem.rb +2 -2
  59. data/lib/ohai/plugins/linux/filesystem2.rb +3 -3
  60. data/lib/ohai/plugins/linux/lsb.rb +2 -2
  61. data/lib/ohai/plugins/linux/memory.rb +2 -2
  62. data/lib/ohai/plugins/linux/network.rb +141 -59
  63. data/lib/ohai/plugins/linux/platform.rb +6 -1
  64. data/lib/ohai/plugins/linux/virtualization.rb +1 -1
  65. data/lib/ohai/plugins/network.rb +49 -42
  66. data/lib/ohai/plugins/ohai_time.rb +4 -4
  67. data/lib/ohai/plugins/openstack.rb +2 -2
  68. data/lib/ohai/plugins/os.rb +2 -2
  69. data/lib/ohai/plugins/packages.rb +122 -0
  70. data/lib/ohai/plugins/perl.rb +5 -5
  71. data/lib/ohai/plugins/platform.rb +2 -2
  72. data/lib/ohai/plugins/powershell.rb +2 -2
  73. data/lib/ohai/plugins/ps.rb +2 -2
  74. data/lib/ohai/plugins/python.rb +1 -1
  75. data/lib/ohai/plugins/rackspace.rb +13 -0
  76. data/lib/ohai/plugins/ruby.rb +6 -6
  77. data/lib/ohai/plugins/sigar/network_route.rb +1 -1
  78. data/lib/ohai/plugins/solaris2/filesystem.rb +1 -1
  79. data/lib/ohai/plugins/solaris2/network.rb +1 -1
  80. data/lib/ohai/plugins/solaris2/platform.rb +1 -1
  81. data/lib/ohai/plugins/solaris2/virtualization.rb +5 -5
  82. data/lib/ohai/plugins/solaris2/zpools.rb +2 -2
  83. data/lib/ohai/plugins/ssh_host_key.rb +2 -2
  84. data/lib/ohai/plugins/uptime.rb +4 -4
  85. data/lib/ohai/plugins/virtualbox.rb +1 -1
  86. data/lib/ohai/plugins/virtualization.rb +7 -7
  87. data/lib/ohai/plugins/vmware.rb +1 -1
  88. data/lib/ohai/plugins/windows/filesystem.rb +1 -1
  89. data/lib/ohai/plugins/windows/network.rb +1 -1
  90. data/lib/ohai/plugins/windows/platform.rb +1 -1
  91. data/lib/ohai/plugins/windows/virtualization.rb +1 -1
  92. data/lib/ohai/provides_map.rb +3 -3
  93. data/lib/ohai/runner.rb +2 -2
  94. data/lib/ohai/system.rb +2 -2
  95. data/lib/ohai/util/file_helper.rb +1 -1
  96. data/lib/ohai/util/win32.rb +1 -1
  97. data/lib/ohai/util/win32/group_helper.rb +1 -1
  98. data/lib/ohai/version.rb +3 -3
  99. data/spec/data/plugins/dpkg-query.output +1087 -0
  100. data/spec/data/plugins/lslpp.output +49 -0
  101. data/spec/data/plugins/pkginfo.output +50 -0
  102. data/spec/data/plugins/pkglist.output +24 -0
  103. data/spec/data/plugins/rpmquery.output +388 -0
  104. data/spec/functional/application_spec.rb +1 -1
  105. data/spec/functional/loader_spec.rb +1 -1
  106. data/spec/functional/plugins/powershell_spec.rb +1 -1
  107. data/spec/functional/plugins/root_group_spec.rb +2 -2
  108. data/spec/ohai_spec.rb +6 -6
  109. data/spec/unit/application_spec.rb +1 -1
  110. data/spec/unit/config_spec.rb +1 -1
  111. data/spec/unit/dsl/plugin_spec.rb +2 -2
  112. data/spec/unit/hints_spec.rb +2 -2
  113. data/spec/unit/loader_spec.rb +2 -2
  114. data/spec/unit/mixin/ec2_metadata_spec.rb +1 -1
  115. data/spec/unit/plugin_config_spec.rb +1 -1
  116. data/spec/unit/plugins/aix/cpu_spec.rb +68 -40
  117. data/spec/unit/plugins/aix/filesystem_spec.rb +152 -50
  118. data/spec/unit/plugins/aix/hostname_spec.rb +5 -3
  119. data/spec/unit/plugins/aix/kernel_spec.rb +2 -1
  120. data/spec/unit/plugins/aix/memory_spec.rb +7 -5
  121. data/spec/unit/plugins/aix/network_spec.rb +17 -1
  122. data/spec/unit/plugins/aix/os_spec.rb +35 -0
  123. data/spec/unit/plugins/aix/platform_spec.rb +5 -4
  124. data/spec/unit/plugins/aix/uptime_spec.rb +2 -1
  125. data/spec/unit/plugins/aix/virtualization_spec.rb +269 -3
  126. data/spec/unit/plugins/azure_spec.rb +1 -1
  127. data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
  128. data/spec/unit/plugins/bsd/virtualization_spec.rb +2 -2
  129. data/spec/unit/plugins/chef_spec.rb +8 -8
  130. data/spec/unit/plugins/darwin/cpu_spec.rb +8 -3
  131. data/spec/unit/plugins/darwin/hostname_spec.rb +2 -2
  132. data/spec/unit/plugins/darwin/kernel_spec.rb +4 -4
  133. data/spec/unit/plugins/darwin/memory_spec.rb +1 -1
  134. data/spec/unit/plugins/darwin/network_spec.rb +1 -1
  135. data/spec/unit/plugins/darwin/platform_spec.rb +6 -6
  136. data/spec/unit/plugins/darwin/system_profiler_output.rb +0 -1
  137. data/spec/unit/plugins/darwin/system_profiler_spec.rb +4 -4
  138. data/spec/unit/plugins/ec2_spec.rb +3 -3
  139. data/spec/unit/plugins/erlang_spec.rb +3 -3
  140. data/spec/unit/plugins/eucalyptus_spec.rb +2 -2
  141. data/spec/unit/plugins/fail_spec.rb +6 -6
  142. data/spec/unit/plugins/freebsd/cpu_spec.rb +19 -4
  143. data/spec/unit/plugins/freebsd/hostname_spec.rb +2 -2
  144. data/spec/unit/plugins/freebsd/kernel_spec.rb +4 -4
  145. data/spec/unit/plugins/freebsd/platform_spec.rb +7 -7
  146. data/spec/unit/plugins/hostname_spec.rb +2 -2
  147. data/spec/unit/plugins/init_package_spec.rb +12 -2
  148. data/spec/unit/plugins/java_spec.rb +5 -5
  149. data/spec/unit/plugins/kernel_spec.rb +4 -2
  150. data/spec/unit/plugins/linux/block_device_spec.rb +75 -0
  151. data/spec/unit/plugins/linux/cpu_spec.rb +2 -2
  152. data/spec/unit/plugins/linux/filesystem2_spec.rb +14 -14
  153. data/spec/unit/plugins/linux/filesystem_spec.rb +1 -1
  154. data/spec/unit/plugins/linux/hostname_spec.rb +2 -2
  155. data/spec/unit/plugins/linux/kernel_spec.rb +5 -5
  156. data/spec/unit/plugins/linux/lsb_spec.rb +17 -17
  157. data/spec/unit/plugins/linux/network_spec.rb +80 -11
  158. data/spec/unit/plugins/linux/platform_spec.rb +20 -1
  159. data/spec/unit/plugins/linux/uptime_spec.rb +8 -8
  160. data/spec/unit/plugins/linux/virtualization_spec.rb +1 -1
  161. data/spec/unit/plugins/lua_spec.rb +2 -2
  162. data/spec/unit/plugins/netbsd/hostname_spec.rb +2 -2
  163. data/spec/unit/plugins/netbsd/kernel_spec.rb +2 -2
  164. data/spec/unit/plugins/netbsd/platform_spec.rb +2 -2
  165. data/spec/unit/plugins/network_spec.rb +110 -37
  166. data/spec/unit/plugins/nodejs_spec.rb +2 -2
  167. data/spec/unit/plugins/ohai_spec.rb +5 -5
  168. data/spec/unit/plugins/ohai_time_spec.rb +8 -8
  169. data/spec/unit/plugins/openbsd/hostname_spec.rb +2 -2
  170. data/spec/unit/plugins/openbsd/kernel_spec.rb +4 -4
  171. data/spec/unit/plugins/openbsd/platform_spec.rb +6 -6
  172. data/spec/unit/plugins/openstack_spec.rb +2 -2
  173. data/spec/unit/plugins/os_spec.rb +11 -11
  174. data/spec/unit/plugins/packages_spec.rb +241 -0
  175. data/spec/unit/plugins/perl_spec.rb +3 -3
  176. data/spec/unit/plugins/php_spec.rb +2 -2
  177. data/spec/unit/plugins/platform_spec.rb +2 -2
  178. data/spec/unit/plugins/python_spec.rb +3 -3
  179. data/spec/unit/plugins/rackspace_spec.rb +7 -0
  180. data/spec/unit/plugins/ruby_spec.rb +3 -3
  181. data/spec/unit/plugins/sigar/network_route_spec.rb +1 -1
  182. data/spec/unit/plugins/solaris2/cpu_spec.rb +1 -1
  183. data/spec/unit/plugins/solaris2/filesystem.rb +1 -1
  184. data/spec/unit/plugins/solaris2/network_spec.rb +3 -3
  185. data/spec/unit/plugins/solaris2/platform_spec.rb +5 -5
  186. data/spec/unit/plugins/solaris2/virtualization_spec.rb +1 -1
  187. data/spec/unit/plugins/ssh_host_keys_spec.rb +2 -2
  188. data/spec/unit/plugins/virtualbox_spec.rb +1 -1
  189. data/spec/unit/plugins/windows/virtualization_spec.rb +1 -1
  190. data/spec/unit/provides_map_spec.rb +2 -2
  191. data/spec/unit/runner_spec.rb +2 -2
  192. data/spec/unit/system_spec.rb +3 -3
  193. data/spec/unit/util/file_helper_spec.rb +1 -1
  194. metadata +13 -3
@@ -1,8 +1,8 @@
1
1
  #
2
2
  # Author:: Tim Dysinger (<tim@dysinger.net>)
3
- # Author:: Benjamin Black (<bb@opscode.com>)
4
- # Author:: Christopher Brown (<cb@opscode.com>)
5
- # Copyright:: Copyright (c) 2009 Opscode, Inc.
3
+ # Author:: Benjamin Black (<bb@chef.io>)
4
+ # Author:: Christopher Brown (<cb@chef.io>)
5
+ # Copyright:: Copyright (c) 2009-2016 Chef Software, Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,6 +36,9 @@ Ohai.plugin(:CPU) do
36
36
  # AMD Features2=0x21<LAHF,ABM>
37
37
  # Structured Extended Features=0x2000<NFPUSG>
38
38
  # TSC: P-state invariant
39
+ # ...
40
+ # FreeBSD/SMP: Multiprocessor System Detected: 16 CPUs
41
+ # FreeBSD/SMP: 2 package(s) x 4 core(s) x 2 SMT threads
39
42
 
40
43
  File.open("/var/run/dmesg.boot").each do |line|
41
44
  case line
@@ -54,13 +57,14 @@ Ohai.plugin(:CPU) do
54
57
  # Features2=0x80000001<SSE3,<b31>>
55
58
  when /Features2=[a-f\dx]+<(.+)>/
56
59
  cpuinfo["flags"].concat($1.downcase.split(','))
57
- when /Logical CPUs per core: (\d+)/
58
- cpuinfo["cores"] = $1
60
+ when /FreeBSD\/SMP: Multiprocessor System Detected: (\d*) CPUs/
61
+ cpuinfo["total"] = $1.to_i
62
+ when /FreeBSD\/SMP: (\d*) package\(s\) x (\d*) core\(s\)/
63
+ cpuinfo["real"] = $1.to_i
64
+ cpuinfo["cores"] = $1.to_i * $2.to_i
59
65
  end
60
66
  end
61
67
 
62
68
  cpu cpuinfo
63
- so = shell_out("sysctl -n hw.ncpu")
64
- cpu[:total] = so.stdout.split($/)[0].to_i
65
69
  end
66
70
  end
@@ -1,7 +1,7 @@
1
1
  #
2
- # Authors:: Adam Jacob (<adam@opscode.com>)
2
+ # Authors:: Adam Jacob (<adam@chef.io>)
3
3
  # Richard Manyanza (<liseki@nyikacraftsmen.com>)
4
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
5
  # Copyright:: Copyright (c) 2014 Richard Manyanza.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
@@ -1,11 +1,12 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
3
  # Author:: Benjamin Black (<nostromo@gmail.com>)
4
4
  # Author:: Bryan McLellan (<btm@loftninjas.org>)
5
5
  # Author:: Daniel DeLeo (<dan@kallistec.com>)
6
6
  # Author:: Doug MacEachern (<dougm@vmware.com>)
7
7
  # Author:: James Gartrell (<jgartrel@gmail.com>)
8
- # Copyright:: Copyright (c) 2008, 2009 Opscode, Inc.
8
+ # Author:: Isa Farnik (<isa@chef.io>)
9
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
9
10
  # Copyright:: Copyright (c) 2009 Bryan McLellan
10
11
  # Copyright:: Copyright (c) 2009 Daniel DeLeo
11
12
  # Copyright:: Copyright (c) 2010 VMware, Inc.
@@ -67,7 +68,7 @@ Ohai.plugin(:Hostname) do
67
68
  def collect_hostname
68
69
  # Hostname is everything before the first dot
69
70
  if machinename
70
- machinename =~ /(\w+)\.?/
71
+ machinename =~ /([^.]+)\.?/
71
72
  hostname $1
72
73
  elsif fqdn
73
74
  fqdn =~ /(.+?)\./
@@ -90,13 +91,20 @@ Ohai.plugin(:Hostname) do
90
91
  end
91
92
  end
92
93
 
93
- collect_data(:aix, :hpux, :default) do
94
+ collect_data(:hpux, :default) do
94
95
  machinename from_cmd("hostname")
95
96
  fqdn sigar_is_available? ? get_fqdn_from_sigar : resolve_fqdn
96
97
  collect_hostname
97
98
  collect_domain
98
99
  end
99
100
 
101
+ collect_data(:aix) do
102
+ machinename from_cmd("hostname -s")
103
+ fqdn resolve_fqdn || from_cmd("hostname")
104
+ collect_hostname
105
+ collect_domain
106
+ end
107
+
100
108
  collect_data(:darwin, :netbsd, :openbsd, :dragonflybsd) do
101
109
  hostname from_cmd("hostname -s")
102
110
  fqdn resolve_fqdn
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Caleb Tennis (<caleb.tennis@gmail.com>)
3
- # Copyright:: Copyright (c) 2012 Opscode, Inc.
3
+ # Copyright:: Copyright (c) 2012-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,12 +20,6 @@ Ohai.plugin(:InitPackage) do
20
20
  provides "init_package"
21
21
 
22
22
  collect_data(:linux) do
23
- package_name = nil
24
-
25
- if File.exists?("/proc/1/comm")
26
- package_name = File.open("/proc/1/comm").gets.chomp
27
- end
28
-
29
- init_package package_name
23
+ init_package File.exists?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : 'init'
30
24
  end
31
25
  end
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Benjamin Black (<bb@opscode.com>)
3
- # Copyright:: Copyright (c) 2009 Opscode, Inc.
2
+ # Author:: Benjamin Black (<bb@chef.io>)
3
+ # Copyright:: Copyright (c) 2009-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,10 +1,10 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
3
  # Author:: Benjamin Black (<nostromo@gmail.com>)
4
4
  # Author:: Bryan McLellan (<btm@loftninjas.org>)
5
- # Author:: Claire McQuin (<claire@opscode.com>)
5
+ # Author:: Claire McQuin (<claire@chef.io>)
6
6
  # Author:: James Gartrell (<jgartrel@gmail.com>)
7
- # Copyright:: Copyright (c) 2008, 2009, 2013 Opscode, Inc.
7
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
8
8
  # Copyright:: Copyright (c) 2009 Bryan McLellan
9
9
  # License:: Apache License, Version 2.0
10
10
  #
@@ -29,7 +29,8 @@ Ohai.plugin(:Kernel) do
29
29
  def init_kernel
30
30
  kernel Mash.new
31
31
  [["uname -s", :name], ["uname -r", :release],
32
- ["uname -v", :version], ["uname -m", :machine]].each do |cmd, property|
32
+ ["uname -v", :version], ["uname -m", :machine],
33
+ ["uname -p", :processor]].each do |cmd, property|
33
34
  so = shell_out(cmd)
34
35
  kernel[property] = so.stdout.split($/)[0]
35
36
  end
@@ -2,14 +2,14 @@
2
2
  # Cookbook Name:: apache2
3
3
  # Recipe:: default
4
4
  #
5
- # Copyright 2008, OpsCode, Inc.
5
+ # Copyright 2008-2016 Chef Software, Inc.
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
9
9
  # You may obtain a copy of the License at
10
- #
10
+ #
11
11
  # http://www.apache.org/licenses/LICENSE-2.0
12
- #
12
+ #
13
13
  # Unless required by applicable law or agreed to in writing, software
14
14
  # distributed under the License is distributed on an "AS IS" BASIS,
15
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -1,14 +1,14 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
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.
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,7 +30,7 @@ Ohai.plugin(:BlockDevice) do
30
30
  File.open("/sys/block/#{dir}/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
31
31
  end
32
32
  end
33
- %w{model rev state timeout vendor}.each do |check|
33
+ %w{model rev state timeout vendor queue_depth}.each do |check|
34
34
  if File.exists?("/sys/block/#{dir}/device/#{check}")
35
35
  File.open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
36
36
  end
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Phil Dibowitz <phil@ipom.com>
3
3
  # Author:: Adam Jacob <adam@chef.io>
4
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
5
  # Copyright:: Copyright (c) 2015 Facebook, Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
@@ -109,7 +109,7 @@ Ohai.plugin(:Filesystem2) do
109
109
  fs[key][:mount] = $6
110
110
  end
111
111
  end
112
-
112
+
113
113
  # Grab filesystem inode data from df
114
114
  so = shell_out("df -iP")
115
115
  so.stdout.each_line do |line|
@@ -159,7 +159,7 @@ Ohai.plugin(:Filesystem2) do
159
159
  fs.each_key do |key|
160
160
  keys_to_update << key if key.start_with?("#{parsed[:dev]},")
161
161
  end
162
-
162
+
163
163
  if keys_to_update.empty?
164
164
  key = "#{parsed[:dev]},"
165
165
  fs[key] = Mash.new
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,7 +1,7 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
3
  # Author:: Chris Read <chris.read@gmail.com>
4
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,6 +41,10 @@ Ohai.plugin(:Network) do
41
41
  ["/sbin/ip", "/usr/bin/ip", "/bin/ip"].any? { |path| File.exist?(path) }
42
42
  end
43
43
 
44
+ def find_ethtool_binary
45
+ ["/sbin/ethtool", "/usr/sbin/ethtool"].find { |path| File.exist?(path) }
46
+ end
47
+
44
48
  def is_openvz?
45
49
  ::File.directory?('/proc/vz')
46
50
  end
@@ -72,8 +76,8 @@ Ohai.plugin(:Network) do
72
76
  # the routing table source field.
73
77
  # 3) and since we're at it, let's populate some :routes attributes
74
78
  # (going to do that for both inet and inet6 addresses)
75
- def check_routing_table(family, iface)
76
- so = shell_out("ip -o -f #{family[:name]} route show")
79
+ def check_routing_table(family, iface, default_route_table)
80
+ so = shell_out("ip -o -f #{family[:name]} route show table #{default_route_table}")
77
81
  so.stdout.lines do |line|
78
82
  line.strip!
79
83
  Ohai::Log.debug("Parsing #{line}")
@@ -134,7 +138,31 @@ Ohai.plugin(:Network) do
134
138
  end.compact.flatten
135
139
  end
136
140
 
141
+ # determine layer 1 details for the interface using ethtool
142
+ def ethernet_layer_one(iface)
143
+ return iface unless ethtool_binary = find_ethtool_binary
144
+ keys = %w[ Speed Duplex Port Transceiver Auto-negotiation MDI-X ]
145
+ iface.each_key do |tmp_int|
146
+ next unless iface[tmp_int][:encapsulation] == 'Ethernet'
147
+ so = shell_out("#{ethtool_binary} #{tmp_int}")
148
+ so.stdout.lines do |line|
149
+ line.chomp!
150
+ Ohai::Log.debug("Parsing ethtool output: #{line}")
151
+ line.lstrip!
152
+ k, v = line.split(': ')
153
+ 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
157
+ v = v[/\d+/].to_i
158
+ end
159
+ iface[tmp_int][k] = v
160
+ end
161
+ end
162
+ iface
163
+ end
137
164
 
165
+ # determine link stats, vlans, queue length, and state for an interface using ip
138
166
  def link_statistics(iface, net_counters)
139
167
  so = shell_out("ip -d -s link")
140
168
  tmp_int = nil
@@ -225,7 +253,6 @@ Ohai.plugin(:Network) do
225
253
  end
226
254
  end
227
255
 
228
-
229
256
  def parse_ip_addr_link_line(cint, iface, line)
230
257
  if line =~ /link\/(\w+) ([\da-f\:]+) /
231
258
  iface[cint][:encapsulation] = linux_encaps_lookup($1)
@@ -267,7 +294,7 @@ Ohai.plugin(:Network) do
267
294
  iface[cint][:addresses][tmp_addr][:scope] = ($1.eql?("host") ? "Node" : $1.capitalize)
268
295
  end
269
296
 
270
- # If we found we were an an alias interface, restore cint to its original value
297
+ # If we found we were an alias interface, restore cint to its original value
271
298
  cint = original_int unless original_int.nil?
272
299
  end
273
300
  cint
@@ -281,6 +308,71 @@ Ohai.plugin(:Network) do
281
308
  end
282
309
  end
283
310
 
311
+ # returns the macaddress for interface from a hash of interfaces (iface elsewhere in this file)
312
+ 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"
314
+ end
315
+
316
+ # returns the default route with the lowest metric (unspecified metric is 0)
317
+ def choose_default_route(routes)
318
+ default_route = routes.select do |r|
319
+ r[:destination] == "default"
320
+ end.sort do |x,y|
321
+ (x[:metric].nil? ? 0 : x[:metric].to_i) <=> (y[:metric].nil? ? 0 : y[:metric].to_i)
322
+ end.first
323
+ end
324
+
325
+ # ipv4/ipv6 routes are different enough that having a single algorithm to select the favored route for both creates unnecessary complexity
326
+ # 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
+ # we only consider routes that are default routes, or those routes that get us to the gateway for a default route
328
+ def favored_default_route(routes, iface, default_route, family)
329
+ routes.select do |r|
330
+ 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
+ )
344
+ 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
+ )
353
+ end
354
+ end.sort_by do |r|
355
+ # sorting the selected routes:
356
+ # - getting default routes first
357
+ # - then sort by metric
358
+ # - then by prefixlen
359
+ [
360
+ r[:destination] == "default" ? 0 : 1,
361
+ r[:metric].nil? ? 0 : r[:metric].to_i,
362
+ # for some reason IPAddress doesn't accept "::/0", it doesn't like prefix==0
363
+ # just a quick workaround: use 0 if IPAddress fails
364
+ begin
365
+ IPAddress( r[:destination] == "default" ? family[:default_route] : r[:destination] ).prefix
366
+ rescue
367
+ 0
368
+ end
369
+ ]
370
+ end.first
371
+ end
372
+
373
+ # Both the network plugin and this plugin (linux/network) are run on linux. This plugin runs first.
374
+ # If the 'ip' binary is available, this plugin may set {ip,mac,ip6}address. The network plugin should not overwrite these.
375
+ # The older code section below that relies on the deprecated net-tools, e.g. netstat and ifconfig, provides less functionality.
284
376
  collect_data(:linux) do
285
377
  require 'ipaddr'
286
378
 
@@ -292,6 +384,14 @@ Ohai.plugin(:Network) do
292
384
  counters Mash.new unless counters
293
385
  counters[:network] = Mash.new unless counters[:network]
294
386
 
387
+ # ohai.plugin[:network][:default_route_table] = 'default'
388
+ if configuration(:default_route_table).nil? || configuration(:default_route_table).empty?
389
+ default_route_table = 'main'
390
+ else
391
+ default_route_table = configuration(:default_route_table)
392
+ end
393
+ Ohai::Log.debug("default route table is '#{default_route_table}'")
394
+
295
395
  # Match the lead line for an interface from iproute2
296
396
  # 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
297
397
  # The '@eth0:' portion doesn't exist on primary interfaces and thus is optional in the regex
@@ -323,22 +423,19 @@ Ohai.plugin(:Network) do
323
423
 
324
424
  iface = extract_neighbors(family, iface, neigh_attr)
325
425
 
326
- iface = check_routing_table(family, iface)
426
+ iface = check_routing_table(family, iface, default_route_table)
327
427
 
328
428
  routes = parse_routes(family, iface)
329
429
 
330
- # using a temporary var to hold the default route
331
- # in case there are more than 1 default route, sort it by its metric
332
- # and return the first one
333
- # (metric value when unspecified is 0)
334
- default_route = routes.select do |r|
335
- r[:destination] == "default"
336
- end.sort do |x,y|
337
- (x[:metric].nil? ? 0 : x[:metric].to_i) <=> (y[:metric].nil? ? 0 : y[:metric].to_i)
338
- end.first
430
+ default_route = choose_default_route(routes)
339
431
 
340
432
  if default_route.nil? or default_route.empty?
341
- Ohai::Log.debug("Unable to determine default #{family[:name]} interface")
433
+ attribute_name == if family[:name] == "inet"
434
+ "default_interface"
435
+ else
436
+ "default_#{family[:name]}_interface"
437
+ end
438
+ Ohai::Log.debug("Unable to determine '#{attribute_name}' as no default routes were found for that interface family")
342
439
  else
343
440
  network["#{default_prefix}_interface"] = default_route[:dev]
344
441
  Ohai::Log.debug("#{default_prefix}_interface set to #{default_route[:dev]}")
@@ -347,52 +444,35 @@ Ohai.plugin(:Network) do
347
444
  network["#{default_prefix}_gateway"] = default_route[:via] ? default_route[:via] : family[:default_route].chomp("/0")
348
445
  Ohai::Log.debug("#{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}")
349
446
 
447
+ # deduce the default route the user most likely cares about to pick {ip,mac,ip6}address below
448
+ favored_route = favored_default_route(routes, iface, default_route, family)
449
+
450
+ # FIXME: This entire block should go away, and the network plugin should be the sole source of {ip,ip6,mac}address
451
+
350
452
  # since we're at it, let's populate {ip,mac,ip6}address with the best values
351
- # using the source field when it's specified :
352
- # 1) in the default route
353
- # 2) in the route entry used to reach the default gateway
354
- route = routes.select do |r|
355
- # selecting routes
356
- r[:src] and # it has a src field
357
- iface[r[:dev]] and # the iface exists
358
- iface[r[:dev]][:addresses].has_key? r[:src] and # the src ip is set on the node
359
- iface[r[:dev]][:addresses][r[:src]][:scope].downcase != "link" and # this isn't a link level addresse
360
- ( r[:destination] == "default" or
361
- ( default_route[:via] and # the default route has a gateway
362
- IPAddress(r[:destination]).include? IPAddress(default_route[:via]) # the route matches the gateway
363
- )
364
- )
365
- end.sort_by do |r|
366
- # sorting the selected routes:
367
- # - getting default routes first
368
- # - then sort by metric
369
- # - then by prefixlen
370
- [
371
- r[:destination] == "default" ? 0 : 1,
372
- r[:metric].nil? ? 0 : r[:metric].to_i,
373
- # for some reason IPAddress doesn't accept "::/0", it doesn't like prefix==0
374
- # just a quick workaround: use 0 if IPAddress fails
375
- begin
376
- IPAddress( r[:destination] == "default" ? family[:default_route] : r[:destination] ).prefix
377
- rescue
378
- 0
379
- end
380
- ]
381
- end.first
382
-
383
- unless route.nil? or route.empty?
453
+ # if we don't set these, the network plugin may set them afterwards
454
+ if favored_route && !favored_route.empty?
384
455
  if family[:name] == "inet"
385
- ipaddress route[:src]
386
- macaddress iface[route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[route[:dev]][:flags].include? "NOARP"
387
- else
388
- ip6address route[:src]
456
+ ipaddress favored_route[:src]
457
+ m = get_mac_for_interface(iface, favored_route[:dev])
458
+ Ohai::Log.debug("Overwriting macaddress #{macaddress} with #{m} from interface #{favored_route[:dev]}") if macaddress
459
+ macaddress m
460
+ elsif family[:name] == "inet6"
461
+ # this rarely does anything since we rarely have src for ipv6, so this usually falls back on the network plugin
462
+ ip6address favored_route[:src]
463
+ if macaddress
464
+ Ohai::Log.debug("Not setting macaddress from ipv6 interface #{favored_route[:dev]} because macaddress is already set")
465
+ else
466
+ macaddress get_mac_for_interface(iface, favored_route[:dev])
467
+ end
389
468
  end
469
+ else
470
+ Ohai::Log.debug("the linux/network plugin was unable to deduce the favored default route for family '#{family[:name]}' despite finding a default route, and is not setting ipaddress/ip6address/macaddress. the network plugin may provide fallbacks.")
471
+ Ohai::Log.debug("this potential default route was excluded: #{default_route}")
390
472
  end
391
473
  end
392
- end
393
-
394
- else
395
-
474
+ end # end families.each
475
+ else # ip binary not available, falling back to net-tools, e.g. route, ifconfig
396
476
  begin
397
477
  so = shell_out("route -n")
398
478
  route_result = so.stdout.split($/).grep( /^0.0.0.0/ )[0].split( /[ \t]+/ )
@@ -476,7 +556,9 @@ Ohai.plugin(:Network) do
476
556
  iface[$4][:arp][$1] = $2.downcase
477
557
  end
478
558
  end
479
- end
559
+ end # end "ip else net-tools" block
560
+
561
+ iface = ethernet_layer_one(iface)
480
562
  counters[:network][:interfaces] = net_counters
481
563
  network["interfaces"] = iface
482
564
  end