Skip to content

Commit

Permalink
Merge pull request #724 from tas50/cloud_debug
Browse files Browse the repository at this point in the history
Improved debug logging for cloud plugins
  • Loading branch information
thommay committed Feb 4, 2016
2 parents 237129a + 42afd29 commit 9b21b51
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
6 changes: 3 additions & 3 deletions lib/ohai/plugins/digital_ocean.rb
Expand Up @@ -22,7 +22,6 @@
DIGITALOCEAN_FILE = '/etc/digitalocean' unless defined?(DIGITALOCEAN_FILE)

provides "digital_ocean"

depends "network/interfaces"

def extract_droplet_ip_addresses
Expand All @@ -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
Expand Down Expand Up @@ -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'}
Expand All @@ -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
Expand Down
20 changes: 12 additions & 8 deletions lib/ohai/plugins/eucalyptus.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/gce.rb
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/ohai/plugins/linode.rb
Expand Up @@ -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
8 changes: 4 additions & 4 deletions lib/ohai/plugins/rackspace.rb
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down
7 changes: 4 additions & 3 deletions lib/ohai/plugins/softlayer.rb
Expand Up @@ -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
end

0 comments on commit 9b21b51

Please sign in to comment.