diff options
author | Kirill Shirinkin <fodojyko@gmail.com> | 2016-12-12 17:43:06 +0100 |
---|---|---|
committer | Kirill Shirinkin <fodojyko@gmail.com> | 2016-12-12 17:59:16 +0100 |
commit | 007eb03df51c6dff5ad86ef7958a9b05ffc56c88 (patch) | |
tree | 09c4d0ff9d0ac1dd1a5989d613d91b745ff34b93 | |
parent | 227759272be4d5db0923c09825445a18f328e40b (diff) | |
download | ohai-007eb03df51c6dff5ad86ef7958a9b05ffc56c88.tar.gz |
Memoize dynamic AWS data
Signed-off-by: Kirill Shirinkin <fodojyko@gmail.com>
-rw-r--r-- | lib/ohai/mixin/ec2_metadata.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/ohai/mixin/ec2_metadata.rb b/lib/ohai/mixin/ec2_metadata.rb index 17eec527..1797105d 100644 --- a/lib/ohai/mixin/ec2_metadata.rb +++ b/lib/ohai/mixin/ec2_metadata.rb @@ -201,14 +201,16 @@ module Ohai end def fetch_dynamic_data - api_version = best_api_version - return {} if api_version.nil? - response = http_client.get("/#{api_version}/dynamic/instance-identity/document/") + @fetch_dynamic_data ||= begin + api_version = best_api_version + return {} if api_version.nil? + response = http_client.get("/#{api_version}/dynamic/instance-identity/document/") - if json?(response.body) && response.code == "200" - FFI_Yajl::Parser.parse(response.body) - else - {} + if json?(response.body) && response.code == "200" + FFI_Yajl::Parser.parse(response.body) + else + {} + end end end |