2009-08-12 22:33:35 -07:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
2009-10-20 19:39:57 -07:00
|
|
|
def addresses(attributes = {})
|
|
|
|
Fog::AWS::EC2::Addresses.new({
|
|
|
|
:connection => self
|
|
|
|
}.merge!(attributes))
|
2009-08-12 22:33:35 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
class Addresses < Fog::Collection
|
|
|
|
|
2009-09-21 11:40:38 -07:00
|
|
|
attribute :public_ip
|
2009-10-20 19:39:57 -07:00
|
|
|
attribute :instance
|
2009-09-21 11:40:38 -07:00
|
|
|
|
2009-10-30 00:11:50 -07:00
|
|
|
model Fog::AWS::EC2::Address
|
2009-10-29 23:35:28 -07:00
|
|
|
|
2009-09-27 21:31:15 -07:00
|
|
|
def initialize(attributes)
|
|
|
|
@public_ip ||= []
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-10-29 23:35:28 -07:00
|
|
|
def all(public_ip = @public_ip)
|
2009-08-19 09:11:26 -07:00
|
|
|
data = connection.describe_addresses(public_ip).body
|
2009-09-26 19:42:08 -07:00
|
|
|
addresses = Fog::AWS::EC2::Addresses.new({
|
2009-09-27 21:31:15 -07:00
|
|
|
:connection => connection,
|
|
|
|
:public_ip => public_ip
|
2009-09-26 19:42:08 -07:00
|
|
|
}.merge!(attributes))
|
2009-08-14 09:19:40 -07:00
|
|
|
data['addressesSet'].each do |address|
|
2009-11-14 16:45:52 -08:00
|
|
|
addresses << new(address.reject {|key, value| value.nil? || value.empty? })
|
2009-08-12 22:33:35 -07:00
|
|
|
end
|
2009-10-20 19:39:57 -07:00
|
|
|
if instance
|
|
|
|
addresses = addresses.select {|address| address.instance_id == instance.id}
|
2009-10-06 18:55:39 -07:00
|
|
|
end
|
2009-08-12 22:33:35 -07:00
|
|
|
addresses
|
|
|
|
end
|
|
|
|
|
2009-09-21 11:40:38 -07:00
|
|
|
def get(public_ip)
|
2009-10-22 20:46:15 -07:00
|
|
|
if public_ip
|
|
|
|
all(public_ip).first
|
|
|
|
end
|
2009-11-08 12:16:52 -08:00
|
|
|
rescue Excon::Errors::BadRequest
|
2009-09-22 22:47:45 -07:00
|
|
|
nil
|
2009-09-21 11:40:38 -07:00
|
|
|
end
|
|
|
|
|
2009-10-29 23:35:28 -07:00
|
|
|
def new(attributes = {})
|
2009-12-05 14:53:42 -08:00
|
|
|
if instance
|
|
|
|
super({ :instance => instance }.merge!(attributes))
|
|
|
|
else
|
|
|
|
super(attributes)
|
|
|
|
end
|
2009-09-21 11:40:38 -07:00
|
|
|
end
|
|
|
|
|
2009-08-12 22:33:35 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|