summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-09 17:04:30 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-09 17:04:30 -0700
commit691d6cb53709e1ed2d4c2e7551d0d9747001acde (patch)
tree3c5786de48953753425c3cb8e5f267c9d17ac841 /lib
parent157fa672190a4793429bf4c11043e010bf86e5ca (diff)
downloadohai-691d6cb53709e1ed2d4c2e7551d0d9747001acde.tar.gz
Gate more of the external requires
Decreases memory usage slightly Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/ohai/application.rb4
-rw-r--r--lib/ohai/log.rb2
-rw-r--r--lib/ohai/mixin/os.rb2
-rw-r--r--lib/ohai/plugins/aix/network.rb2
-rw-r--r--lib/ohai/plugins/aix/uptime.rb2
-rw-r--r--lib/ohai/plugins/cloud.rb2
-rw-r--r--lib/ohai/plugins/cpu.rb2
-rw-r--r--lib/ohai/plugins/docker.rb2
-rw-r--r--lib/ohai/plugins/ec2.rb2
-rw-r--r--lib/ohai/plugins/filesystem.rb2
-rw-r--r--lib/ohai/plugins/gce.rb2
-rw-r--r--lib/ohai/plugins/hostname.rb4
-rw-r--r--lib/ohai/plugins/kernel.rb2
-rw-r--r--lib/ohai/plugins/linux/network.rb2
-rw-r--r--lib/ohai/plugins/network.rb2
-rw-r--r--lib/ohai/plugins/packages.rb2
-rw-r--r--lib/ohai/plugins/rackspace.rb2
-rw-r--r--lib/ohai/plugins/root_group.rb2
-rw-r--r--lib/ohai/plugins/shard.rb2
-rw-r--r--lib/ohai/plugins/uptime.rb2
-rw-r--r--lib/ohai/plugins/windows/dmi.rb2
-rw-r--r--lib/ohai/plugins/windows/drivers.rb2
-rw-r--r--lib/ohai/plugins/windows/memory.rb2
-rw-r--r--lib/ohai/plugins/windows/network.rb2
-rw-r--r--lib/ohai/plugins/windows/virtualization.rb2
-rw-r--r--lib/ohai/runner.rb2
-rw-r--r--lib/ohai/util/ip_helper.rb2
27 files changed, 29 insertions, 29 deletions
diff --git a/lib/ohai/application.rb b/lib/ohai/application.rb
index cdbac369..49b7d5e9 100644
--- a/lib/ohai/application.rb
+++ b/lib/ohai/application.rb
@@ -18,9 +18,9 @@
require "chef-config/path_helper"
require "chef-config/workstation_config_loader"
require_relative "../ohai"
-require_relative "log"
+require_relative "log" unless defined?(Ohai::Log)
require "mixlib/cli" unless defined?(Mixlib::CLI)
-require "benchmark"
+require "benchmark" unless defined?(Benchmark)
# The Application class is what is called by the Ohai CLI binary. It handles:
# - CLI options and attribute arguments
diff --git a/lib/ohai/log.rb b/lib/ohai/log.rb
index 6cf0ec2e..44e4daa3 100644
--- a/lib/ohai/log.rb
+++ b/lib/ohai/log.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-require "mixlib/log"
+require "mixlib/log" unless defined?(Mixlib::Log)
module Ohai
# the Ohai Logger which is just Mixlib::Log defaulting to STDERR and :info level
diff --git a/lib/ohai/mixin/os.rb b/lib/ohai/mixin/os.rb
index f4d4dd9f..44b790be 100644
--- a/lib/ohai/mixin/os.rb
+++ b/lib/ohai/mixin/os.rb
@@ -17,7 +17,7 @@
# limitations under the License.
#
-require "rbconfig"
+require "rbconfig" unless defined?(RbConfig)
module Ohai
module Mixin
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb
index c0d5fb77..de9dd101 100644
--- a/lib/ohai/plugins/aix/network.rb
+++ b/lib/ohai/plugins/aix/network.rb
@@ -19,7 +19,7 @@
#
Ohai.plugin(:Network) do
- require "ipaddr"
+ require "ipaddr" unless defined?(IPAddr)
require_relative "../../mixin/network_helper"
provides "network", "counters/network", "macaddress"
diff --git a/lib/ohai/plugins/aix/uptime.rb b/lib/ohai/plugins/aix/uptime.rb
index 470429ce..11840d88 100644
--- a/lib/ohai/plugins/aix/uptime.rb
+++ b/lib/ohai/plugins/aix/uptime.rb
@@ -21,7 +21,7 @@ Ohai.plugin(:Uptime) do
provides "uptime", "uptime_seconds"
collect_data(:aix) do
- require "date"
+ require "date" unless defined?(DateTime)
# below we're going to assume that PID 1 is init (this is true 99.99999% of the time)
# output will look like this
# 1148-20:54:50
diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb
index 45e5f8c5..d6df2571 100644
--- a/lib/ohai/plugins/cloud.rb
+++ b/lib/ohai/plugins/cloud.rb
@@ -320,7 +320,7 @@ Ohai.plugin(:Cloud) do
end
collect_data do
- require "ipaddr"
+ require "ipaddr" unless defined?(IPAddr)
@cloud_attr_obj = CloudAttrs.new
diff --git a/lib/ohai/plugins/cpu.rb b/lib/ohai/plugins/cpu.rb
index a33084de..3569935e 100644
--- a/lib/ohai/plugins/cpu.rb
+++ b/lib/ohai/plugins/cpu.rb
@@ -377,7 +377,7 @@ Ohai.plugin(:CPU) do
end
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
cpu Mash.new
cores = 0
diff --git a/lib/ohai/plugins/docker.rb b/lib/ohai/plugins/docker.rb
index 6bea2ace..421c7243 100644
--- a/lib/ohai/plugins/docker.rb
+++ b/lib/ohai/plugins/docker.rb
@@ -16,7 +16,7 @@
#
Ohai.plugin(:Docker) do
- require "json"
+ require "json" unless defined?(JSON)
provides "docker"
depends "virtualization"
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb
index 82064365..6aa262f1 100644
--- a/lib/ohai/plugins/ec2.rb
+++ b/lib/ohai/plugins/ec2.rb
@@ -82,7 +82,7 @@ Ohai.plugin(:EC2) do
# @return [Boolean] do we have a Xen Identifying Number or not?
def has_ec2_identifying_number?
if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
wmi = WmiLite::Wmi.new
if /^ec2/.match?(wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"])
logger.trace("Plugin EC2: has_ec2_identifying_number? == true")
diff --git a/lib/ohai/plugins/filesystem.rb b/lib/ohai/plugins/filesystem.rb
index 77b77bad..85eb6ad7 100644
--- a/lib/ohai/plugins/filesystem.rb
+++ b/lib/ohai/plugins/filesystem.rb
@@ -718,7 +718,7 @@ Ohai.plugin(:Filesystem) do
end
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
require_relative "../mash"
fs = merge_info(logical_info, encryptable_info)
diff --git a/lib/ohai/plugins/gce.rb b/lib/ohai/plugins/gce.rb
index f8c30b32..db336dfe 100644
--- a/lib/ohai/plugins/gce.rb
+++ b/lib/ohai/plugins/gce.rb
@@ -49,7 +49,7 @@ Ohai.plugin(:GCE) do
# @return [Boolean] Are the manufacturer and model Google?
def has_gce_system_info?
if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
wmi = WmiLite::Wmi.new
computer_system = wmi.first_of("Win32_ComputerSystem")
if computer_system["Manufacturer"] =~ /^Google/ && computer_system["Model"] =~ /^Google/
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index f4f95054..177cfcad 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -27,7 +27,7 @@
Ohai.plugin(:Hostname) do
require "socket" unless defined?(Socket)
- require "ipaddr"
+ require "ipaddr" unless defined?(IPAddr)
provides "domain", "hostname", "fqdn", "machinename"
@@ -161,7 +161,7 @@ Ohai.plugin(:Hostname) do
end
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
require "socket" unless defined?(Socket)
wmi = WmiLite::Wmi.new
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb
index 7dc273fa..0b106026 100644
--- a/lib/ohai/plugins/kernel.rb
+++ b/lib/ohai/plugins/kernel.rb
@@ -252,7 +252,7 @@ Ohai.plugin(:Kernel) do
collect_data(:windows) do
require "win32ole" unless defined?(WIN32OLE)
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
WIN32OLE.codepage = WIN32OLE::CP_UTF8
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 7d0d2de8..b38df361 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -577,7 +577,7 @@ Ohai.plugin(:Network) do
# If the 'ip' binary is available, this plugin may set {ip,mac,ip6}address. The network plugin should not overwrite these.
# The older code section below that relies on the deprecated net-tools, e.g. netstat and ifconfig, provides less functionality.
collect_data(:linux) do
- require "ipaddr"
+ require "ipaddr" unless defined?(IPAddr)
iface = Mash.new
net_counters = Mash.new
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb
index c1b15ced..74990bea 100644
--- a/lib/ohai/plugins/network.rb
+++ b/lib/ohai/plugins/network.rb
@@ -17,7 +17,7 @@
#
Ohai.plugin(:NetworkAddresses) do
- require "ipaddress"
+ require "ipaddress" unless defined?(IPAddress)
require_relative "../mixin/network_helper"
include Ohai::Mixin::NetworkHelper
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb
index f9653dbf..098a3126 100644
--- a/lib/ohai/plugins/packages.rb
+++ b/lib/ohai/plugins/packages.rb
@@ -79,7 +79,7 @@ Ohai.plugin(:Packages) do
end
when "arch"
- require "date"
+ require "date" unless defined?(DateTime)
# Set LANG=C to force an easy to parse date format
so = shell_out("LANG=C pacman -Qi")
diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb
index ccec304f..3f4e8339 100644
--- a/lib/ohai/plugins/rackspace.rb
+++ b/lib/ohai/plugins/rackspace.rb
@@ -50,7 +50,7 @@ Ohai.plugin(:Rackspace) do
def has_rackspace_manufacturer?
return false unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
wmi = WmiLite::Wmi.new
if wmi.first_of("Win32_ComputerSystem")["PrimaryOwnerName"] == "Rackspace"
logger.trace("Plugin Rackspace: has_rackspace_manufacturer? == true")
diff --git a/lib/ohai/plugins/root_group.rb b/lib/ohai/plugins/root_group.rb
index ea1af938..28dba9bb 100644
--- a/lib/ohai/plugins/root_group.rb
+++ b/lib/ohai/plugins/root_group.rb
@@ -19,7 +19,7 @@ Ohai.plugin(:RootGroup) do
provides "root_group"
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
wmi = WmiLite::Wmi.new
# Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
diff --git a/lib/ohai/plugins/shard.rb b/lib/ohai/plugins/shard.rb
index 259bdc6b..cf7641b0 100644
--- a/lib/ohai/plugins/shard.rb
+++ b/lib/ohai/plugins/shard.rb
@@ -94,7 +94,7 @@ Ohai.plugin(:ShardSeed) do
end
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
wmi = WmiLite::Wmi.new
create_seed do |src|
diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb
index 5883f13c..dafdfaea 100644
--- a/lib/ohai/plugins/uptime.rb
+++ b/lib/ohai/plugins/uptime.rb
@@ -84,7 +84,7 @@ Ohai.plugin(:Uptime) do
end
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
wmi = WmiLite::Wmi.new
last_boot_up_time = wmi.first_of("Win32_OperatingSystem")["lastbootuptime"]
uptime_seconds Time.new.to_i - Time.parse(last_boot_up_time).to_i
diff --git a/lib/ohai/plugins/windows/dmi.rb b/lib/ohai/plugins/windows/dmi.rb
index eea5b37f..d0d6cdd8 100644
--- a/lib/ohai/plugins/windows/dmi.rb
+++ b/lib/ohai/plugins/windows/dmi.rb
@@ -46,7 +46,7 @@ Ohai.plugin(:DMI) do
collect_data(:windows) do
require "ohai/common/dmi"
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
wmi = WmiLite::Wmi.new
dmi Mash.new
diff --git a/lib/ohai/plugins/windows/drivers.rb b/lib/ohai/plugins/windows/drivers.rb
index 425d33dc..d9fb41fc 100644
--- a/lib/ohai/plugins/windows/drivers.rb
+++ b/lib/ohai/plugins/windows/drivers.rb
@@ -22,7 +22,7 @@ Ohai.plugin(:Drivers) do
collect_data(:windows) do
if configuration(:enabled)
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
kext = Mash.new
pnp_drivers = Mash.new
diff --git a/lib/ohai/plugins/windows/memory.rb b/lib/ohai/plugins/windows/memory.rb
index e0bb46f0..b8bd84a1 100644
--- a/lib/ohai/plugins/windows/memory.rb
+++ b/lib/ohai/plugins/windows/memory.rb
@@ -17,7 +17,7 @@ Ohai.plugin(:Memory) do
provides "memory"
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
memory Mash.new
memory[:swap] = Mash.new
diff --git a/lib/ohai/plugins/windows/network.rb b/lib/ohai/plugins/windows/network.rb
index d44d6079..2b8fdd62 100644
--- a/lib/ohai/plugins/windows/network.rb
+++ b/lib/ohai/plugins/windows/network.rb
@@ -118,7 +118,7 @@ Ohai.plugin(:Network) do
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
iface = Mash.new
iface_config = Mash.new
diff --git a/lib/ohai/plugins/windows/virtualization.rb b/lib/ohai/plugins/windows/virtualization.rb
index 0ce24418..0ed73d60 100644
--- a/lib/ohai/plugins/windows/virtualization.rb
+++ b/lib/ohai/plugins/windows/virtualization.rb
@@ -24,7 +24,7 @@ Ohai.plugin(:Virtualization) do
include Ohai::Mixin::DmiDecode
collect_data(:windows) do
- require "wmi-lite/wmi"
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
virtualization Mash.new unless virtualization
virtualization[:systems] ||= Mash.new
diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb
index 5961a2cf..c5039813 100644
--- a/lib/ohai/runner.rb
+++ b/lib/ohai/runner.rb
@@ -18,7 +18,7 @@
#
require_relative "dsl"
-require "benchmark"
+require "benchmark" unless defined?(Benchmark)
module Ohai
class Runner
diff --git a/lib/ohai/util/ip_helper.rb b/lib/ohai/util/ip_helper.rb
index f22c4fdd..22657867 100644
--- a/lib/ohai/util/ip_helper.rb
+++ b/lib/ohai/util/ip_helper.rb
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-require "ipaddress"
+require "ipaddress" unless defined?(IPAddress)
module Ohai
module Util