ohai 16.4.11 → 16.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +11 -6
- data/bin/ohai +1 -1
- data/lib/ohai.rb +1 -1
- data/lib/ohai/application.rb +39 -0
- data/lib/ohai/common/dmi.rb +7 -3
- data/lib/ohai/config.rb +2 -3
- data/lib/ohai/dsl.rb +1 -1
- data/lib/ohai/dsl/plugin.rb +12 -5
- data/lib/ohai/dsl/plugin/versionvii.rb +28 -16
- data/lib/ohai/exception.rb +1 -1
- data/lib/ohai/hints.rb +1 -1
- data/lib/ohai/loader.rb +1 -1
- data/lib/ohai/log.rb +1 -1
- data/lib/ohai/mixin/azure_metadata.rb +1 -1
- data/lib/ohai/mixin/chef_utils_wiring.rb +51 -0
- data/lib/ohai/mixin/command.rb +3 -54
- data/lib/ohai/mixin/constant_helper.rb +1 -1
- data/lib/ohai/mixin/dmi_decode.rb +1 -1
- data/lib/ohai/mixin/do_metadata.rb +1 -1
- data/lib/ohai/mixin/ec2_metadata.rb +3 -3
- data/lib/ohai/mixin/http_helper.rb +1 -1
- data/lib/ohai/mixin/network_helper.rb +1 -1
- data/lib/ohai/mixin/os.rb +67 -2
- data/lib/ohai/mixin/scaleway_metadata.rb +1 -1
- data/lib/ohai/mixin/seconds_to_human.rb +1 -1
- data/lib/ohai/mixin/shell_out.rb +50 -0
- data/lib/ohai/mixin/string.rb +1 -1
- data/lib/ohai/mixin/train_helpers.rb +35 -0
- data/lib/ohai/mixin/which.rb +38 -0
- data/lib/ohai/plugin_config.rb +1 -1
- data/lib/ohai/plugins/aix/kernel.rb +1 -1
- data/lib/ohai/plugins/aix/memory.rb +3 -3
- data/lib/ohai/plugins/aix/network.rb +1 -1
- data/lib/ohai/plugins/aix/platform.rb +1 -1
- data/lib/ohai/plugins/aix/uptime.rb +1 -1
- data/lib/ohai/plugins/aix/virtualization.rb +1 -1
- data/lib/ohai/plugins/azure.rb +25 -5
- data/lib/ohai/plugins/bsd/virtualization.rb +3 -3
- data/lib/ohai/plugins/chef.rb +1 -1
- data/lib/ohai/plugins/cloud.rb +1 -1
- data/lib/ohai/plugins/command.rb +1 -1
- data/lib/ohai/plugins/cpu.rb +6 -6
- data/lib/ohai/plugins/darwin/memory.rb +1 -1
- data/lib/ohai/plugins/darwin/network.rb +1 -1
- data/lib/ohai/plugins/darwin/platform.rb +2 -2
- data/lib/ohai/plugins/darwin/virtualization.rb +2 -2
- data/lib/ohai/plugins/dmi.rb +1 -1
- data/lib/ohai/plugins/docker.rb +1 -1
- data/lib/ohai/plugins/ec2.rb +15 -9
- data/lib/ohai/plugins/erlang.rb +1 -1
- data/lib/ohai/plugins/eucalyptus.rb +1 -1
- data/lib/ohai/plugins/filesystem.rb +4 -4
- data/lib/ohai/plugins/fips.rb +1 -1
- data/lib/ohai/plugins/gce.rb +2 -2
- data/lib/ohai/plugins/hostname.rb +1 -1
- data/lib/ohai/plugins/init_package.rb +2 -2
- data/lib/ohai/plugins/java.rb +1 -1
- data/lib/ohai/plugins/joyent.rb +2 -2
- data/lib/ohai/plugins/kernel.rb +9 -5
- data/lib/ohai/plugins/keys.rb +1 -1
- data/lib/ohai/plugins/languages.rb +1 -1
- data/lib/ohai/plugins/libvirt.rb +1 -1
- data/lib/ohai/plugins/linode.rb +1 -1
- data/lib/ohai/plugins/linux/block_device.rb +9 -9
- data/lib/ohai/plugins/linux/interrupts.rb +3 -3
- data/lib/ohai/plugins/linux/ipc.rb +1 -1
- data/lib/ohai/plugins/linux/lsb.rb +4 -4
- data/lib/ohai/plugins/linux/machineid.rb +4 -4
- data/lib/ohai/plugins/linux/mdadm.rb +2 -2
- data/lib/ohai/plugins/linux/memory.rb +2 -2
- data/lib/ohai/plugins/linux/network.rb +13 -13
- data/lib/ohai/plugins/linux/platform.rb +30 -30
- data/lib/ohai/plugins/linux/virtualization.rb +24 -24
- data/lib/ohai/plugins/network.rb +1 -1
- data/lib/ohai/plugins/ohai_time.rb +2 -2
- data/lib/ohai/plugins/openstack.rb +1 -1
- data/lib/ohai/plugins/os.rb +5 -1
- data/lib/ohai/plugins/packages.rb +20 -0
- data/lib/ohai/plugins/passwd.rb +57 -1
- data/lib/ohai/plugins/perl.rb +1 -1
- data/lib/ohai/plugins/platform.rb +1 -1
- data/lib/ohai/plugins/powershell.rb +1 -1
- data/lib/ohai/plugins/ps.rb +1 -1
- data/lib/ohai/plugins/python.rb +1 -1
- data/lib/ohai/plugins/rackspace.rb +2 -2
- data/lib/ohai/plugins/scaleway.rb +1 -1
- data/lib/ohai/plugins/shard.rb +1 -1
- data/lib/ohai/plugins/shells.rb +3 -3
- data/lib/ohai/plugins/softlayer.rb +1 -1
- data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
- data/lib/ohai/plugins/solaris2/network.rb +6 -8
- data/lib/ohai/plugins/solaris2/platform.rb +3 -3
- data/lib/ohai/plugins/solaris2/virtualization.rb +2 -2
- data/lib/ohai/plugins/ssh_host_key.rb +13 -13
- data/lib/ohai/plugins/train.rb +35 -0
- data/lib/ohai/plugins/uptime.rb +2 -2
- data/lib/ohai/plugins/virtualbox.rb +1 -1
- data/lib/ohai/plugins/vmware.rb +2 -2
- data/lib/ohai/plugins/windows/drivers.rb +1 -1
- data/lib/ohai/plugins/windows/network.rb +2 -2
- data/lib/ohai/plugins/windows/platform.rb +1 -1
- data/lib/ohai/plugins/windows/system_enclosure.rb +1 -1
- data/lib/ohai/plugins/windows/virtualization.rb +1 -1
- data/lib/ohai/plugins/zpools.rb +1 -1
- data/lib/ohai/provides_map.rb +1 -1
- data/lib/ohai/runner.rb +5 -1
- data/lib/ohai/system.rb +34 -7
- data/lib/ohai/train_transport.rb +28 -0
- data/lib/ohai/util/file_helper.rb +4 -37
- data/lib/ohai/util/win32.rb +1 -1
- data/lib/ohai/version.rb +3 -3
- data/ohai.gemspec +7 -7
- metadata +80 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86cf0dbd863325b1c5104d78cb1b848d924bfc1c67375df2f42d4cc855cccf1a
|
4
|
+
data.tar.gz: 20131622886b909b75708612f8340e59366f9d74b109f4f4176e34b6578f750c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 142be9e566d266d83e0561a662e5170c5d4b497d044279b51360393c9956004a4217ef5a3151d93f139fcd30fd9c6c07c35c9dde5d4e8b53c6b91532d3b884ce
|
7
|
+
data.tar.gz: 30d6872cb01724ae5bc88f1f65aa7b5693a47502be8f94492c28367c8408cd1fe82278efd1dc3e70ff9cbb83ea9ba9bd74ff4be2a850c9bf764b33c17d19297a
|
data/Gemfile
CHANGED
@@ -2,22 +2,27 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
# pull these gems from master of chef/chef so that we're testing against what we will release
|
6
|
+
gem "chef-config", git: "https://github.com/chef/chef", glob: "chef-config/chef-config.gemspec"
|
7
|
+
gem "chef-utils", git: "https://github.com/chef/chef", glob: "chef-utils/chef-utils.gemspec"
|
8
|
+
|
5
9
|
# NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local
|
6
10
|
group :development do
|
7
11
|
gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
|
8
|
-
gem "
|
12
|
+
gem "ipaddr_extensions"
|
9
13
|
gem "rake", ">= 10.1.0"
|
14
|
+
gem "rspec-collection_matchers", "~> 1.0"
|
10
15
|
gem "rspec-core", "~> 3.0"
|
11
16
|
gem "rspec-expectations", "~> 3.0"
|
12
17
|
gem "rspec-mocks", "~> 3.0"
|
13
|
-
gem "
|
14
|
-
gem "
|
18
|
+
gem "rubocop-performance", "1.8.1"
|
19
|
+
gem "rubocop-rspec"
|
15
20
|
end
|
16
21
|
|
17
22
|
group :docs do
|
18
|
-
gem "yard"
|
19
|
-
gem "redcarpet"
|
20
23
|
gem "github-markup"
|
24
|
+
gem "redcarpet"
|
25
|
+
gem "yard"
|
21
26
|
end
|
22
27
|
|
23
28
|
group :debug do
|
@@ -25,4 +30,4 @@ group :debug do
|
|
25
30
|
gem "pry-byebug"
|
26
31
|
gem "pry-stack_explorer", "~> 0.4.0" # pin until we drop ruby < 2.6
|
27
32
|
gem "rb-readline"
|
28
|
-
end
|
33
|
+
end
|
data/bin/ohai
CHANGED
data/lib/ohai.rb
CHANGED
data/lib/ohai/application.rb
CHANGED
@@ -56,6 +56,15 @@ class Ohai::Application
|
|
56
56
|
description: "Set the log file location, defaults to STDOUT - recommended for daemonizing",
|
57
57
|
proc: nil
|
58
58
|
|
59
|
+
option :target,
|
60
|
+
short: "-t TARGET",
|
61
|
+
long: "--target TARGET",
|
62
|
+
description: "Target Ohai against a remote system or device",
|
63
|
+
proc: lambda { |target|
|
64
|
+
Ohai::Log.warn "-- EXPERIMENTAL -- Target mode activated -- EXPERIMENTAL --"
|
65
|
+
target
|
66
|
+
}
|
67
|
+
|
59
68
|
option :help,
|
60
69
|
short: "-h",
|
61
70
|
long: "--help",
|
@@ -93,9 +102,39 @@ class Ohai::Application
|
|
93
102
|
|
94
103
|
load_workstation_config
|
95
104
|
|
105
|
+
merge_configs
|
106
|
+
|
107
|
+
if config[:target]
|
108
|
+
Ohai::Config.target_mode.host = config[:target]
|
109
|
+
if URI.parse(Ohai::Config.target_mode.host).scheme
|
110
|
+
train_config = Train.unpack_target_from_uri(Ohai::Config.target_mode.host)
|
111
|
+
Ohai::Config.target_mode = train_config
|
112
|
+
end
|
113
|
+
Ohai::Config.target_mode.enabled = true
|
114
|
+
Ohai::Config.node_name = Ohai::Config.target_mode.host unless Ohai::Config.node_name
|
115
|
+
end
|
116
|
+
|
96
117
|
Ohai::Log.init(Ohai.config[:log_location])
|
97
118
|
end
|
98
119
|
|
120
|
+
# @api private
|
121
|
+
def config_file_defaults
|
122
|
+
Ohai::Config.save(true)
|
123
|
+
end
|
124
|
+
|
125
|
+
# @api private
|
126
|
+
def config_file_settings
|
127
|
+
Ohai::Config.save(false)
|
128
|
+
end
|
129
|
+
|
130
|
+
# See lib/chef/knife.rb in the chef/chef github repo
|
131
|
+
#
|
132
|
+
# @api private
|
133
|
+
def merge_configs
|
134
|
+
config.replace(config_file_defaults.merge(default_config).merge(config_file_settings).merge(config))
|
135
|
+
Ohai::Config.merge!(config) # make them both the same
|
136
|
+
end
|
137
|
+
|
99
138
|
# Passes config and attributes arguments to Ohai::System then prints the results.
|
100
139
|
# Called by the run method after config / logging have been initialized
|
101
140
|
#
|
data/lib/ohai/common/dmi.rb
CHANGED
@@ -76,11 +76,11 @@ module Ohai
|
|
76
76
|
# away some of the less useful IDs
|
77
77
|
ID_TO_CAPTURE = [ 0, 1, 2, 3, 4, 6, 11 ].freeze
|
78
78
|
|
79
|
-
# the
|
79
|
+
# the allowlisted DMI IDs. This is combination of the defaults + any additional
|
80
80
|
# IDs defined in the :additional_dmi_ids config
|
81
81
|
#
|
82
82
|
# @return [Array] the list of DMI IDs to capture
|
83
|
-
def
|
83
|
+
def allowlisted_ids
|
84
84
|
if Ohai.config[:additional_dmi_ids]
|
85
85
|
if [ Integer, Array ].include?(Ohai.config[:additional_dmi_ids].class)
|
86
86
|
return ID_TO_CAPTURE + Array(Ohai.config[:additional_dmi_ids])
|
@@ -91,6 +91,10 @@ module Ohai
|
|
91
91
|
ID_TO_CAPTURE
|
92
92
|
end
|
93
93
|
|
94
|
+
##
|
95
|
+
# @deprecated Use the `allowlisted_ids` method instead.
|
96
|
+
alias whitelisted_ids allowlisted_ids
|
97
|
+
|
94
98
|
# the human readable description from a DMI ID
|
95
99
|
#
|
96
100
|
# @param id [String, Integer] the ID to lookup
|
@@ -152,7 +156,7 @@ module Ohai
|
|
152
156
|
end
|
153
157
|
end
|
154
158
|
|
155
|
-
module_function :id_lookup, :convenience_keys, :whitelisted_ids
|
159
|
+
module_function :id_lookup, :convenience_keys, :allowlisted_ids, :whitelisted_ids
|
156
160
|
end
|
157
161
|
end
|
158
162
|
end
|
data/lib/ohai/config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
3
|
# Author:: Claire McQuin (<claire@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) 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");
|
@@ -27,14 +27,13 @@ module Ohai
|
|
27
27
|
# Reopens ChefConfig::Config to add Ohai configuration settings.
|
28
28
|
# see: https://github.com/chef/chef/blob/master/lib/chef/config.rb
|
29
29
|
class Config
|
30
|
-
|
31
30
|
config_context :ohai do
|
32
31
|
default :disabled_plugins, []
|
33
32
|
default :hints_path, [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ]
|
34
33
|
default :log_level, :auto
|
35
34
|
default :log_location, STDERR
|
36
35
|
default :plugin, ( Ohai::PluginConfig.new { |h, k| h[k] = Ohai::PluginConfig.new } )
|
37
|
-
default :plugin_path, [ File.expand_path(File.join(
|
36
|
+
default :plugin_path, [ File.expand_path(File.join(__dir__, "plugins")), ChefConfig::Config.platform_specific_path("/etc/chef/ohai/plugins") ]
|
38
37
|
default :critical_plugins, []
|
39
38
|
# causes all optional plugins to be run.
|
40
39
|
default :run_all_plugins, false
|
data/lib/ohai/dsl.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Serdar Sutay (<serdar@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) 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");
|
data/lib/ohai/dsl/plugin.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
3
|
# Author:: Claire McQuin (<claire@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) 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");
|
@@ -19,10 +19,11 @@
|
|
19
19
|
#
|
20
20
|
|
21
21
|
require_relative "../mixin/os"
|
22
|
-
require_relative "../mixin/
|
22
|
+
require_relative "../mixin/shell_out"
|
23
23
|
require_relative "../mixin/seconds_to_human"
|
24
|
+
require_relative "../mixin/which"
|
25
|
+
require_relative "../mixin/train_helpers"
|
24
26
|
require_relative "../hints"
|
25
|
-
require_relative "../util/file_helper"
|
26
27
|
|
27
28
|
module Ohai
|
28
29
|
|
@@ -83,13 +84,15 @@ module Ohai
|
|
83
84
|
class Plugin
|
84
85
|
|
85
86
|
include Ohai::Mixin::OS
|
86
|
-
include Ohai::Mixin::
|
87
|
+
include Ohai::Mixin::ShellOut
|
87
88
|
include Ohai::Mixin::SecondsToHuman
|
88
|
-
include Ohai::
|
89
|
+
include Ohai::Mixin::Which
|
90
|
+
include Ohai::Mixin::TrainHelpers
|
89
91
|
|
90
92
|
attr_reader :data
|
91
93
|
attr_reader :failed
|
92
94
|
attr_reader :logger
|
95
|
+
attr_accessor :transport_connection
|
93
96
|
|
94
97
|
def initialize(data, logger)
|
95
98
|
@data = data
|
@@ -98,6 +101,10 @@ module Ohai
|
|
98
101
|
@failed = false
|
99
102
|
end
|
100
103
|
|
104
|
+
def target_mode?
|
105
|
+
!!@transport_connection
|
106
|
+
end
|
107
|
+
|
101
108
|
def run
|
102
109
|
@has_run = true
|
103
110
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Serdar Sutay (<serdar@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) 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");
|
@@ -46,7 +46,8 @@ module Ohai
|
|
46
46
|
:version7
|
47
47
|
end
|
48
48
|
|
49
|
-
#
|
49
|
+
# The source of the plugin on disk. This is an array since a plugin may exist for multiple
|
50
|
+
# oses and this would include each of those os specific file paths
|
50
51
|
#
|
51
52
|
# @return [Array]
|
52
53
|
def self.sources
|
@@ -61,7 +62,7 @@ module Ohai
|
|
61
62
|
@depends_attrs ||= []
|
62
63
|
end
|
63
64
|
|
64
|
-
# A block per
|
65
|
+
# A block per os for actually performing data collection constructed
|
65
66
|
# by the collect_data method
|
66
67
|
#
|
67
68
|
# @return [Mash]
|
@@ -101,15 +102,16 @@ module Ohai
|
|
101
102
|
!!@optional
|
102
103
|
end
|
103
104
|
|
104
|
-
# define data collection methodology per
|
105
|
+
# define data collection methodology per os
|
105
106
|
#
|
106
|
-
# @param
|
107
|
-
# @param
|
108
|
-
#
|
109
|
-
def self.collect_data(
|
110
|
-
[
|
111
|
-
|
112
|
-
|
107
|
+
# @param os [Array<Symbol>] the list of oses to collect data for
|
108
|
+
# @param block [block] the actual code to collect data for the specified os
|
109
|
+
#
|
110
|
+
def self.collect_data(*os_list, &block)
|
111
|
+
os_list = [ :default ] if os_list.empty?
|
112
|
+
os_list.flatten.each do |os|
|
113
|
+
Ohai::Log.warn("collect_data already defined on os '#{os}' for #{self}, last plugin seen will be used") if data_collector.key?(os)
|
114
|
+
data_collector[os] = block
|
113
115
|
end
|
114
116
|
end
|
115
117
|
|
@@ -120,12 +122,22 @@ module Ohai
|
|
120
122
|
|
121
123
|
def run_plugin
|
122
124
|
collector = self.class.data_collector
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
os = collect_os
|
126
|
+
|
127
|
+
# :default - means any remote or local unix or windows host
|
128
|
+
# :target - means any remote API which is not unix/windows or otherwise rubyable (cisco switches, IPMI console, HTTP API, etc)
|
129
|
+
#
|
130
|
+
# Do not be confused by the fact that collectors tagged :target do not run against e.g. target-mode ubuntu boxes, that is not
|
131
|
+
# what :target is intended for. Also, do not be confused by the fact that collectors tagged :default do not run by default against
|
132
|
+
# pure-target mode targets like switches. That is all intended behavior, the names are problematic. The :default nomenclature was
|
133
|
+
# invented 10 years before target mode and we are stuck with it.
|
134
|
+
#
|
135
|
+
if collector.key?(os)
|
136
|
+
instance_eval(&collector[os])
|
137
|
+
elsif collector.key?(:default) && !nonruby_target?
|
128
138
|
instance_eval(&collector[:default])
|
139
|
+
elsif collector.key?(:target) && nonruby_target?
|
140
|
+
instance_eval(&collector[:target])
|
129
141
|
else
|
130
142
|
logger.trace("Plugin #{name}: No data to collect. Skipping...")
|
131
143
|
end
|
data/lib/ohai/exception.rb
CHANGED
data/lib/ohai/hints.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Serdar Sutay (<serdar@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) 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");
|
data/lib/ohai/loader.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Claire McQuin (<claire@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) 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");
|
data/lib/ohai/log.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
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
|
+
|
18
|
+
require_relative "../config"
|
19
|
+
require "singleton" unless defined?(Singleton)
|
20
|
+
|
21
|
+
module Ohai
|
22
|
+
module Mixin
|
23
|
+
# Common Dependency Injection wiring for ChefUtils-related modules
|
24
|
+
module ChefUtilsWiring
|
25
|
+
private
|
26
|
+
|
27
|
+
def __config
|
28
|
+
Ohai::Config
|
29
|
+
end
|
30
|
+
|
31
|
+
def __log
|
32
|
+
logger
|
33
|
+
end
|
34
|
+
|
35
|
+
def __transport_connection
|
36
|
+
transport_connection
|
37
|
+
end
|
38
|
+
|
39
|
+
# because of target mode we cache the PATH to avoid massive amounts of `echo $PATH` remote queries
|
40
|
+
#
|
41
|
+
def __env_path
|
42
|
+
PathCache.instance.path_cache ||= super
|
43
|
+
end
|
44
|
+
|
45
|
+
class PathCache
|
46
|
+
include Singleton
|
47
|
+
attr_accessor :path_cache
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/ohai/mixin/command.rb
CHANGED
@@ -1,54 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
+
$stderr.puts "WARN: Ohai::Mixin::Command is deprecated, please use Ohai::Mixin::ShellOut or remove if the reference is unnecessary"
|
2
|
+
require_relative "shell_out"
|
3
|
+
Ohai::Mixin::Command = Ohai::Mixin::ShellOut unless defined?(Ohai::Mixin::Command)
|