diff options
author | Tim Smith <tsmith@chef.io> | 2018-03-09 09:52:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-09 09:52:53 -0800 |
commit | a31a6144f87149ca27f72588a4c0e44c0b4d2bf8 (patch) | |
tree | c1bab4d4d3d9986b30e32a5ee58b993d72c4b083 | |
parent | 6eab5f80f309e160e2acaba05d4511f8a6aedf73 (diff) | |
parent | 142c7f3961930e5531a74c36203fe95061b07c2b (diff) | |
download | ohai-a31a6144f87149ca27f72588a4c0e44c0b4d2bf8.tar.gz |
Merge pull request #1154 from kriszentner/master
Fix bug in azure plugin/update to recent metadata version.
-rw-r--r-- | lib/ohai/mixin/azure_metadata.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/azure.rb | 38 |
2 files changed, 24 insertions, 16 deletions
diff --git a/lib/ohai/mixin/azure_metadata.rb b/lib/ohai/mixin/azure_metadata.rb index 90304e54..08ba8399 100644 --- a/lib/ohai/mixin/azure_metadata.rb +++ b/lib/ohai/mixin/azure_metadata.rb @@ -22,7 +22,7 @@ module Ohai module AzureMetadata AZURE_METADATA_ADDR = "169.254.169.254" unless defined?(AZURE_METADATA_ADDR) - AZURE_METADATA_URL = "/metadata/instance?api-version=2017-04-02" unless defined?(AZURE_METADATA_URL) + AZURE_METADATA_URL = "/metadata/instance?api-version=2017-08-01" unless defined?(AZURE_METADATA_URL) # fetch the meta content with a timeout and the required header def http_get(uri) diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb index cf173a59..4a15dc54 100644 --- a/lib/ohai/plugins/azure.rb +++ b/lib/ohai/plugins/azure.rb @@ -68,9 +68,13 @@ Ohai.plugin(:Azure) do end # create the basic structure we'll store our data in - def initialize_metadata_mash + def initialize_metadata_mash_compute metadata = Mash.new metadata["compute"] = Mash.new + metadata + end + + def initialize_metadata_mash_network(metadata) metadata["network"] = Mash.new metadata["network"]["interfaces"] = Mash.new %w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type| @@ -93,27 +97,31 @@ Ohai.plugin(:Azure) do endpoint_data = fetch_metadata return nil if endpoint_data.nil? - metadata = initialize_metadata_mash + metadata = initialize_metadata_mash_compute # blindly add everything in compute to our data structure endpoint_data["compute"].each do |k, v| metadata["compute"][k] = v end - # parse out per interface interface IP data - endpoint_data["network"]["interface"].each do |int| - metadata["network"]["interfaces"][int["macAddress"]] = Mash.new - metadata["network"]["interfaces"][int["macAddress"]]["mac"] = int["macAddress"] - metadata["network"]["interfaces"][int["macAddress"]]["public_ipv6"] = fetch_ip_data(int, "ipv6", "publicIpAddress") - metadata["network"]["interfaces"][int["macAddress"]]["public_ipv4"] = fetch_ip_data(int, "ipv4", "publicIpAddress") - metadata["network"]["interfaces"][int["macAddress"]]["local_ipv6"] = fetch_ip_data(int, "ipv6", "privateIpAddress") - metadata["network"]["interfaces"][int["macAddress"]]["local_ipv4"] = fetch_ip_data(int, "ipv4", "privateIpAddress") - end + # receiving network output is not guaranteed + unless endpoint_data["network"].nil? + metadata = initialize_metadata_mash_network(metadata) + # parse out per interface interface IP data + endpoint_data["network"]["interface"].each do |int| + metadata["network"]["interfaces"][int["macAddress"]] = Mash.new + metadata["network"]["interfaces"][int["macAddress"]]["mac"] = int["macAddress"] + metadata["network"]["interfaces"][int["macAddress"]]["public_ipv6"] = fetch_ip_data(int, "ipv6", "publicIpAddress") + metadata["network"]["interfaces"][int["macAddress"]]["public_ipv4"] = fetch_ip_data(int, "ipv4", "publicIpAddress") + metadata["network"]["interfaces"][int["macAddress"]]["local_ipv6"] = fetch_ip_data(int, "ipv6", "privateIpAddress") + metadata["network"]["interfaces"][int["macAddress"]]["local_ipv4"] = fetch_ip_data(int, "ipv4", "privateIpAddress") + end - # aggregate the total IP data - %w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type| - metadata["network"]["interfaces"].each_value do |val| - metadata["network"][type].concat val[type] unless val[type].empty? + # aggregate the total IP data + %w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type| + metadata["network"]["interfaces"].each_value do |val| + metadata["network"][type].concat val[type] unless val[type].empty? + end end end |