1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

add ability to detach/dissasociate and add new_record? method

This commit is contained in:
Wesley Beary 2009-11-11 22:22:13 -08:00
parent 5b9189658e
commit e75a7fba57
3 changed files with 53 additions and 15 deletions

View file

@ -21,12 +21,10 @@ module Fog
end
def instance=(new_instance)
if !@public_ip
@instance = new_instance
elsif new_instance
@instance = nil
@instance_id = new_instance.instance_id
connection.associate_address(@instance_id, @public_ip)
if new_instance
associate(new_instance)
else
detach
end
end
@ -39,6 +37,26 @@ module Fog
true
end
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
end
end

View file

@ -28,15 +28,10 @@ module Fog
end
def instance=(new_instance)
if !@volume_id
@instance = new_instance
if new_instance
@availability_zone = new_instance.availability_zone
end
elsif new_instance
@instance = nil
@instance_id = new_instance.instance_id
connection.attach_volume(@instance_id, @volume_id, @device)
if new_instance
attach(new_instance)
else
detach
end
end
@ -54,6 +49,27 @@ module Fog
connection.snapshots(:volume_id => volume_id)
end
private
def attach(new_instance)
if new_record?
@instance = new_instance
@availability_zone = new_instance.availability_zone
elsif new_instance
@instance = nil
@instance_id = new_instance.instance_id
connection.attach_volume(@instance_id, @volume_id, @device)
end
end
def detach
@instance = nil
@instance_id = nil
unless new_record?
connection.detach_volume(@volume_id)
end
end
end
end

View file

@ -63,6 +63,10 @@ module Fog
self
end
def new_record?
!identity
end
def reload
new_attributes = collection.get(identity).attributes
merge_attributes(new_attributes)