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

[ec2] better behaved volume models in relation to servers and attach/detach

This commit is contained in:
geemus 2010-04-27 11:19:24 -07:00
parent d43ccd2515
commit 6d4127a7ca

View file

@ -20,6 +20,8 @@ module Fog
attribute :state, 'status'
def initialize(attributes = {})
# assign server first to prevent race condition with new_record?
self.server = attributes.delete(:server)
if attributes['attachmentSet']
attributes.merge!(attributes.delete('attachmentSet').first || {})
end
@ -33,6 +35,10 @@ module Fog
true
end
def ready?
state == 'available'
end
def server=(new_server)
if new_server
attach(new_server)
@ -70,6 +76,7 @@ module Fog
@server = nil
@server_id = new_server.id
connection.attach_volume(@server_id, @id, @device)
reload
end
end
@ -78,6 +85,7 @@ module Fog
@server_id = nil
unless new_record?
connection.detach_volume(@id)
reload
end
end