summaryrefslogtreecommitdiff
path: root/lib/ohai
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ohai')
-rw-r--r--lib/ohai/mixin/dmi_decode.rb6
-rw-r--r--lib/ohai/plugins/azure.rb25
2 files changed, 25 insertions, 6 deletions
diff --git a/lib/ohai/mixin/dmi_decode.rb b/lib/ohai/mixin/dmi_decode.rb
index 755afda0..1b3ba625 100644
--- a/lib/ohai/mixin/dmi_decode.rb
+++ b/lib/ohai/mixin/dmi_decode.rb
@@ -22,10 +22,10 @@ module ::Ohai::Mixin::DmiDecode
case line
when /Manufacturer: Microsoft/
if dmi_data =~ /Product Name: Virtual Machine/
- if dmi_data =~ /Version: (VS2005R2|6.0)/
- return 'virtualpc'
- elsif dmi_data =~ /Version: (7.0|Hyper-V)/
+ if dmi_data =~ /Version: (7.0|Hyper-V)/
return 'hyperv'
+ elsif dmi_data =~ /Version: (VS2005R2|6.0)/
+ return 'virtualpc'
elsif dmi_data =~ /Version: 5.0/
return 'virtualserver'
end
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
index 97ba1cc4..852bcd94 100644
--- a/lib/ohai/plugins/azure.rb
+++ b/lib/ohai/plugins/azure.rb
@@ -19,17 +19,36 @@ Ohai.plugin(:Azure) do
collect_data do
# The azure hints are populated by the knife plugin for Azure.
- # The project is located at https://github.com/opscode/knife-azure
+ # The project is located at https://github.com/chef/knife-azure
# Please see the lib/chef/knife/azure_server_create.rb file in that
# project for details
azure_metadata_from_hints = hint?('azure')
if azure_metadata_from_hints
- Ohai::Log.debug("azure_metadata_from_hints is present.")
+ Ohai::Log.debug("azure plugin: azure_metadata_from_hints is present.")
azure Mash.new
azure_metadata_from_hints.each {|k, v| azure[k] = v }
+ elsif looks_like_azure?
+ Ohai::Log.debug("azure plugin: No hints present, but system appears to be on azure.")
+ azure Mash.new
else
- Ohai::Log.debug("No hints present for azure.")
+ Ohai::Log.debug("azure plugin: No hints present for azure and doesn't appear to be azure.")
false
end
end
+
+ # check for either the waagent or the unknown-245 DHCP option that Azure uses
+ # http://blog.mszcool.com/index.php/2015/04/detecting-if-a-virtual-machine-runs-in-microsoft-azure-linux-windows-to-protect-your-software-when-distributed-via-the-azure-marketplace/
+ def looks_like_azure?
+ if File.exist?('/usr/sbin/waagent') || Dir.exist?('C:\WindowsAzure')
+ Ohai::Log.debug("azure plugin: Found waagent used by MS Azure.")
+ return true
+ elsif File.exist?('/var/lib/dhcp/dhclient.eth0.leases')
+ File.open("/var/lib/dhcp/dhclient.eth0.leases").each do |line|
+ if line =~ /unknown-245/
+ Ohai::Log.debug("azure plugin: Found unknown-245 DHCP option used by MS Azure.")
+ return true
+ end
+ end
+ end
+ end
end