summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2009-02-28 09:27:22 +1100
committerJames Turnbull <james@lovedthanlost.net>2009-02-28 09:27:31 +1100
commit6b904a0953177744c533b456e73fe78d08198285 (patch)
tree05fe3883de605c111c142a466b61b9db7f101d58
parent86b01bf61b143e03647f5983cbc99beae8744704 (diff)
downloadfacter-6b904a0953177744c533b456e73fe78d08198285.tar.gz
facter-6b904a0953177744c533b456e73fe78d08198285.tar.xz
facter-6b904a0953177744c533b456e73fe78d08198285.zip
Added EC2 facts
-rw-r--r--CHANGELOG8
-rw-r--r--lib/facter/ec2.rb35
2 files changed, 40 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index ac03ca6..d7131e1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
-1.5.x:
- Fixed #2032 - file.open hanging on /proc/uptime on some platform
-
+1.6.0:
+ Added EC2 facts
+
+ Fixed #2032 - file.open hanging on /proc/uptime on some platform
+
1.5.4:
Fixed #1966 - Added physicalprocessorcount fact
diff --git a/lib/facter/ec2.rb b/lib/facter/ec2.rb
new file mode 100644
index 0000000..ef84757
--- /dev/null
+++ b/lib/facter/ec2.rb
@@ -0,0 +1,35 @@
+# Changelog:
+# Original facts - Tim Dysinger
+# Updated and added can_connect? function - KurtBe
+
+require 'open-uri'
+require 'timeout'
+
+def can_connect?(ip,port,wait_sec=2)
+ Timeout::timeout(wait_sec) {open(ip, port)}
+ return true
+rescue
+ return false
+end
+
+
+def metadata(id = "")
+ open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read.
+ split("\n").each do |o|
+ key = "#{id}#{o.gsub(/\=.*$/, '/')}"
+ if key[-1..-1] != '/'
+ value = open("http://169.254.169.254/2008-02-01/meta-data/#{key}").read.
+ split("\n")
+ value = value.size>1 ? value : value.first
+ symbol = "ec2_#{key.gsub(/\-|\//, '_')}".to_sym
+ Facter.add(symbol) { setcode { value } }
+ else
+ metadata(key)
+ end
+ end
+end
+
+if can_connect?("169.254.169.254","80")
+ metadata
+end
+