Class: AWS::EC2::InstanceCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/mongolly/extensions/aws/ec2/instance_collection.rb

Instance Method Summary collapse

Instance Method Details

#find_from_address(address, port = 27107) ⇒ Object

rubocop:disable Style/NumericLiterals



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mongolly/extensions/aws/ec2/instance_collection.rb', line 7

def find_from_address(address, port = 27107) # rubocop:disable Style/NumericLiterals
  ip_address = convert_address_to_ip(address, port)

  instances = select do |instance|
    instance.public_ip_address == ip_address || instance.private_ip_address == ip_address
  end
  raise error_class "InstanceNotFound"  if instances.length != 1

  return instances.first
rescue SocketError
  raise RuntimeError.new("Unable to determine IP address from #{address}:#{port}")
end