diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-08-09 17:31:14 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-08-09 17:31:14 -0700 |
commit | a120ce8074a07c9549eeabb03dac742467e7cf8b (patch) | |
tree | 89179b195231176a0ec0f2376f3bcaa26ec7be00 /lib | |
parent | 691d6cb53709e1ed2d4c2e7551d0d9747001acde (diff) | |
download | ohai-a120ce8074a07c9549eeabb03dac742467e7cf8b.tar.gz |
Move requires into collect methods
Avoid requiring these unless we actually run the plugin.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ohai/plugins/aix/network.rb | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/docker.rb | 4 | ||||
-rw-r--r-- | lib/ohai/plugins/ec2.rb | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/filesystem.rb | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/hostname.rb | 6 | ||||
-rw-r--r-- | lib/ohai/plugins/network.rb | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/openstack.rb | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/passwd.rb | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/rackspace.rb | 3 | ||||
-rw-r--r-- | lib/ohai/util/ip_helper.rb | 4 |
10 files changed, 20 insertions, 15 deletions
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb index de9dd101..125bdb05 100644 --- a/lib/ohai/plugins/aix/network.rb +++ b/lib/ohai/plugins/aix/network.rb @@ -19,7 +19,6 @@ # Ohai.plugin(:Network) do - require "ipaddr" unless defined?(IPAddr) require_relative "../../mixin/network_helper" provides "network", "counters/network", "macaddress" @@ -27,6 +26,8 @@ Ohai.plugin(:Network) do include Ohai::Mixin::NetworkHelper collect_data(:aix) do + require "ipaddr" unless defined?(IPAddr) + # Loads following information. # :default_interface, :default_gateway - route -n get 0 # :interfaces diff --git a/lib/ohai/plugins/docker.rb b/lib/ohai/plugins/docker.rb index 421c7243..d6626c5c 100644 --- a/lib/ohai/plugins/docker.rb +++ b/lib/ohai/plugins/docker.rb @@ -16,8 +16,6 @@ # Ohai.plugin(:Docker) do - require "json" unless defined?(JSON) - provides "docker" depends "virtualization" @@ -50,6 +48,8 @@ Ohai.plugin(:Docker) do end collect_data do + require "json" unless defined?(JSON) + if virtualization[:systems][:docker] docker_ohai_data(docker_info_json) end diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb index 6aa262f1..b4fb735e 100644 --- a/lib/ohai/plugins/ec2.rb +++ b/lib/ohai/plugins/ec2.rb @@ -28,7 +28,6 @@ Ohai.plugin(:EC2) do require_relative "../mixin/ec2_metadata" require_relative "../mixin/http_helper" - require "base64" include Ohai::Mixin::Ec2Metadata include Ohai::Mixin::HttpHelper @@ -115,6 +114,8 @@ Ohai.plugin(:EC2) do end collect_data do + require "base64" + if looks_like_ec2? logger.trace("Plugin EC2: looks_like_ec2? == true") ec2 Mash.new diff --git a/lib/ohai/plugins/filesystem.rb b/lib/ohai/plugins/filesystem.rb index 85eb6ad7..c27035f5 100644 --- a/lib/ohai/plugins/filesystem.rb +++ b/lib/ohai/plugins/filesystem.rb @@ -23,8 +23,6 @@ # limitations under the License. # -require "set" - Ohai.plugin(:Filesystem) do provides "filesystem" @@ -718,6 +716,7 @@ Ohai.plugin(:Filesystem) do end collect_data(:windows) do + require "set" require "wmi-lite/wmi" unless defined?(WmiLite::Wmi) require_relative "../mash" diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb index 177cfcad..1360b227 100644 --- a/lib/ohai/plugins/hostname.rb +++ b/lib/ohai/plugins/hostname.rb @@ -26,9 +26,6 @@ # Ohai.plugin(:Hostname) do - require "socket" unless defined?(Socket) - require "ipaddr" unless defined?(IPAddr) - provides "domain", "hostname", "fqdn", "machinename" # hostname : short hostname @@ -47,6 +44,9 @@ Ohai.plugin(:Hostname) do # forward and reverse lookup to canonicalize FQDN (hostname -f equivalent) # this is ipv6-safe, works on ruby 1.8.7+ def resolve_fqdn + require "socket" unless defined?(Socket) + require "ipaddr" unless defined?(IPAddr) + hostname = from_cmd("hostname") addrinfo = Socket.getaddrinfo(hostname, nil).first iaddr = IPAddr.new(addrinfo[3]) diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb index 74990bea..09bcd766 100644 --- a/lib/ohai/plugins/network.rb +++ b/lib/ohai/plugins/network.rb @@ -17,7 +17,6 @@ # Ohai.plugin(:NetworkAddresses) do - require "ipaddress" unless defined?(IPAddress) require_relative "../mixin/network_helper" include Ohai::Mixin::NetworkHelper @@ -134,6 +133,8 @@ Ohai.plugin(:NetworkAddresses) do # time as ipaddress. if ipaddress is set and macaddress is nil, that means # the interface ipaddress is bound to has the NOARP flag collect_data do + require "ipaddress" unless defined?(IPAddress) + results = {} network Mash.new unless network diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb index 50106d7e..361e0488 100644 --- a/lib/ohai/plugins/openstack.rb +++ b/lib/ohai/plugins/openstack.rb @@ -19,7 +19,6 @@ Ohai.plugin(:Openstack) do require_relative "../mixin/ec2_metadata" require_relative "../mixin/http_helper" - require "etc" unless defined?(Etc) include Ohai::Mixin::Ec2Metadata include Ohai::Mixin::HttpHelper @@ -59,6 +58,8 @@ Ohai.plugin(:Openstack) do end collect_data do + require "etc" unless defined?(Etc) + # fetch data if we look like openstack if openstack_hint? || openstack_virtualization? openstack Mash.new diff --git a/lib/ohai/plugins/passwd.rb b/lib/ohai/plugins/passwd.rb index 2c43d73b..4af41450 100644 --- a/lib/ohai/plugins/passwd.rb +++ b/lib/ohai/plugins/passwd.rb @@ -1,6 +1,5 @@ Ohai.plugin(:Passwd) do - require "etc" unless defined?(Etc) provides "etc", "current_user" optional true @@ -14,6 +13,8 @@ Ohai.plugin(:Passwd) do end collect_data do + require "etc" unless defined?(Etc) + unless etc etc Mash.new diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb index 3f4e8339..c831d1b5 100644 --- a/lib/ohai/plugins/rackspace.rb +++ b/lib/ohai/plugins/rackspace.rb @@ -15,7 +15,6 @@ # limitations under the License. Ohai.plugin(:Rackspace) do - require "resolv" provides "rackspace" depends "kernel", "network/interfaces" @@ -147,6 +146,8 @@ Ohai.plugin(:Rackspace) do end collect_data do + require "resolv" + # Adds rackspace Mash if looks_like_rackspace? rackspace Mash.new diff --git a/lib/ohai/util/ip_helper.rb b/lib/ohai/util/ip_helper.rb index 22657867..8b56eecf 100644 --- a/lib/ohai/util/ip_helper.rb +++ b/lib/ohai/util/ip_helper.rb @@ -14,11 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "ipaddress" unless defined?(IPAddress) - module Ohai module Util module IpHelper + require "ipaddress" unless defined?(IPAddress) + # Corresponding to RFC 4192 + RFC 4193 IPV6_LINK_LOCAL_UNICAST_BLOCK = IPAddress("fe80::/10") IPV6_PRIVATE_ADDRESS_BLOCK = IPAddress("fc00::/7") |