ohai 13.12.6 → 14.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -12
  3. data/README.md +7 -12
  4. data/Rakefile +16 -23
  5. data/docs/man/man1/ohai.1 +97 -0
  6. data/lib/ohai/application.rb +9 -4
  7. data/lib/ohai/common/dmi.rb +4 -16
  8. data/lib/ohai/config.rb +5 -1
  9. data/lib/ohai/dsl.rb +0 -1
  10. data/lib/ohai/dsl/plugin.rb +12 -16
  11. data/lib/ohai/dsl/plugin/versionvii.rb +17 -5
  12. data/lib/ohai/hints.rb +2 -2
  13. data/lib/ohai/loader.rb +21 -70
  14. data/lib/ohai/log.rb +1 -1
  15. data/lib/ohai/mixin/azure_metadata.rb +4 -4
  16. data/lib/ohai/mixin/command.rb +3 -3
  17. data/lib/ohai/mixin/dmi_decode.rb +0 -2
  18. data/lib/ohai/mixin/do_metadata.rb +1 -1
  19. data/lib/ohai/mixin/ec2_metadata.rb +8 -8
  20. data/lib/ohai/mixin/gce_metadata.rb +1 -5
  21. data/lib/ohai/mixin/http_helper.rb +3 -3
  22. data/lib/ohai/mixin/scaleway_metadata.rb +46 -0
  23. data/lib/ohai/mixin/softlayer_metadata.rb +3 -3
  24. data/lib/ohai/plugins/aix/filesystem.rb +1 -1
  25. data/lib/ohai/plugins/aix/memory.rb +1 -1
  26. data/lib/ohai/plugins/aix/network.rb +2 -2
  27. data/lib/ohai/plugins/aix/virtualization.rb +1 -1
  28. data/lib/ohai/plugins/azure.rb +5 -5
  29. data/lib/ohai/plugins/bsd/virtualization.rb +11 -11
  30. data/lib/ohai/plugins/c.rb +8 -8
  31. data/lib/ohai/plugins/chef.rb +2 -1
  32. data/lib/ohai/plugins/cloud.rb +0 -3
  33. data/lib/ohai/plugins/darwin/cpu.rb +2 -2
  34. data/lib/ohai/plugins/darwin/filesystem.rb +0 -2
  35. data/lib/ohai/plugins/darwin/hardware.rb +9 -3
  36. data/lib/ohai/plugins/darwin/network.rb +2 -2
  37. data/lib/ohai/plugins/darwin/system_profiler.rb +19 -19
  38. data/lib/ohai/plugins/darwin/virtualization.rb +10 -0
  39. data/lib/ohai/plugins/digital_ocean.rb +4 -4
  40. data/lib/ohai/plugins/dmi.rb +15 -14
  41. data/lib/ohai/plugins/docker.rb +57 -0
  42. data/lib/ohai/plugins/ec2.rb +11 -11
  43. data/lib/ohai/plugins/elixir.rb +1 -1
  44. data/lib/ohai/plugins/erlang.rb +2 -2
  45. data/lib/ohai/plugins/eucalyptus.rb +5 -5
  46. data/lib/ohai/plugins/gce.rb +2 -2
  47. data/lib/ohai/plugins/go.rb +1 -1
  48. data/lib/ohai/plugins/groovy.rb +1 -1
  49. data/lib/ohai/plugins/haskell.rb +4 -4
  50. data/lib/ohai/plugins/hostname.rb +6 -6
  51. data/lib/ohai/plugins/init_package.rb +1 -1
  52. data/lib/ohai/plugins/java.rb +1 -1
  53. data/lib/ohai/plugins/kernel.rb +109 -40
  54. data/lib/ohai/plugins/libvirt.rb +113 -0
  55. data/lib/ohai/plugins/linode.rb +4 -4
  56. data/lib/ohai/plugins/linux/block_device.rb +4 -4
  57. data/lib/ohai/plugins/linux/cpu.rb +3 -3
  58. data/lib/ohai/plugins/linux/filesystem.rb +4 -6
  59. data/lib/ohai/plugins/linux/lsb.rb +3 -3
  60. data/lib/ohai/plugins/linux/lspci.rb +2 -1
  61. data/lib/ohai/plugins/linux/machineid.rb +4 -4
  62. data/lib/ohai/plugins/linux/network.rb +16 -16
  63. data/lib/ohai/plugins/linux/platform.rb +4 -10
  64. data/lib/ohai/plugins/linux/sessions.rb +2 -1
  65. data/lib/ohai/plugins/linux/virtualization.rb +53 -31
  66. data/lib/ohai/plugins/lua.rb +1 -1
  67. data/lib/ohai/plugins/mono.rb +2 -2
  68. data/lib/ohai/plugins/network.rb +11 -11
  69. data/lib/ohai/plugins/nodejs.rb +1 -1
  70. data/lib/ohai/plugins/ohai.rb +0 -2
  71. data/lib/ohai/plugins/openstack.rb +7 -10
  72. data/lib/ohai/plugins/packages.rb +1 -1
  73. data/lib/ohai/plugins/passwd.rb +1 -0
  74. data/lib/ohai/plugins/perl.rb +1 -1
  75. data/lib/ohai/plugins/php.rb +1 -1
  76. data/lib/ohai/plugins/powershell.rb +1 -1
  77. data/lib/ohai/plugins/python.rb +1 -1
  78. data/lib/ohai/plugins/rackspace.rb +5 -5
  79. data/lib/ohai/plugins/root_group.rb +6 -9
  80. data/lib/ohai/plugins/ruby.rb +2 -2
  81. data/lib/ohai/plugins/rust.rb +1 -1
  82. data/lib/ohai/plugins/scala.rb +1 -1
  83. data/lib/ohai/plugins/scaleway.rb +56 -0
  84. data/lib/ohai/plugins/shard.rb +1 -0
  85. data/lib/ohai/plugins/softlayer.rb +2 -2
  86. data/lib/ohai/plugins/solaris2/cpu.rb +1 -1
  87. data/lib/ohai/plugins/solaris2/dmi.rb +13 -13
  88. data/lib/ohai/plugins/solaris2/network.rb +6 -6
  89. data/lib/ohai/plugins/solaris2/platform.rb +2 -2
  90. data/lib/ohai/plugins/ssh_host_key.rb +7 -7
  91. data/lib/ohai/plugins/uptime.rb +2 -7
  92. data/lib/ohai/plugins/virtualbox.rb +1 -1
  93. data/lib/ohai/plugins/vmware.rb +2 -2
  94. data/lib/ohai/plugins/windows/cpu.rb +2 -16
  95. data/lib/ohai/plugins/windows/network.rb +4 -2
  96. data/lib/ohai/plugins/zpools.rb +3 -3
  97. data/lib/ohai/provides_map.rb +1 -1
  98. data/lib/ohai/runner.rb +11 -14
  99. data/lib/ohai/system.rb +8 -71
  100. data/lib/ohai/util/file_helper.rb +2 -2
  101. data/lib/ohai/util/win32/group_helper.rb +0 -2
  102. data/lib/ohai/version.rb +1 -1
  103. data/ohai.gemspec +6 -5
  104. data/spec/functional/plugins/root_group_spec.rb +2 -2
  105. data/spec/functional/plugins/windows/uptime_spec.rb +0 -29
  106. data/spec/unit/dsl/plugin_spec.rb +14 -46
  107. data/spec/unit/loader_spec.rb +8 -70
  108. data/spec/unit/mixin/azure_metadata_spec.rb +9 -4
  109. data/spec/unit/mixin/command_spec.rb +11 -8
  110. data/spec/unit/mixin/ec2_metadata_spec.rb +5 -0
  111. data/spec/unit/mixin/softlayer_metadata_spec.rb +6 -1
  112. data/spec/unit/plugins/aix/filesystem_spec.rb +10 -10
  113. data/spec/unit/plugins/aix/network_spec.rb +1 -1
  114. data/spec/unit/plugins/aix/virtualization_spec.rb +3 -3
  115. data/spec/unit/plugins/cloud_spec.rb +0 -12
  116. data/spec/unit/plugins/darwin/cpu_spec.rb +2 -2
  117. data/spec/unit/plugins/darwin/filesystem_spec.rb +1 -6
  118. data/spec/unit/plugins/darwin/hardware_spec.rb +1 -1
  119. data/spec/unit/plugins/darwin/virtualization_spec.rb +8 -0
  120. data/spec/unit/plugins/dmi_spec.rb +17 -25
  121. data/spec/unit/plugins/docker_spec.rb +100 -0
  122. data/spec/unit/plugins/fail_spec.rb +3 -58
  123. data/spec/unit/plugins/haskell_spec.rb +1 -1
  124. data/spec/unit/plugins/init_package_spec.rb +1 -1
  125. data/spec/unit/plugins/kernel_spec.rb +0 -52
  126. data/spec/unit/plugins/linux/block_device_spec.rb +2 -2
  127. data/spec/unit/plugins/linux/filesystem_spec.rb +2 -7
  128. data/spec/unit/plugins/linux/lsb_spec.rb +5 -5
  129. data/spec/unit/plugins/linux/lspci_spec.rb +2 -2
  130. data/spec/unit/plugins/linux/machineid_spec.rb +5 -5
  131. data/spec/unit/plugins/linux/network_spec.rb +16 -16
  132. data/spec/unit/plugins/linux/platform_spec.rb +1 -17
  133. data/spec/unit/plugins/linux/virtualization_spec.rb +21 -1
  134. data/spec/unit/plugins/network_spec.rb +58 -58
  135. data/spec/unit/plugins/openstack_spec.rb +5 -24
  136. data/spec/unit/plugins/rackspace_spec.rb +6 -6
  137. data/spec/unit/plugins/root_group_spec.rb +1 -1
  138. data/spec/unit/plugins/ruby_spec.rb +1 -1
  139. data/spec/unit/plugins/rust_spec.rb +1 -1
  140. data/spec/unit/plugins/scala_spec.rb +1 -1
  141. data/spec/unit/plugins/scaleway_spec.rb +91 -0
  142. data/spec/unit/plugins/solaris2/cpu_spec.rb +3 -3
  143. data/spec/unit/plugins/solaris2/platform_spec.rb +2 -2
  144. data/spec/unit/plugins/ssh_host_keys_spec.rb +8 -8
  145. data/spec/unit/plugins/sysconf_spec.rb +1 -0
  146. data/spec/unit/plugins/windows/kernel_spec.rb +79 -0
  147. data/spec/unit/plugins/windows/uptime_spec.rb +8 -58
  148. data/spec/unit/provides_map_spec.rb +4 -4
  149. data/spec/unit/runner_spec.rb +15 -54
  150. data/spec/unit/system_spec.rb +35 -348
  151. data/spec/unit/util/file_helper_spec.rb +2 -0
  152. metadata +28 -28
  153. data/lib/ohai/dsl/plugin/versionvi.rb +0 -61
  154. data/lib/ohai/plugins/bsd/filesystem2.rb +0 -121
  155. data/lib/ohai/plugins/ip_scopes.rb +0 -67
  156. data/lib/ohai/plugins/virtualization.rb +0 -83
  157. data/spec/data/plugins/messages.rb +0 -8
  158. data/spec/data/plugins/v6message.rb +0 -2
  159. data/spec/unit/plugins/bsd/filesystem2_spec.rb +0 -126
  160. data/spec/unit/plugins/ip_scopes_spec.rb +0 -139
@@ -41,11 +41,11 @@ module Ohai
41
41
  Ohai.config[:hints_path].each do |path|
42
42
  filename = File.join(path, "#{name}.json")
43
43
  next unless File.exist?(filename)
44
- Ohai::Log.debug("Found hint #{name}.json at #{filename}")
44
+ Ohai::Log.trace("Found hint #{name}.json at #{filename}")
45
45
  @hints[name] = parse_hint_file(filename)
46
46
  end
47
47
 
48
- Ohai::Log.debug("Did not find hint #{name}.json in the hint path(s): #{Ohai.config[:hints_path].join(', ')} ") unless @hints.key?(name)
48
+ Ohai::Log.trace("Did not find hint #{name}.json in the hint path(s): #{Ohai.config[:hints_path].join(', ')} ") unless @hints.key?(name)
49
49
  @hints[name]
50
50
  end
51
51
  end
@@ -44,27 +44,19 @@ module Ohai
44
44
  return []
45
45
  end
46
46
 
47
- Ohai::Log.debug("Searching for Ohai plugins in #{plugin_dir}")
47
+ Ohai::Log.trace("Searching for Ohai plugins in #{plugin_dir}")
48
48
 
49
- # escape_glob_dir does not exist in 12.7 or below
50
- if ChefConfig::PathHelper.respond_to?(:escape_glob_dir)
51
- escaped = ChefConfig::PathHelper.escape_glob_dir(plugin_dir)
52
- else
53
- escaped = ChefConfig::PathHelper.escape_glob(plugin_dir)
54
- end
49
+ escaped = ChefConfig::PathHelper.escape_glob_dir(plugin_dir)
55
50
  Dir[File.join(escaped, "**", "*.rb")].map do |file|
56
51
  new(file, plugin_dir)
57
52
  end
58
53
  end
59
54
  end
60
55
 
61
- # Simple struct to track a v6 plugin's class, file path, and the root of
62
- # the plugin dir from which it was loaded.
63
- V6PluginClass = Struct.new(:plugin_class, :plugin_path, :plugin_dir_path)
64
-
56
+ attr_reader :logger
65
57
  def initialize(controller)
66
58
  @controller = controller
67
- @v6_plugin_classes = []
59
+ @logger = controller.logger.with_child(subsystem: "loader")
68
60
  @v7_plugin_classes = []
69
61
  end
70
62
 
@@ -81,14 +73,13 @@ module Ohai
81
73
  load_plugin_class(plugin_file.path, plugin_file.plugin_root)
82
74
  end
83
75
 
84
- collect_v6_plugins
85
76
  collect_v7_plugins
86
77
  end
87
78
 
88
79
  def load_additional(from)
89
80
  from = [ Ohai.config[:plugin_path], from].flatten
90
81
  plugin_files_by_dir(from).collect do |plugin_file|
91
- Ohai::Log.debug "Loading additional plugin: #{plugin_file}"
82
+ logger.trace "Loading additional plugin: #{plugin_file}"
92
83
  plugin = load_plugin_class(plugin_file.path, plugin_file.plugin_root)
93
84
  load_v7_plugin(plugin)
94
85
  end
@@ -97,14 +88,10 @@ module Ohai
97
88
  # Load a specified file as an ohai plugin and creates an instance of it.
98
89
  # Not used by ohai itself, but can be used to load a plugin for testing
99
90
  # purposes.
100
- # plugin_dir_path is required when loading a v6 plugin.
101
91
  def load_plugin(plugin_path, plugin_dir_path = nil)
102
92
  plugin_class = load_plugin_class(plugin_path, plugin_dir_path)
103
93
  return nil unless plugin_class.kind_of?(Class)
104
- case
105
- when plugin_class < Ohai::DSL::Plugin::VersionVI
106
- load_v6_plugin(plugin_class, plugin_path, plugin_dir_path)
107
- when plugin_class < Ohai::DSL::Plugin::VersionVII
94
+ if plugin_class < Ohai::DSL::Plugin::VersionVII
108
95
  load_v7_plugin(plugin_class)
109
96
  else
110
97
  raise Exceptions::IllegalPluginDefinition, "cannot create plugin of type #{plugin_class}"
@@ -121,10 +108,10 @@ module Ohai
121
108
  # Read the contents of the plugin to understand if it's a V6 or V7 plugin.
122
109
  contents = ""
123
110
  begin
124
- Ohai::Log.debug("Loading plugin at #{plugin_path}")
111
+ logger.trace("Loading plugin at #{plugin_path}")
125
112
  contents << IO.read(plugin_path)
126
113
  rescue IOError, Errno::ENOENT
127
- Ohai::Log.warn("Unable to open or read plugin at #{plugin_path}")
114
+ logger.warn("Unable to open or read plugin at #{plugin_path}")
128
115
  return nil
129
116
  end
130
117
 
@@ -132,12 +119,10 @@ module Ohai
132
119
  if contents.include?("Ohai.plugin")
133
120
  load_v7_plugin_class(contents, plugin_path)
134
121
  else
135
- Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. \
136
- Version 6 plugins will not be supported in Chef/Ohai 14. \
137
- Please upgrade your plugin to version 7 plugin format. \
138
- For more information visit here: docs.chef.io/ohai_custom.html")
139
-
140
- load_v6_plugin_class(contents, plugin_path, plugin_dir_path)
122
+ raise Exceptions::IllegalPluginDefinition, "[DEPRECATION] Plugin at #{plugin_path}"\
123
+ " is a version 6 plugin. Version 6 plugins are no longer supported by Ohai. This"\
124
+ " plugin will need to be updated to the v7 Ohai plugin format. See"\
125
+ " https://docs.chef.io/ohai_custom.html for v7 syntax."
141
126
  end
142
127
  end
143
128
 
@@ -148,62 +133,28 @@ For more information visit here: docs.chef.io/ohai_custom.html")
148
133
  @controller.provides_map.set_providers_for(plugin, plugin_provides)
149
134
  end
150
135
 
151
- def v6_dependency_solver
152
- @controller.v6_dependency_solver
153
- end
154
-
155
- def collect_v6_plugins
156
- @v6_plugin_classes.each do |plugin_spec|
157
- plugin = load_v6_plugin(plugin_spec.plugin_class, plugin_spec.plugin_path, plugin_spec.plugin_dir_path)
158
- loaded_v6_plugin(plugin, plugin_spec.plugin_path, plugin_spec.plugin_dir_path)
159
- end
160
- end
161
-
162
136
  def collect_v7_plugins
163
137
  @v7_plugin_classes.each do |plugin_class|
164
138
  load_v7_plugin(plugin_class)
165
139
  end
166
140
  end
167
141
 
168
- def load_v6_plugin_class(contents, plugin_path, plugin_dir_path)
169
- plugin_class = Class.new(Ohai::DSL::Plugin::VersionVI) { collect_contents(contents) }
170
- @v6_plugin_classes << V6PluginClass.new(plugin_class, plugin_path, plugin_dir_path)
171
- plugin_class
172
- end
173
-
174
- def load_v6_plugin(plugin_class, plugin_path, plugin_dir_path)
175
- plugin_class.new(@controller, plugin_path, plugin_dir_path)
176
- end
177
-
178
- # Capture the plugin in @v6_dependency_solver if it is a V6 plugin
179
- # to be able to resolve V6 dependencies later on.
180
- # We are using the partial path in the dep solver as a key.
181
- def loaded_v6_plugin(plugin, plugin_file_path, plugin_dir_path)
182
- partial_path = Pathname.new(plugin_file_path).relative_path_from(Pathname.new(plugin_dir_path)).to_s
183
-
184
- unless v6_dependency_solver.has_key?(partial_path)
185
- v6_dependency_solver[partial_path] = plugin
186
- else
187
- Ohai::Log.debug("Plugin '#{plugin_file_path}' is already loaded.")
188
- end
189
- end
190
-
191
142
  def load_v7_plugin_class(contents, plugin_path)
192
- plugin_class = eval(contents, TOPLEVEL_BINDING, plugin_path)
143
+ plugin_class = eval(contents, TOPLEVEL_BINDING, plugin_path) # rubocop: disable Security/Eval
193
144
  unless plugin_class.kind_of?(Class) && plugin_class < Ohai::DSL::Plugin
194
145
  raise Ohai::Exceptions::IllegalPluginDefinition, "Plugin file cannot contain any statements after the plugin definition"
195
146
  end
196
147
  plugin_class.sources << plugin_path
197
148
  @v7_plugin_classes << plugin_class unless @v7_plugin_classes.include?(plugin_class)
198
149
  plugin_class
199
- rescue SystemExit, Interrupt
150
+ rescue SystemExit, Interrupt # rubocop: disable Lint/ShadowedException
200
151
  raise
201
152
  rescue Ohai::Exceptions::InvalidPluginName => e
202
- Ohai::Log.warn("Plugin Name Error: <#{plugin_path}>: #{e.message}")
153
+ logger.warn("Plugin Name Error: <#{plugin_path}>: #{e.message}")
203
154
  rescue Ohai::Exceptions::IllegalPluginDefinition => e
204
- Ohai::Log.warn("Plugin Definition Error: <#{plugin_path}>: #{e.message}")
155
+ logger.warn("Plugin Definition Error: <#{plugin_path}>: #{e.message}")
205
156
  rescue NoMethodError => e
206
- Ohai::Log.warn("Plugin Method Error: <#{plugin_path}>: unsupported operation \'#{e.name}\'")
157
+ logger.warn("Plugin Method Error: <#{plugin_path}>: unsupported operation \'#{e.name}\'")
207
158
  rescue SyntaxError => e
208
159
  # split on occurrences of
209
160
  # <env>: syntax error,
@@ -212,15 +163,15 @@ For more information visit here: docs.chef.io/ohai_custom.html")
212
163
  parts = e.message.split(/<.*>[:[0-9]+]*: syntax error, /)
213
164
  parts.each do |part|
214
165
  next if part.length == 0
215
- Ohai::Log.warn("Plugin Syntax Error: <#{plugin_path}>: #{part}")
166
+ logger.warn("Plugin Syntax Error: <#{plugin_path}>: #{part}")
216
167
  end
217
168
  rescue Exception, Errno::ENOENT => e
218
- Ohai::Log.warn("Plugin Error: <#{plugin_path}>: #{e.message}")
219
- Ohai::Log.debug("Plugin Error: <#{plugin_path}>: #{e.inspect}, #{e.backtrace.join('\n')}")
169
+ logger.warn("Plugin Error: <#{plugin_path}>: #{e.message}")
170
+ logger.trace("Plugin Error: <#{plugin_path}>: #{e.inspect}, #{e.backtrace.join('\n')}")
220
171
  end
221
172
 
222
173
  def load_v7_plugin(plugin_class)
223
- plugin = plugin_class.new(@controller.data)
174
+ plugin = plugin_class.new(@controller.data, @controller.logger)
224
175
  collect_provides(plugin)
225
176
  plugin
226
177
  end
@@ -25,7 +25,7 @@ module Ohai
25
25
  # this class loading initalization is so that we don't lose early logger
26
26
  # messages when run from the CLI?
27
27
  init(STDERR)
28
- level = :info
28
+ level = :info # rubocop:disable Lint/UselessAssignment
29
29
 
30
30
  end
31
31
  end
@@ -28,11 +28,11 @@ module Ohai
28
28
  def http_get(uri)
29
29
  conn = Net::HTTP.start(AZURE_METADATA_ADDR)
30
30
  conn.read_timeout = 6
31
- conn.get(uri, initheader = { "Metadata" => "true" })
31
+ conn.get(uri, { "Metadata" => "true" })
32
32
  end
33
33
 
34
34
  def fetch_metadata
35
- Ohai::Log.debug("Mixin AzureMetadata: Fetching metadata from host #{AZURE_METADATA_ADDR} at #{AZURE_METADATA_URL}")
35
+ logger.trace("Mixin AzureMetadata: Fetching metadata from host #{AZURE_METADATA_ADDR} at #{AZURE_METADATA_URL}")
36
36
  response = http_get(AZURE_METADATA_URL)
37
37
  if response.code == "200"
38
38
  begin
@@ -40,11 +40,11 @@ module Ohai
40
40
  parser = FFI_Yajl::Parser.new
41
41
  parser.parse(data)
42
42
  rescue FFI_Yajl::ParseError
43
- Ohai::Log.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON")
43
+ logger.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON")
44
44
  nil
45
45
  end
46
46
  else
47
- Ohai::Log.warn("Mixin AzureMetadata: Received response code #{response.code} requesting metadata")
47
+ logger.warn("Mixin AzureMetadata: Received response code #{response.code} requesting metadata")
48
48
  nil
49
49
  end
50
50
  end
@@ -37,13 +37,13 @@ module Ohai
37
37
  so = Mixlib::ShellOut.new(cmd, options)
38
38
  begin
39
39
  so.run_command
40
- Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}")
40
+ logger.trace("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}")
41
41
  so
42
42
  rescue Errno::ENOENT => e
43
- Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}")
43
+ logger.trace("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}")
44
44
  raise Ohai::Exceptions::Exec, e
45
45
  rescue Mixlib::ShellOut::CommandTimeout => e
46
- Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
46
+ logger.trace("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
47
47
  raise Ohai::Exceptions::Exec, e
48
48
  end
49
49
  end
@@ -44,8 +44,6 @@ module ::Ohai::Mixin::DmiDecode
44
44
  return "bhyve"
45
45
  when /Manufacturer: Veertu/
46
46
  return "veertu"
47
- when /Manufacturer: Amazon EC2/
48
- return "amazonec2"
49
47
  end
50
48
  end
51
49
  nil
@@ -35,7 +35,7 @@ module Ohai
35
35
  parser = FFI_Yajl::Parser.new
36
36
  parser.parse(response.body)
37
37
  when "404"
38
- Ohai::Log.debug("Mixin DOMetadata: Encountered 404 response retrieving Digital Ocean metadata: #{uri} ; continuing.")
38
+ logger.trace("Mixin DOMetadata: Encountered 404 response retrieving Digital Ocean metadata: #{uri} ; continuing.")
39
39
  {}
40
40
  else
41
41
  raise "Mixin DOMetadata: Encountered error retrieving Digital Ocean metadata (#{uri} returned #{response.code} response)"
@@ -43,16 +43,16 @@ module Ohai
43
43
  EC2_SUPPORTED_VERSIONS = %w{ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15
44
44
  2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12
45
45
  2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02 }
46
- EC2_ARRAY_VALUES = %w{security-groups}
46
+ EC2_ARRAY_VALUES = %w{security-groups local_ipv4s}
47
47
  EC2_ARRAY_DIR = %w{network/interfaces/macs}
48
48
  EC2_JSON_DIR = %w{iam}
49
49
 
50
50
  def best_api_version
51
51
  @api_version ||= begin
52
- Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/ to determine the latest supported metadata release")
52
+ logger.trace("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/ to determine the latest supported metadata release")
53
53
  response = http_client.get("/")
54
54
  if response.code == "404"
55
- Ohai::Log.debug("Mixin EC2: Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
55
+ logger.trace("Mixin EC2: Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
56
56
  return "latest"
57
57
  elsif response.code != "200"
58
58
  raise "Mixin EC2: Unable to determine EC2 metadata version (returned #{response.code} response)"
@@ -62,9 +62,9 @@ module Ohai
62
62
  versions = response.body.split("\n").sort
63
63
  until versions.empty? || EC2_SUPPORTED_VERSIONS.include?(versions.last)
64
64
  pv = versions.pop
65
- Ohai::Log.debug("Mixin EC2: EC2 lists metadata version: #{pv} not yet supported by Ohai") unless pv == "latest"
65
+ logger.trace("Mixin EC2: EC2 lists metadata version: #{pv} not yet supported by Ohai") unless pv == "latest"
66
66
  end
67
- Ohai::Log.debug("Mixin EC2: Latest supported EC2 metadata version: #{versions.last}")
67
+ logger.trace("Mixin EC2: Latest supported EC2 metadata version: #{versions.last}")
68
68
  if versions.empty?
69
69
  raise "Mixin EC2: Unable to determine EC2 metadata version (no supported entries found)"
70
70
  end
@@ -88,13 +88,13 @@ module Ohai
88
88
  # `nil` and continue the run instead of failing it.
89
89
  def metadata_get(id, api_version)
90
90
  path = "/#{api_version}/meta-data/#{id}"
91
- Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}#{path}")
91
+ logger.trace("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}#{path}")
92
92
  response = http_client.get(path)
93
93
  case response.code
94
94
  when "200"
95
95
  response.body
96
96
  when "404"
97
- Ohai::Log.debug("Mixin EC2: Encountered 404 response retrieving EC2 metadata path: #{path} ; continuing.")
97
+ logger.trace("Mixin EC2: Encountered 404 response retrieving EC2 metadata path: #{path} ; continuing.")
98
98
  nil
99
99
  else
100
100
  raise "Mixin EC2: Encountered error retrieving EC2 metadata (#{path} returned #{response.code} response)"
@@ -169,7 +169,7 @@ module Ohai
169
169
  end
170
170
 
171
171
  def fetch_userdata
172
- Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/#{best_api_version}/user-data/")
172
+ logger.trace("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/#{best_api_version}/user-data/")
173
173
  response = http_client.get("/#{best_api_version}/user-data/")
174
174
  response.code == "200" ? response.body : nil
175
175
  end
@@ -28,11 +28,7 @@ module Ohai
28
28
  def http_get(uri)
29
29
  conn = Net::HTTP.start(GCE_METADATA_ADDR)
30
30
  conn.read_timeout = 6
31
- conn.get(uri, {
32
- "Metadata-Flavor" => "Google",
33
- "User-Agent" => "chef-ohai/#{Ohai::VERSION}",
34
- }
35
- )
31
+ conn.get(uri, { "Metadata-Flavor" => "Google" })
36
32
  end
37
33
 
38
34
  def fetch_metadata(id = "")
@@ -25,7 +25,7 @@ module Ohai
25
25
  begin
26
26
  saddr = Socket.pack_sockaddr_in(port, addr)
27
27
  rescue SocketError => e # generally means dns resolution error
28
- Ohai::Log.debug("Mixin HttpHelper: can_socket_connect? failed setting up socket connection: #{e}")
28
+ logger.trace("Mixin HttpHelper: can_socket_connect? failed setting up socket connection: #{e}")
29
29
  return false
30
30
  end
31
31
 
@@ -34,7 +34,7 @@ module Ohai
34
34
  begin
35
35
  t.connect_nonblock(saddr)
36
36
  rescue Errno::EINPROGRESS
37
- r, w, e = IO.select(nil, [t], nil, timeout)
37
+ _r, w, _e = IO.select(nil, [t], nil, timeout)
38
38
  if !w.nil?
39
39
  connected = true
40
40
  else
@@ -48,7 +48,7 @@ module Ohai
48
48
  end
49
49
  rescue SystemCallError
50
50
  end
51
- Ohai::Log.debug("Mixin HttpHelper: can_socket_connect? == #{connected}")
51
+ logger.trace("Mixin HttpHelper: can_socket_connect? == #{connected}")
52
52
  connected
53
53
  end
54
54
  end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Author:: Jonathan Amiez (<jonathan.amiez@gmail.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "net/http"
18
+
19
+ module Ohai
20
+ module Mixin
21
+ module ScalewayMetadata
22
+
23
+ SCALEWAY_METADATA_ADDR = "169.254.42.42" unless defined?(SCALEWAY_METADATA_ADDR)
24
+ SCALEWAY_METADATA_URL = "/conf?format=json" unless defined?(SCALEWAY_METADATA_URL)
25
+
26
+ def http_client
27
+ Net::HTTP.start(SCALEWAY_METADATA_ADDR).tap { |h| h.read_timeout = 6 }
28
+ end
29
+
30
+ def fetch_metadata
31
+ uri = "#{SCALEWAY_METADATA_URL}"
32
+ response = http_client.get(uri)
33
+ case response.code
34
+ when "200"
35
+ parser = FFI_Yajl::Parser.new
36
+ parser.parse(response.body)
37
+ when "404"
38
+ logger.trace("Mixin ScalewayMetadata: Encountered 404 response retrieving Scaleway metadata: #{uri} ; continuing.")
39
+ {}
40
+ else
41
+ raise "Mixin ScalewayMetadata: Encountered error retrieving Scaleway metadata (#{uri} returned #{response.code} response)"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -25,7 +25,7 @@ module ::Ohai::Mixin::SoftlayerMetadata
25
25
  SOFTLAYER_API_QUERY_URL = "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata" unless defined?(SOFTLAYER_API_QUERY_URL)
26
26
 
27
27
  def fetch_metadata
28
- metadata = {
28
+ {
29
29
  "public_fqdn" => fetch_metadata_item("getFullyQualifiedDomainName.txt"),
30
30
  "local_ipv4" => fetch_metadata_item("getPrimaryBackendIpAddress.txt"),
31
31
  "public_ipv4" => fetch_metadata_item("getPrimaryIpAddress.txt"),
@@ -54,11 +54,11 @@ module ::Ohai::Mixin::SoftlayerMetadata
54
54
  if res.code.to_i.between?(200, 299)
55
55
  res.body
56
56
  else
57
- ::Ohai::Log.error("Mixin Softlayer: Unable to fetch item #{full_url}: status (#{res.code}) body (#{res.body})")
57
+ logger.error("Mixin Softlayer: Unable to fetch item #{full_url}: status (#{res.code}) body (#{res.body})")
58
58
  nil
59
59
  end
60
60
  rescue => e
61
- ::Ohai::Log.error("Mixin Softlayer: Unable to fetch softlayer metadata from #{u}: #{e.class}: #{e.message}")
61
+ logger.error("Mixin Softlayer: Unable to fetch softlayer metadata from #{u}: #{e.class}: #{e.message}")
62
62
  raise e
63
63
  end
64
64
  end
@@ -59,7 +59,7 @@ Ohai.plugin(:Filesystem) do
59
59
  else
60
60
  key = fields[0] + ":" + fields[1]
61
61
  oldie[key] ||= Mash.new
62
- oldie[key][:mount] = fields[2]
62
+ oldie[key][:mount] = fields[1]
63
63
  oldie[key][:fs_type] = fields[3]
64
64
  oldie[key][:mount_options] = fields[7].split(",")
65
65
  end
@@ -25,7 +25,7 @@ Ohai.plugin(:Memory) do
25
25
  memory[:swap] = Mash.new
26
26
 
27
27
  meminfo = shell_out("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'").stdout
28
- total_in_mb, u, free_in_mb = meminfo.split
28
+ total_in_mb, _u, free_in_mb = meminfo.split
29
29
  memory[:total] = "#{total_in_mb.to_i * 1024}kB"
30
30
  memory[:free] = "#{free_in_mb.to_i * 1024}kB"
31
31