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