1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/ec2/addresses.rb

59 lines
1.3 KiB
Ruby
Raw Normal View History

2009-08-12 22:33:35 -07:00
module Fog
module AWS
class EC2
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
attribute :public_ip
attribute :instance
model Fog::AWS::EC2::Address
def initialize(attributes)
@public_ip ||= []
super
end
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({
: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|
addresses << new(address.reject {|key, value| value.nil? || value.empty? })
2009-08-12 22:33:35 -07:00
end
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 get(public_ip)
2009-10-22 20:46:15 -07:00
if public_ip
all(public_ip).first
end
rescue Excon::Errors::BadRequest
2009-09-22 22:47:45 -07:00
nil
end
def new(attributes = {})
if instance
super({ :instance => instance }.merge!(attributes))
else
super(attributes)
end
end
2009-08-12 22:33:35 -07:00
end
end
end
end