2009-08-13 01:33:35 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
|
|
|
class Address < Fog::Model
|
|
|
|
|
2009-10-24 01:23:55 -04:00
|
|
|
identity :public_ip, 'publicIp'
|
2009-08-13 01:33:35 -04:00
|
|
|
|
2009-10-24 01:23:55 -04:00
|
|
|
attribute :instance_id, 'instanceId'
|
2009-09-19 15:21:31 -04:00
|
|
|
|
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-11-12 01:22:13 -05:00
|
|
|
if new_instance
|
|
|
|
associate(new_instance)
|
|
|
|
else
|
2009-11-12 02:17:50 -05:00
|
|
|
disassociate
|
2009-10-20 22:39:57 -04:00
|
|
|
end
|
2009-10-06 21:55:39 -04:00
|
|
|
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
|
2009-10-22 12:42:02 -04:00
|
|
|
self.instance = @instance
|
2009-10-20 22:39:57 -04:00
|
|
|
end
|
2009-09-05 23:50:40 -04:00
|
|
|
true
|
2009-08-13 01:33:35 -04:00
|
|
|
end
|
|
|
|
|
2009-11-12 01:22:13 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def associate(new_instance)
|
|
|
|
if new_record?
|
|
|
|
@instance = new_instance
|
|
|
|
else
|
|
|
|
@instance = nil
|
|
|
|
@instance_id = new_instance.instance_id
|
|
|
|
connection.associate_address(@instance_id, @public_ip)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def disassociate
|
|
|
|
@instance = nil
|
|
|
|
@instance_id = nil
|
|
|
|
unless new_record?
|
|
|
|
connection.disassociate_address(@public_ip)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-13 01:33:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|