Class: Fog::Models::ProfitBricks::Base

Inherits:
Fog::Model
  • Object
show all
Defined in:
lib/fog/profitbricks/models/base.rb

Instance Method Summary collapse

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fog/profitbricks/models/base.rb', line 31

def failed?
  request_status(request_id) == 'FAILED'
end

#ready?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/fog/profitbricks/models/base.rb', line 27

def ready?
  request_status(request_id) == 'DONE'
end

#request_status(request_id) ⇒ Object



22
23
24
25
# File 'lib/fog/profitbricks/models/base.rb', line 22

def request_status(request_id)
  request = service.requests.get_status(request_id)
  request.status
end

#wait_for(timeout = Fog.timeout, interval = Fog.interval, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/profitbricks/models/base.rb', line 5

def wait_for(timeout = Fog.timeout, interval = Fog.interval, &block)
  reload_has_succeeded = false
  duration = Fog.wait_for(timeout, interval) do # Note that duration = false if it times out
    if ready?
      reload_has_succeeded = true
      instance_eval(&block)
    else
      false
    end
  end
  if reload_has_succeeded
    return duration # false if timeout; otherwise {:duration => elapsed time }
  else
    raise Fog::Errors::Error, "Reload failed, #{self.class} #{identity} not present."
  end
end