[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, upstream, updated. 3a39dd8353b6308cf49522990104cc63e55d7cda
James Turnbull
james at lovedthanlost.net
Fri Jan 29 17:22:09 UTC 2010
The following commit has been merged in the upstream branch:
commit 6b904a0953177744c533b456e73fe78d08198285
Author: James Turnbull <james at lovedthanlost.net>
Date: Sat Feb 28 09:27:22 2009 +1100
Added EC2 facts
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
+
--
Packaging of Facter for debian
More information about the Pkg-puppet-devel
mailing list