From 42afd29c44dc3d9c1c772496a02e70313215d46c Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 3 Feb 2016 12:14:20 -0800 Subject: [PATCH] Improved debug logging for cloud plugins Add debug for hints / mac detection to a few plugins Fixed the eucalyptus plugin to not spam debug with mac detection false warnings for each interface --- lib/ohai/plugins/digital_ocean.rb | 6 +++--- lib/ohai/plugins/eucalyptus.rb | 20 ++++++++++++-------- lib/ohai/plugins/gce.rb | 4 ++-- lib/ohai/plugins/linode.rb | 3 +++ lib/ohai/plugins/rackspace.rb | 8 ++++---- lib/ohai/plugins/softlayer.rb | 7 ++++--- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/lib/ohai/plugins/digital_ocean.rb b/lib/ohai/plugins/digital_ocean.rb index f637e7489..abc5f853d 100644 --- a/lib/ohai/plugins/digital_ocean.rb +++ b/lib/ohai/plugins/digital_ocean.rb @@ -22,7 +22,6 @@ DIGITALOCEAN_FILE = '/etc/digitalocean' unless defined?(DIGITALOCEAN_FILE) provides "digital_ocean" - depends "network/interfaces" def extract_droplet_ip_addresses @@ -35,7 +34,7 @@ def extract_droplet_ip_addresses type = digital_ocean_address_type(ip) address_hash = build_address_hash(ip, details) addresses[type] << address_hash - end + end end addresses end @@ -64,6 +63,7 @@ def looks_like_digital_ocean? collect_data do if looks_like_digital_ocean? + Ohai::Log.debug("digitalocean plugin: looks_like_digital_ocean? == true") digital_ocean Mash.new hint = hint?('digital_ocean') || {} hint.each {|k, v| digital_ocean[k] = v unless k == 'ip_addresses'} @@ -74,7 +74,7 @@ def looks_like_digital_ocean? # https://developers.digitalocean.com/#droplets digital_ocean[:networks] = extract_droplet_ip_addresses else - Ohai::Log.debug("No hints present for digital_ocean.") + Ohai::Log.debug("digitalocean plugin: No hints present for and doesn't look like digitalocean") false end end diff --git a/lib/ohai/plugins/eucalyptus.rb b/lib/ohai/plugins/eucalyptus.rb index eb04009d0..0a0c0b4b0 100644 --- a/lib/ohai/plugins/eucalyptus.rb +++ b/lib/ohai/plugins/eucalyptus.rb @@ -17,15 +17,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +# eucalyptus metadata service is compatible with the ec2 service calls require 'ohai/mixin/ec2_metadata' Ohai.plugin(:Eucalyptus) do include Ohai::Mixin::Ec2Metadata provides "eucalyptus" - depends "network/interfaces" + # returns the mac address from the collection of all address types def get_mac_address(addresses) detected_addresses = addresses.detect { |address, keypair| keypair == {"family"=>"lladdr"} } if detected_addresses @@ -35,26 +36,29 @@ def get_mac_address(addresses) end end + # detect if the mac address starts with d0:0d def has_euca_mac? network[:interfaces].values.each do |iface| - has_mac = (get_mac_address(iface[:addresses]) =~ /^[dD]0:0[dD]:/) - Ohai::Log.debug("has_euca_mac? == #{!!has_mac}") - return true if has_mac + mac = get_mac_address(iface[:addresses]) + if mac =~ /^[dD]0:0[dD]:/ + Ohai::Log.debug("eucalyptus plugin: has_euca_mac? == true (#{mac})") + return true + end end - Ohai::Log.debug("has_euca_mac? == false") + Ohai::Log.debug("eucalyptus plugin: has_euca_mac? == false") false end def looks_like_euca? # Try non-blocking connect so we don't "block" if - # the Xen environment is *not* EC2 + # the metadata service doesn't respond hint?('eucalyptus') || has_euca_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80) end collect_data do if looks_like_euca? - Ohai::Log.debug("looks_like_euca? == true") + Ohai::Log.debug("eucalyptus plugin: looks_like_euca? == true") eucalyptus Mash.new self.fetch_metadata.each do |k, v| # Eucalyptus 3.4+ supports IAM roles and Instance Profiles much like AWS @@ -69,7 +73,7 @@ def looks_like_euca? end eucalyptus[:userdata] = self.fetch_userdata else - Ohai::Log.debug("looks_like_euca? == false") + Ohai::Log.debug("eucalyptus plugin: looks_like_euca? == false") false end end diff --git a/lib/ohai/plugins/gce.rb b/lib/ohai/plugins/gce.rb index 6a03f0fc4..82abaf082 100644 --- a/lib/ohai/plugins/gce.rb +++ b/lib/ohai/plugins/gce.rb @@ -41,11 +41,11 @@ def looks_like_gce? collect_data do if looks_like_gce? - Ohai::Log.debug("looks_like_gce? == true") + Ohai::Log.debug("gce plugin: looks_like_gce? == true") gce Mash.new fetch_metadata.each {|k, v| gce[k] = v } else - Ohai::Log.debug("looks_like_gce? == false") + Ohai::Log.debug("gce plugin: looks_like_gce? == false") false end end diff --git a/lib/ohai/plugins/linode.rb b/lib/ohai/plugins/linode.rb index 72c40a2de..a585783db 100644 --- a/lib/ohai/plugins/linode.rb +++ b/lib/ohai/plugins/linode.rb @@ -53,10 +53,13 @@ def get_ip_address(name, eth) collect_data do # Setup linode mash if it is a linode system if looks_like_linode? + Ohai::Log.debug("linode plugin: looks_like_linode? == true") linode Mash.new get_ip_address(:public_ip, :eth0) get_ip_address(:private_ip, "eth0:1") hint?('linode').each{|k,v| linode[k] = v } if hint?('linode').kind_of?(Hash) + else + Ohai::Log.debug("linode plugin: looks_like_linode? == false") end end end diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb index 195fed064..7aa02b2d8 100644 --- a/lib/ohai/plugins/rackspace.rb +++ b/lib/ohai/plugins/rackspace.rb @@ -92,7 +92,7 @@ def get_region() end end rescue Errno::ENOENT - Ohai::Log.debug("Unable to find xenstore-ls, cannot capture region information for Rackspace cloud") + Ohai::Log.debug("rackspace plugin: Unable to find xenstore-ls, cannot capture region information for Rackspace cloud") nil end @@ -104,7 +104,7 @@ def get_instance_id() rackspace[:instance_id] = so.stdout.gsub(/instance-/, "") end rescue Errno::ENOENT - Ohai::Log.debug("Unable to find xenstore-read, cannot capture instance ID information for Rackspace cloud") + Ohai::Log.debug("rackspace plugin: Unable to find xenstore-read, cannot capture instance ID information for Rackspace cloud") nil end @@ -119,7 +119,7 @@ def get_private_networks() if _so.exitstatus == 0 networks.push(FFI_Yajl::Parser.new.parse(_so.stdout)) else - Ohai::Log.debug('Unable to capture custom private networking information for Rackspace cloud') + Ohai::Log.debug('rackspace plugin: Unable to capture custom private networking information for Rackspace cloud') return false end end @@ -128,7 +128,7 @@ def get_private_networks() networks.delete_if { |hash| hash['label'] == 'public' } end rescue Errno::ENOENT - Ohai::Log.debug('Unable to capture custom private networking information for Rackspace cloud') + Ohai::Log.debug('rackspace plugin: Unable to capture custom private networking information for Rackspace cloud') nil end diff --git a/lib/ohai/plugins/softlayer.rb b/lib/ohai/plugins/softlayer.rb index 028a744f4..4704e0a63 100644 --- a/lib/ohai/plugins/softlayer.rb +++ b/lib/ohai/plugins/softlayer.rb @@ -37,11 +37,12 @@ def looks_like_softlayer? collect_data do # Adds softlayer Mash if looks_like_softlayer? - ::Ohai::Log.debug("looks_like_softlayer? == true") + Ohai::Log.debug("softlayer plugin: looks_like_softlayer? == true") metadata = fetch_metadata softlayer Mash.new metadata.each { |k,v| softlayer[k] = v } if metadata + else + Ohai::Log.debug("softlayer plugin: looks_like_softlayer? == false") end - end -end \ No newline at end of file +end