ohai 16.4.12 → 16.7.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +11 -11
  3. data/bin/ohai +2 -1
  4. data/lib/ohai.rb +2 -1
  5. data/lib/ohai/application.rb +40 -0
  6. data/lib/ohai/common/dmi.rb +8 -3
  7. data/lib/ohai/config.rb +3 -3
  8. data/lib/ohai/dsl.rb +2 -1
  9. data/lib/ohai/dsl/plugin.rb +13 -5
  10. data/lib/ohai/dsl/plugin/versionvii.rb +29 -16
  11. data/lib/ohai/exception.rb +2 -1
  12. data/lib/ohai/hints.rb +2 -1
  13. data/lib/ohai/loader.rb +1 -1
  14. data/lib/ohai/log.rb +2 -1
  15. data/lib/ohai/mash.rb +1 -0
  16. data/lib/ohai/mixin/azure_metadata.rb +3 -2
  17. data/lib/ohai/mixin/chef_utils_wiring.rb +52 -0
  18. data/lib/ohai/mixin/command.rb +4 -54
  19. data/lib/ohai/mixin/constant_helper.rb +2 -1
  20. data/lib/ohai/mixin/dmi_decode.rb +2 -1
  21. data/lib/ohai/mixin/do_metadata.rb +4 -3
  22. data/lib/ohai/mixin/ec2_metadata.rb +5 -4
  23. data/lib/ohai/mixin/gce_metadata.rb +3 -2
  24. data/lib/ohai/mixin/http_helper.rb +2 -1
  25. data/lib/ohai/mixin/network_helper.rb +2 -1
  26. data/lib/ohai/mixin/os.rb +68 -2
  27. data/lib/ohai/mixin/scaleway_metadata.rb +4 -3
  28. data/lib/ohai/mixin/seconds_to_human.rb +2 -1
  29. data/lib/ohai/mixin/shell_out.rb +51 -0
  30. data/lib/ohai/mixin/softlayer_metadata.rb +2 -1
  31. data/lib/ohai/mixin/string.rb +2 -1
  32. data/lib/ohai/mixin/train_helpers.rb +36 -0
  33. data/lib/ohai/mixin/which.rb +39 -0
  34. data/lib/ohai/plugin_config.rb +2 -1
  35. data/lib/ohai/plugins/aix/kernel.rb +2 -1
  36. data/lib/ohai/plugins/aix/memory.rb +4 -3
  37. data/lib/ohai/plugins/aix/network.rb +3 -2
  38. data/lib/ohai/plugins/aix/platform.rb +2 -1
  39. data/lib/ohai/plugins/aix/uptime.rb +4 -3
  40. data/lib/ohai/plugins/aix/virtualization.rb +1 -1
  41. data/lib/ohai/plugins/azure.rb +26 -5
  42. data/lib/ohai/plugins/bsd/virtualization.rb +4 -3
  43. data/lib/ohai/plugins/c.rb +1 -0
  44. data/lib/ohai/plugins/chef.rb +2 -1
  45. data/lib/ohai/plugins/cloud.rb +2 -1
  46. data/lib/ohai/plugins/command.rb +2 -1
  47. data/lib/ohai/plugins/cpu.rb +8 -9
  48. data/lib/ohai/plugins/darwin/hardware.rb +1 -0
  49. data/lib/ohai/plugins/darwin/memory.rb +3 -4
  50. data/lib/ohai/plugins/darwin/network.rb +2 -1
  51. data/lib/ohai/plugins/darwin/platform.rb +3 -2
  52. data/lib/ohai/plugins/darwin/virtualization.rb +3 -2
  53. data/lib/ohai/plugins/digital_ocean.rb +1 -0
  54. data/lib/ohai/plugins/dmi.rb +2 -1
  55. data/lib/ohai/plugins/docker.rb +2 -1
  56. data/lib/ohai/plugins/dragonflybsd/memory.rb +1 -0
  57. data/lib/ohai/plugins/dragonflybsd/network.rb +1 -0
  58. data/lib/ohai/plugins/dragonflybsd/platform.rb +1 -0
  59. data/lib/ohai/plugins/ec2.rb +16 -9
  60. data/lib/ohai/plugins/elixir.rb +1 -1
  61. data/lib/ohai/plugins/erlang.rb +2 -1
  62. data/lib/ohai/plugins/eucalyptus.rb +5 -2
  63. data/lib/ohai/plugins/filesystem.rb +5 -5
  64. data/lib/ohai/plugins/fips.rb +2 -1
  65. data/lib/ohai/plugins/freebsd/memory.rb +1 -0
  66. data/lib/ohai/plugins/freebsd/network.rb +1 -0
  67. data/lib/ohai/plugins/freebsd/platform.rb +1 -0
  68. data/lib/ohai/plugins/gce.rb +3 -2
  69. data/lib/ohai/plugins/go.rb +1 -1
  70. data/lib/ohai/plugins/groovy.rb +1 -1
  71. data/lib/ohai/plugins/haskell.rb +1 -0
  72. data/lib/ohai/plugins/hostname.rb +2 -1
  73. data/lib/ohai/plugins/init_package.rb +3 -2
  74. data/lib/ohai/plugins/java.rb +2 -1
  75. data/lib/ohai/plugins/joyent.rb +3 -2
  76. data/lib/ohai/plugins/kernel.rb +11 -6
  77. data/lib/ohai/plugins/keys.rb +2 -1
  78. data/lib/ohai/plugins/languages.rb +2 -1
  79. data/lib/ohai/plugins/libvirt.rb +2 -1
  80. data/lib/ohai/plugins/linode.rb +2 -1
  81. data/lib/ohai/plugins/linux/block_device.rb +10 -9
  82. data/lib/ohai/plugins/linux/hostnamectl.rb +3 -2
  83. data/lib/ohai/plugins/linux/interrupts.rb +4 -3
  84. data/lib/ohai/plugins/linux/ipc.rb +2 -1
  85. data/lib/ohai/plugins/linux/lsb.rb +8 -21
  86. data/lib/ohai/plugins/linux/lspci.rb +1 -0
  87. data/lib/ohai/plugins/linux/machineid.rb +5 -4
  88. data/lib/ohai/plugins/linux/mdadm.rb +3 -2
  89. data/lib/ohai/plugins/linux/memory.rb +39 -38
  90. data/lib/ohai/plugins/linux/network.rb +14 -13
  91. data/lib/ohai/plugins/linux/platform.rb +32 -31
  92. data/lib/ohai/plugins/linux/selinux.rb +1 -0
  93. data/lib/ohai/plugins/linux/sessions.rb +1 -0
  94. data/lib/ohai/plugins/linux/sysctl.rb +1 -0
  95. data/lib/ohai/plugins/linux/systemd_paths.rb +1 -0
  96. data/lib/ohai/plugins/linux/virtualization.rb +25 -24
  97. data/lib/ohai/plugins/lua.rb +1 -1
  98. data/lib/ohai/plugins/mono.rb +1 -1
  99. data/lib/ohai/plugins/netbsd/memory.rb +1 -0
  100. data/lib/ohai/plugins/netbsd/network.rb +1 -0
  101. data/lib/ohai/plugins/netbsd/platform.rb +1 -0
  102. data/lib/ohai/plugins/network.rb +2 -1
  103. data/lib/ohai/plugins/nodejs.rb +1 -1
  104. data/lib/ohai/plugins/ohai.rb +1 -0
  105. data/lib/ohai/plugins/ohai_time.rb +3 -2
  106. data/lib/ohai/plugins/openbsd/memory.rb +1 -0
  107. data/lib/ohai/plugins/openbsd/network.rb +1 -0
  108. data/lib/ohai/plugins/openbsd/platform.rb +1 -0
  109. data/lib/ohai/plugins/openstack.rb +2 -1
  110. data/lib/ohai/plugins/os.rb +6 -1
  111. data/lib/ohai/plugins/packages.rb +21 -0
  112. data/lib/ohai/plugins/passwd.rb +58 -1
  113. data/lib/ohai/plugins/perl.rb +2 -2
  114. data/lib/ohai/plugins/php.rb +1 -1
  115. data/lib/ohai/plugins/platform.rb +2 -1
  116. data/lib/ohai/plugins/powershell.rb +2 -2
  117. data/lib/ohai/plugins/ps.rb +2 -1
  118. data/lib/ohai/plugins/python.rb +2 -2
  119. data/lib/ohai/plugins/rackspace.rb +4 -3
  120. data/lib/ohai/plugins/root_group.rb +1 -0
  121. data/lib/ohai/plugins/ruby.rb +3 -2
  122. data/lib/ohai/plugins/rust.rb +1 -1
  123. data/lib/ohai/plugins/scala.rb +1 -0
  124. data/lib/ohai/plugins/scaleway.rb +2 -1
  125. data/lib/ohai/plugins/scsi.rb +1 -0
  126. data/lib/ohai/plugins/shard.rb +2 -2
  127. data/lib/ohai/plugins/shells.rb +4 -3
  128. data/lib/ohai/plugins/softlayer.rb +2 -1
  129. data/lib/ohai/plugins/solaris2/dmi.rb +2 -1
  130. data/lib/ohai/plugins/solaris2/memory.rb +1 -0
  131. data/lib/ohai/plugins/solaris2/network.rb +7 -8
  132. data/lib/ohai/plugins/solaris2/platform.rb +9 -15
  133. data/lib/ohai/plugins/solaris2/virtualization.rb +4 -3
  134. data/lib/ohai/plugins/ssh_host_key.rb +14 -13
  135. data/lib/ohai/plugins/sysconf.rb +1 -0
  136. data/lib/ohai/plugins/timezone.rb +1 -0
  137. data/lib/ohai/plugins/train.rb +36 -0
  138. data/lib/ohai/plugins/uptime.rb +3 -2
  139. data/lib/ohai/plugins/virtualbox.rb +2 -1
  140. data/lib/ohai/plugins/vmware.rb +3 -2
  141. data/lib/ohai/plugins/windows/dmi.rb +1 -0
  142. data/lib/ohai/plugins/windows/drivers.rb +2 -1
  143. data/lib/ohai/plugins/windows/memory.rb +1 -0
  144. data/lib/ohai/plugins/windows/network.rb +3 -2
  145. data/lib/ohai/plugins/windows/platform.rb +2 -1
  146. data/lib/ohai/plugins/windows/system_enclosure.rb +2 -1
  147. data/lib/ohai/plugins/windows/virtualization.rb +2 -1
  148. data/lib/ohai/plugins/zpools.rb +6 -3
  149. data/lib/ohai/provides_map.rb +2 -1
  150. data/lib/ohai/runner.rb +8 -5
  151. data/lib/ohai/system.rb +35 -7
  152. data/lib/ohai/train_transport.rb +29 -0
  153. data/lib/ohai/util/file_helper.rb +5 -37
  154. data/lib/ohai/util/ip_helper.rb +1 -0
  155. data/lib/ohai/util/win32.rb +2 -1
  156. data/lib/ohai/version.rb +4 -3
  157. data/ohai.gemspec +8 -7
  158. metadata +80 -60
@@ -1,54 +1,4 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Author:: Tim Smith (<tsmith@chef.io>)
4
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require_relative "../exception"
21
- require_relative "../log"
22
- require "mixlib/shellout" unless defined?(Mixlib::ShellOut::DEFAULT_READ_TIMEOUT)
23
-
24
- module Ohai
25
- module Mixin
26
- module Command
27
- # DISCLAIMER: Logging only works in the context of a plugin!!
28
- # accept a command and any of the mixlib-shellout options
29
- def shell_out(cmd, **options)
30
- options = options.dup
31
- # unless specified by the caller timeout after configured timeout (default 30 seconds)
32
- options[:timeout] ||= Ohai::Config.ohai[:shellout_timeout]
33
- unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
34
- options[:env] = options.key?(:env) ? options[:env].dup : {}
35
- options[:env]["PATH"] ||= ((ENV["PATH"] || "").split(":") + %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}).join(":")
36
- end
37
- so = Mixlib::ShellOut.new(cmd, options)
38
- begin
39
- so.run_command
40
- logger.trace("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}")
41
- so
42
- rescue Errno::ENOENT => e
43
- logger.trace("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}")
44
- raise Ohai::Exceptions::Exec, e
45
- rescue Mixlib::ShellOut::CommandTimeout => e
46
- logger.trace("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
47
- raise Ohai::Exceptions::Exec, e
48
- end
49
- end
50
-
51
- module_function :shell_out
52
- end
53
- end
54
- end
1
+ # frozen_string_literal: true
2
+ $stderr.puts "WARN: Ohai::Mixin::Command is deprecated, please use Ohai::Mixin::ShellOut or remove if the reference is unnecessary"
3
+ require_relative "shell_out"
4
+ Ohai::Mixin::Command = Ohai::Mixin::ShellOut unless defined?(Ohai::Mixin::Command)
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Serdar Sutay (<serdar@chef.io>)
3
- # Copyright:: Copyright (c) 2014-2016 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) Chef Software Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Tim Smith <tsmith@chef.io>
3
- # Copyright:: Copyright (c) 2015-2018 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) Chef Software Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  # Author:: Dylan Page (<dpage@digitalocean.com>)
3
4
  # License:: Apache License, Version 2.0
@@ -20,15 +21,15 @@ module Ohai
20
21
  module Mixin
21
22
  module DOMetadata
22
23
 
23
- DO_METADATA_ADDR ||= "169.254.169.254".freeze
24
- DO_METADATA_URL ||= "/metadata/v1.json".freeze
24
+ DO_METADATA_ADDR ||= "169.254.169.254"
25
+ DO_METADATA_URL ||= "/metadata/v1.json"
25
26
 
26
27
  def http_client
27
28
  Net::HTTP.start(DO_METADATA_ADDR).tap { |h| h.read_timeout = 6 }
28
29
  end
29
30
 
30
31
  def fetch_metadata
31
- uri = (DO_METADATA_URL).to_s
32
+ uri = DO_METADATA_URL.to_s
32
33
  response = http_client.get(uri)
33
34
  case response.code
34
35
  when "200"
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Tim Dysinger (<tim@dysinger.net>)
3
4
  # Author:: Benjamin Black (<bb@chef.io>)
4
5
  # Author:: Christopher Brown (<cb@chef.io>)
5
- # Copyright:: 2009-2017 Chef Software, Inc.
6
+ # Copyright:: Copyright (c) Chef Software Inc.
6
7
  # License:: Apache License, Version 2.0
7
8
  #
8
9
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,7 +40,7 @@ module Ohai
39
40
  #
40
41
  module Ec2Metadata
41
42
 
42
- EC2_METADATA_ADDR ||= "169.254.169.254".freeze
43
+ EC2_METADATA_ADDR ||= "169.254.169.254"
43
44
  EC2_SUPPORTED_VERSIONS ||= %w{ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15
44
45
  2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12
45
46
  2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02 }.freeze
@@ -142,7 +143,7 @@ module Ohai
142
143
  key = expand_path(o)
143
144
  if key[-1..-1] != "/"
144
145
  retr_meta = metadata_get("#{id}#{key}", api_version)
145
- metadata[metadata_key(key)] = retr_meta ? retr_meta : ""
146
+ metadata[metadata_key(key)] = retr_meta || ""
146
147
  elsif not key.eql?("/")
147
148
  metadata[key[0..-2]] = fetch_dir_metadata("#{id}#{key}", api_version)
148
149
  end
@@ -159,7 +160,7 @@ module Ohai
159
160
  key = expand_path(o)
160
161
  if key[-1..-1] != "/"
161
162
  retr_meta = metadata_get("#{id}#{key}", api_version)
162
- data = retr_meta ? retr_meta : ""
163
+ data = retr_meta || ""
163
164
  json = String(data)
164
165
  parser = FFI_Yajl::Parser.new
165
166
  metadata[metadata_key(key)] = parser.parse(json)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Ranjib Dey (<dey.ranjib@gmail.com>)
3
4
  # License:: Apache License, Version 2.0
@@ -21,8 +22,8 @@ module Ohai
21
22
  module GCEMetadata
22
23
 
23
24
  # Trailing dot to host is added to avoid DNS search path
24
- GCE_METADATA_ADDR ||= "metadata.google.internal.".freeze
25
- GCE_METADATA_URL ||= "/computeMetadata/v1/?recursive=true".freeze
25
+ GCE_METADATA_ADDR ||= "metadata.google.internal."
26
+ GCE_METADATA_URL ||= "/computeMetadata/v1/?recursive=true"
26
27
 
27
28
  # fetch the meta content with a timeout and the required header
28
29
  def http_get(uri)
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  #
2
- # Copyright:: 2017, Chef Software, Inc.
3
+ # Copyright:: Copyright (c) Chef Software Inc.
3
4
  # License:: Apache License, Version 2.0
4
5
  #
5
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Serdar Sutay (<serdar@chef.io>)
3
- # Copyright:: Copyright (c) 2014-2016 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) Chef Software Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) Chef Software Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,6 +28,71 @@ module Ohai
27
28
  #
28
29
  # @return [String] the OS
29
30
  def collect_os
31
+ if target_mode?
32
+ collect_os_target
33
+ else
34
+ collect_os_local
35
+ end
36
+ end
37
+
38
+ # This should exactly preserve the semantics of collect_os_local below, which is authoritative
39
+ # for the API and must adhere to pre-existing ohai semantics and not follow inspec's notion of
40
+ # os/family/hierarchy.
41
+ #
42
+ # Right or wrong the ohai `os` variable has matched the ruby `host_os` definition for the past
43
+ # 10+ years, preceding inspec/train's definitions and this is the documented correct API of
44
+ # these methods. Mismatches between the ruby notion and the train version will be fixed as
45
+ # bugfixes in these methods and may not be considered semver violating even though they make
46
+ # break downstream consumers. Please ensure that both methods produce the same results if
47
+ # you are on a platform which supports running ruby (train is considered authoritative for
48
+ # any "OS" which cannot run ruby -- server consoles, REST APIs, etc...)
49
+ #
50
+ # @api private
51
+ def collect_os_target
52
+ case
53
+ when transport_connection.os.aix?
54
+ "aix"
55
+ when transport_connection.os.darwin?
56
+ "darwin"
57
+ when transport_connection.os.linux?
58
+ "linux"
59
+ when transport_connection.os.family == "freebsd"
60
+ "freebsd"
61
+ when transport_connection.os.family == "openbsd"
62
+ "openbsd"
63
+ when transport_connection.os.family == "netbsd"
64
+ "netbsd"
65
+ when transport_connection.os.family == "dragonflybsd"
66
+ "dragonflybsd"
67
+ when transport_connection.os.solaris?
68
+ "solaris2"
69
+ when transport_connection.os.windows?
70
+ "windows"
71
+
72
+ #
73
+ # The purpose of the next two lines is that anything which runs Unix is presumed to be able to run ruby, and
74
+ # if it was not caught above, we MUST translate whatever train uses as the 'os' into the proper ruby host_os
75
+ # string. If it is not unix and not caught above we assume it is something like a REST API which cannot run
76
+ # ruby. If these assumptions are incorrect then it is a bug, which should be submitted to fix it, and the
77
+ # values should not be relied upon until that bug is fixed. The train os is NEVER considered authoritative
78
+ # for any target which can run ruby.
79
+ #
80
+ when transport_connection.os.unix?
81
+ raise "Target mode unsupported on this Unix-like host, please update the collect_os_target case statement with the correct ruby host_os value."
82
+ else
83
+ # now we have something like an IPMI console that isn't Unix-like or Windows, presumably cannot run ruby, and
84
+ # so we just trust the train O/S information.
85
+ transport_connection.os
86
+ end
87
+ end
88
+
89
+ # @api private
90
+ def nonruby_target?
91
+ transport_connection && !transport_connection.os.unix? && !transport_connection.os.windows
92
+ end
93
+
94
+ # @api private
95
+ def collect_os_local
30
96
  case ::RbConfig::CONFIG["host_os"]
31
97
  when /aix(.+)$/
32
98
  "aix"
@@ -56,7 +122,7 @@ module Ohai
56
122
  end
57
123
  end
58
124
 
59
- module_function :collect_os
125
+ extend self
60
126
  end
61
127
  end
62
128
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Jonathan Amiez (<jonathan.amiez@gmail.com>)
3
4
  # License:: Apache License, Version 2.0
@@ -20,8 +21,8 @@ module Ohai
20
21
  module Mixin
21
22
  module ScalewayMetadata
22
23
 
23
- SCALEWAY_METADATA_ADDR ||= "169.254.42.42".freeze
24
- SCALEWAY_METADATA_URL ||= "/conf?format=json".freeze
24
+ SCALEWAY_METADATA_ADDR ||= "169.254.42.42"
25
+ SCALEWAY_METADATA_URL ||= "/conf?format=json"
25
26
 
26
27
  # @return [Net::HTTP] net/http object without timeout set to 6
27
28
  def http_client
@@ -32,7 +33,7 @@ module Ohai
32
33
  #
33
34
  # @return [Hash]
34
35
  def fetch_metadata
35
- uri = (SCALEWAY_METADATA_URL).to_s
36
+ uri = SCALEWAY_METADATA_URL.to_s
36
37
  response = http_client.get(uri)
37
38
  case response.code
38
39
  when "200"
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) Chef Software Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Author:: Adam Jacob (<adam@chef.io>)
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ # Copyright:: Copyright (c) Chef Software Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require_relative "../exception"
22
+ require_relative "../log"
23
+
24
+ require "mixlib/shellout/helper" unless defined?(Mixlib::ShellOut::Helper)
25
+ require_relative "chef_utils_wiring" unless defined?(Ohai::Mixin::ChefUtilsWiring)
26
+
27
+ module Ohai
28
+ module Mixin
29
+ module ShellOut
30
+ include Mixlib::ShellOut::Helper
31
+ include Ohai::Mixin::ChefUtilsWiring
32
+
33
+ def shell_out(cmd, **options)
34
+ options = options.dup
35
+ # unless specified by the caller timeout after configured timeout (default 30 seconds)
36
+ options[:timeout] ||= Ohai::Config.ohai[:shellout_timeout]
37
+ begin
38
+ so = super(cmd, **options)
39
+ logger.trace("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}")
40
+ so
41
+ rescue Errno::ENOENT => e
42
+ logger.trace("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}")
43
+ raise Ohai::Exceptions::Exec, e
44
+ rescue Mixlib::ShellOut::CommandTimeout => e
45
+ logger.trace("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
46
+ raise Ohai::Exceptions::Exec, e
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Alexey Karpik <alexey.karpik@rightscale.com>
3
4
  # Author:: Peter Schroeter <peter.schroeter@rightscale.com>
@@ -22,7 +23,7 @@ require "uri" unless defined?(URI)
22
23
 
23
24
  # https://softlayer.github.io/reference/services/SoftLayer_Resource_Metadata/
24
25
  module ::Ohai::Mixin::SoftlayerMetadata
25
- SOFTLAYER_API_QUERY_URL ||= "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata".freeze
26
+ SOFTLAYER_API_QUERY_URL ||= "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata"
26
27
 
27
28
  # fetch metadata items and build out hash of data
28
29
  #
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: James Gartrell (<jgartrel@gmail.com>)
3
- # Copyright:: Copyright (c) 2009-2016 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) Chef Software Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require "chef-utils/dsl/train_helpers" unless defined?(ChefUtils::DSL::TrainHelpers)
19
+ require_relative "chef_utils_wiring" unless defined?(Ohai::Mixin::ChefUtilsWiring)
20
+
21
+ module Ohai
22
+ module Mixin
23
+ module TrainHelpers
24
+ include ChefUtils::DSL::TrainHelpers
25
+ include ChefUtilsWiring
26
+
27
+ # anything added to this file temporarily should be pushed back up
28
+ # into ChefUtils::DSL::TrainHelpers
29
+
30
+ # XXX: this needs better support directly in train
31
+ def dir_glob(path)
32
+ shell_out!("ls -d #{path}").stdout.split
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require "chef-utils/dsl/which" unless defined?(ChefUtils::DSL::Which)
19
+ require "chef-utils/dsl/default_paths" unless defined?(ChefUtils::DSL::DefaultPaths)
20
+ require_relative "chef_utils_wiring" unless defined?(Ohai::Mixin::ChefUtilsWiring)
21
+
22
+ module Ohai
23
+ module Mixin
24
+ module Which
25
+ include ChefUtils::DSL::Which
26
+ include ChefUtils::DSL::DefaultPaths
27
+ include ChefUtilsWiring
28
+
29
+ private
30
+
31
+ # we dep-inject default paths into this API for historical reasons
32
+ #
33
+ # @api private
34
+ def __extra_path
35
+ __default_paths
36
+ end
37
+ end
38
+ end
39
+ end