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-09-27 21:31:15 -07:00
|
|
|
def initialize(attributes)
|
|
|
|
@public_ip ||= []
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-08-19 09:11:26 -07:00
|
|
|
def all(public_ip = [])
|
|
|
|
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-08-12 22:33:35 -07:00
|
|
|
addresses << Fog::AWS::EC2::Address.new({
|
2009-10-14 21:55:53 -07:00
|
|
|
:addresses => addresses,
|
2009-08-12 22:33:35 -07:00
|
|
|
:connection => connection
|
|
|
|
}.merge!(address))
|
|
|
|
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
|
|
|
|
|
|
|
|
def create
|
|
|
|
address = new
|
|
|
|
address.save
|
|
|
|
address
|
|
|
|
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-09-22 22:47:45 -07:00
|
|
|
rescue Fog::Errors::BadRequest
|
|
|
|
nil
|
2009-09-21 11:40:38 -07:00
|
|
|
end
|
|
|
|
|
2009-08-12 22:33:35 -07:00
|
|
|
def new
|
2009-09-20 09:21:03 -07:00
|
|
|
Fog::AWS::EC2::Address.new(
|
2009-09-27 21:31:15 -07:00
|
|
|
:addresses => self,
|
2009-10-20 19:39:57 -07:00
|
|
|
:connection => connection,
|
|
|
|
:instance => instance
|
2009-09-20 09:21:03 -07:00
|
|
|
)
|
2009-08-12 22:33:35 -07:00
|
|
|
end
|
|
|
|
|
2009-09-21 11:40:38 -07:00
|
|
|
def reload
|
|
|
|
all(public_ip)
|
|
|
|
end
|
|
|
|
|
2009-08-12 22:33:35 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|