diff options
author | Jason Barnett <jason.w.barnett@gmail.com> | 2020-09-30 09:16:52 -0400 |
---|---|---|
committer | Jason Barnett <jason.w.barnett@gmail.com> | 2020-09-30 14:49:11 -0400 |
commit | a60af6b1f3b9d0fde917b9a70fe4f493b0b822fa (patch) | |
tree | ac0dea8257ace1e0d39b7ea1b99c461de0047615 /lib | |
parent | e0d81b68c3b78712e0c34ce14ff60d7dcc662d25 (diff) | |
download | ohai-a60af6b1f3b9d0fde917b9a70fe4f493b0b822fa.tar.gz |
Detect Azure when DHCP domain is set to reddog.microsoft.com
Signed-off-by: Jason Barnett <jason.w.barnett@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ohai/plugins/azure.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb index c19d3c80..31cbaeed 100644 --- a/lib/ohai/plugins/azure.rb +++ b/lib/ohai/plugins/azure.rb @@ -34,7 +34,7 @@ Ohai.plugin(:Azure) do azure Mash.new azure_metadata_from_hints.each { |k, v| azure[k] = v } azure["metadata"] = parse_metadata - elsif has_waagent? || has_dhcp_option_245? + elsif has_waagent? || has_dhcp_option_245? || has_reddog_dhcp_domain? logger.trace("Plugin Azure: No hints present, but system appears to be on Azure.") azure Mash.new azure["metadata"] = parse_metadata @@ -67,6 +67,26 @@ Ohai.plugin(:Azure) do has_245 end + def has_reddog_dhcp_domain? + tcp_ip_dhcp_domain == "reddog.microsoft.com" + end + + def tcp_ip_dhcp_domain + return unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/) + + require "win32/registry" unless defined?(Win32::Registry) + + begin + key = Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters") + dhcp_domain = key["DhcpDomain"] + Ohai::Log.trace("Plugin Azure: DhcpDomain registry value is #{dhcp_domain}") + rescue Win32::Registry::Error + Ohai::Log.trace("Plugin Azure: DhcpDomain registry value cannot be found") + end + + dhcp_domain + end + # create the basic structure we'll store our data in def initialize_metadata_mash_compute metadata = Mash.new |