diff options
author | Tim Smith <tsmith84@gmail.com> | 2016-05-09 21:47:16 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-02-23 12:57:31 -0800 |
commit | 708854dbd35e05f2723a11731ac1b52bbd34f967 (patch) | |
tree | 72eb377292e34d7f376d0e724ba13093a1a62b37 | |
parent | d1906045a7ebd748fcabc8e937504dc8d659a669 (diff) | |
download | ohai-708854dbd35e05f2723a11731ac1b52bbd34f967.tar.gz |
Parse the JSON so that we can do .each on it later
Without this it's just a big string and the .each fails
-rw-r--r-- | lib/ohai/mixin/do_metadata.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/ohai/mixin/do_metadata.rb b/lib/ohai/mixin/do_metadata.rb index 21945b49..d2952023 100644 --- a/lib/ohai/mixin/do_metadata.rb +++ b/lib/ohai/mixin/do_metadata.rb @@ -54,17 +54,18 @@ module Ohai Net::HTTP.start(DO_METADATA_ADDR).tap { |h| h.read_timeout = 6 } end - def fetch_metadata() + def fetch_metadata uri = "#{DO_METADATA_URL}" response = http_client.get(uri) case response.code when "200" - response.body + parser = FFI_Yajl::Parser.new + parser.parse(response.body) when "404" - Ohai::Log.debug("Encountered 404 response retreiving Digital Ocean metadata: #{uri} ; continuing.") - Hash.new + Ohai::Log.debug("DOMetadata mixin:Encountered 404 response retreiving Digital Ocean metadata: #{uri} ; continuing.") + {} else - raise "Encountered error retrieving Digital Ocean metadata (#{uri} returned #{response.code} response)" + raise "DOMetadata mixin:Encountered error retrieving Digital Ocean metadata (#{uri} returned #{response.code} response)" end end |