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:
parent
d43ccd2515
commit
6d4127a7ca
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue