[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, experimental, updated. debian/1.5.8-2-160-gb26a2a8
Nigel Kersten
nigel at puppetlabs.com
Tue May 10 08:40:12 UTC 2011
The following commit has been merged in the experimental branch:
commit cc67a0148b97e315572cdb905476df1224a78dd5
Author: James Turnbull <james at lovedthanlost.net>
Date: Wed May 4 11:02:41 2011 +1000
Removed inappropriately uncredited Ohai method from ec2 fact
diff --git a/lib/facter/arp.rb b/lib/facter/arp.rb
index 6269ae0..383fb48 100644
--- a/lib/facter/arp.rb
+++ b/lib/facter/arp.rb
@@ -13,7 +13,7 @@ Facter.add(:arp) do
end
end
end
- EC2_ARP == arp ? arp : nil
+ "fe:ff:ff:ff:ff:ff" == arp ? arp : nil
end
end
@@ -22,7 +22,7 @@ Facter::Util::IP.get_interfaces.each do |interface|
confine :kernel => :linux
setcode do
arp = Facter::Util::IP.get_arp_value(interface)
- EC2_ARP == arp ? arp : nil
+ "fe:ff:ff:ff:ff:ff" == arp ? arp : nil
end
end
end
diff --git a/lib/facter/ec2.rb b/lib/facter/ec2.rb
index 693e78e..c52f76b 100644
--- a/lib/facter/ec2.rb
+++ b/lib/facter/ec2.rb
@@ -4,45 +4,24 @@
# Additional work modelled on Ohai EC2 fact
require 'open-uri'
-require 'socket'
-
-EC2_ADDR = "169.254.169.254"
-EC2_METADATA_URL = "http://#{EC2_ADDR}/2008-02-01/meta-data"
-EC2_USERDATA_URL = "http://#{EC2_ADDR}/2008-02-01/user-data"
-EC2_ARP = "fe:ff:ff:ff:ff:ff"
-EC2_EUCA_MAC = %r{^[dD]0:0[dD]:}
-
-def can_metadata_connect?(addr, port, timeout=2)
- t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
- saddr = Socket.pack_sockaddr_in(port, addr)
- connected = false
-
- begin
- t.connect_nonblock(saddr)
- rescue Errno::EINPROGRESS
- r,w,e = IO::select(nil,[t],nil,timeout)
- if !w.nil?
- connected = true
- else
- begin
- t.connect_nonblock(saddr)
- rescue Errno::EISCONN
- t.close
- connected = true
- rescue SystemCallError
- end
- end
- rescue SystemCallError
- end
- connected
+require 'timeout'
+
+def can_connect?(wait_sec=2)
+ url = "http://169.254.169.254:80/"
+ Timeout::timeout(wait_sec) {open(url)}
+ return true
+ rescue Timeout::Error
+ return false
+ rescue
+ return false
end
def metadata(id = "")
- open("#{EC2_METADATA_URL}/#{id||=''}").read.
+ 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("#{EC2_METADATA_URL}/#{key}").read.
+ 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
@@ -54,23 +33,22 @@ def metadata(id = "")
end
def userdata()
- # assumes the only expected error is the 404 if there's no user-data
begin
- value = OpenURI.open_uri("#{EC2_USERDATA_URL}/").read.split
+ value = OpenURI.open_uri("http://169.254.169.254/2008-02-01/user-data/").read.split
Facter.add(:ec2_userdata) { setcode { value } }
rescue OpenURI::HTTPError
end
end
def has_euca_mac?
- !!(Facter.value(:macaddress) =~ EC2_EUCA_MAC)
+ !!(Facter.value(:macaddress) =~ %r{^[dD]0:0[dD]:})
end
def has_ec2_arp?
- !!(Facter.value(:arp) == EC2_ARP)
+ !!(Facter.value(:arp) == "fe:ff:ff:ff:ff:ff")
end
-if (has_euca_mac? || has_ec2_arp?) && can_metadata_connect?(EC2_ADDR,80)
+if (has_euca_mac? || has_ec2_arp?) && can_connect?
metadata
userdata
else
--
Packaging of Facter for debian
More information about the Pkg-puppet-devel
mailing list