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

[vcloud|compute] make status/ready handling more reliable

This commit is contained in:
Lincoln Stoll 2011-05-31 13:24:15 +10:00
parent 01ace6c62f
commit 001559350f
2 changed files with 13 additions and 5 deletions

View file

@ -16,6 +16,7 @@ module Fog
attribute :description, :aliases => :Description
attribute :storage_size, :aliases => :size
attribute :links, :aliases => :Link, :type => :array
attribute :tasks, :aliases => :Tasks, :type => :array
attribute :vm_data, :aliases => :Children, :squash => :Vm
@ -39,17 +40,18 @@ module Fog
end
def ready?
reload # always ensure we have the correct status
status != '0' # ready unless creating.
reload_status # always ensure we have the correct status
running_tasks = tasks && tasks.flatten.any? {|ti| ti.kind_of?(Hash) && ti[:status] == 'running' }
status != '0' && !running_tasks # 0 is provisioning, and no running tasks
end
def on?
reload # always ensure we have the correct status
reload_status # always ensure we have the correct status
status == '4'
end
def off?
reload # always ensure we have the correct status
reload_status # always ensure we have the correct status
status == '8'
end
@ -117,7 +119,6 @@ module Fog
end
def disks
pp disk_mess
disk_mess.map do |dm|
{ :number => dm[:"rasd:AddressOnParent"], :size => dm[:"rasd:VirtualQuantity"].to_i, :resource => dm[:"rasd:HostResource"] }
end
@ -180,6 +181,7 @@ module Fog
wait_for { off? }
end
wait_for { off? } # be sure..
wait_for { ready? } # be doubly sure..
sleep 2 # API lies. need to give it some time to be happy.
connection.delete_vapp(href).body[:status] == "running"
end
@ -240,6 +242,10 @@ module Fog
true
end
def reload_status
self.status = connection.get_vapp(href).body[:status]
end
end
end
end

View file

@ -19,6 +19,8 @@ module Fog
def get(uri)
if data = connection.get_vapp(uri)
# If no tasks returned, set a mock entry to flush on reload
data.body[:Tasks] = {} unless data.body[:Tasks]
new(data.body)
end
rescue Fog::Errors::NotFound