summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKris Zentner <kzentner@section6.net>2018-03-07 10:03:27 -0800
committerGitHub <noreply@github.com>2018-03-07 10:03:27 -0800
commit33203590e54011794cb0050038f49aa2e5342e8b (patch)
treee4c6e49e99a2d741297081b4e84db6aef898634c
parent20305d8791869f36b7c54558e3c631e0c508ecc5 (diff)
downloadohai-33203590e54011794cb0050038f49aa2e5342e8b.tar.gz
Separating network mash
In Azure, receiving the network section of the JSON output is not guaranteed, and will crash this plugin in these cases.
-rw-r--r--lib/ohai/plugins/azure.rb42
1 files changed, 25 insertions, 17 deletions
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
index cf173a59..7f74299d 100644
--- a/lib/ohai/plugins/azure.rb
+++ b/lib/ohai/plugins/azure.rb
@@ -68,16 +68,20 @@ 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 = Mash.new
metadata["network"] = Mash.new
metadata["network"]["interfaces"] = Mash.new
%w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type|
metadata["network"][type] = []
end
metadata
- end
+ end
def fetch_ip_data(data, type, field)
ips = []
@@ -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
+
+ # receiving network output is not guaranteed
+ unless endpoint_data["network"].nil?
+ metadata = initialize_metadata_mash_network
+ # 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
- # 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