Facter::Util::EC2

Provide a set of utility static methods that help with resolving the EC2 fact.

Public Class Methods

can_connect?(wait_sec=2) click to toggle source

Test if we can connect to the EC2 api. Return true if able to connect. On failure this function fails silently and returns false.

The wait_sec parameter provides you with an adjustable timeout.

    # File lib/facter/util/ec2.rb, line 13
13:     def can_connect?(wait_sec=2)
14:       url = "http://169.254.169.254:80/"
15:       Timeout::timeout(wait_sec) {open(url)}
16:       return true
17:       rescue Timeout::Error
18:         return false
19:       rescue
20:         return false
21:     end
has_ec2_arp?() click to toggle source

Test if the host has an arp entry in its cache that matches the EC2 arp, which is normally +fe:ff:ff:ff:ff:ff+.

    # File lib/facter/util/ec2.rb, line 37
37:     def has_ec2_arp?
38:       mac_address = "fe:ff:ff:ff:ff:ff"
39:       if Facter.value(:kernel) == 'windows'
40:         arp_command = "arp -a"
41:         mac_address.gsub!(":","-")
42:       else
43:         arp_command = "arp -an"
44:       end
45: 
46:       arp_table = Facter::Util::Resolution.exec(arp_command)
47:       if not arp_table.nil?
48:         arp_table.each_line do |line|
49:           return true if line.downcase.include?(mac_address)
50:         end
51:       end
52:       return false
53:     end
has_euca_mac?() click to toggle source

Test if this host has a mac address used by Eucalyptus clouds, which normally is +d0:0d+.

    # File lib/facter/util/ec2.rb, line 25
25:     def has_euca_mac?
26:       !!(Facter.value(:macaddress) =~ %{^[dD]0:0[dD]:})
27:     end
has_openstack_mac?() click to toggle source

Test if this host has a mac address used by OpenStack, which normally starts with 02:16:3E

    # File lib/facter/util/ec2.rb, line 31
31:     def has_openstack_mac?
32:       !!(Facter.value(:macaddress) =~ %{^02:16:3[eE]})
33:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.