diff options
author | Thom May <thom@may.lt> | 2018-03-19 10:40:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-19 10:40:43 +0000 |
commit | 8580567fad1bceb685c82b86a21e7aa78b670d46 (patch) | |
tree | bc737a8d77861ff06c02e66d59519782c4b28de7 | |
parent | 064bf49645e786a421859d24c91a62a35fe00c7b (diff) | |
parent | f8b2331b0c3a127bc4a88a2726e8de1b86b144df (diff) | |
download | ohai-8580567fad1bceb685c82b86a21e7aa78b670d46.tar.gz |
Merge pull request #1156 from chef/azure
Fix bug in azure plugin/update to recent metadata version. [ backport #1154]
-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 115477d2..481f51ed 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 |