2009-08-13 01:33:35 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
|
|
|
class Address < Fog::Model
|
|
|
|
|
2009-09-05 23:50:40 -04:00
|
|
|
attribute :instance_id, 'instanceId'
|
|
|
|
attribute :public_ip, 'publicIp'
|
2009-08-13 01:33:35 -04:00
|
|
|
|
2009-09-19 15:21:31 -04:00
|
|
|
def addresses
|
|
|
|
@addresses
|
|
|
|
end
|
|
|
|
|
2009-09-23 01:47:45 -04:00
|
|
|
def initialize(new_attributes = {})
|
|
|
|
new_attributes = {
|
|
|
|
:instance_id => ''
|
|
|
|
}.merge!(new_attributes)
|
|
|
|
super(new_attributes)
|
|
|
|
end
|
|
|
|
|
2009-09-20 12:21:03 -04:00
|
|
|
def destroy
|
2009-08-13 01:33:35 -04:00
|
|
|
connection.release_address(@public_ip)
|
2009-09-05 23:50:40 -04:00
|
|
|
true
|
2009-08-13 01:33:35 -04:00
|
|
|
end
|
|
|
|
|
2009-10-06 21:55:39 -04:00
|
|
|
def instance=(new_instance)
|
2009-10-20 22:39:57 -04:00
|
|
|
if !@public_ip
|
|
|
|
@instance = new_instance
|
|
|
|
elsif new_instance
|
|
|
|
@instance = nil
|
|
|
|
@instance_id = new_instance.instance_id
|
|
|
|
connection.associate_address(@instance_id, @public_ip)
|
|
|
|
end
|
2009-10-06 21:55:39 -04:00
|
|
|
end
|
|
|
|
|
2009-09-19 15:31:15 -04:00
|
|
|
def reload
|
2009-09-24 22:18:20 -04:00
|
|
|
new_attributes = addresses.get(@public_ip).attributes
|
2009-09-19 15:31:15 -04:00
|
|
|
merge_attributes(new_attributes)
|
|
|
|
end
|
|
|
|
|
2009-08-13 01:33:35 -04:00
|
|
|
def save
|
|
|
|
data = connection.allocate_address
|
|
|
|
@public_ip = data.body['publicIp']
|
2009-10-20 22:39:57 -04:00
|
|
|
if @instance
|
|
|
|
instance = @instance
|
|
|
|
end
|
2009-09-05 23:50:40 -04:00
|
|
|
true
|
2009-08-13 01:33:35 -04:00
|
|
|
end
|
|
|
|
|
2009-09-19 15:21:31 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def addresses=(new_addresses)
|
|
|
|
@addresses = new_addresses
|
|
|
|
end
|
|
|
|
|
2009-08-13 01:33:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|