Module: VagrantPlugins::Skytap::API::Busyable

Included in:
Interface, RunstateOperations, VpnAttachment
Defined in:
lib/vagrant-skytap/api/busyable.rb

Constant Summary collapse

WAIT_TIMEOUT =
300
WAIT_ITERATION_PERIOD =
2

Instance Method Summary collapse

Instance Method Details

#retry_while_resource_busy(timeout = WAIT_TIMEOUT, &block) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-skytap/api/busyable.rb', line 18

def retry_while_resource_busy(timeout=WAIT_TIMEOUT, &block)
  begin
    Timeout.timeout(timeout) do
      loop do
        break if env[:interrupted] # is this right?
        begin
          yield
        rescue Errors::ResourceBusy
        end
        sleep WAIT_ITERATION_PERIOD
      end
    end
  rescue Timeout::Error => ex
    raise Errors::InstanceReadyTimeout, timeout: timeout
  end
end

#update_with_retry(attrs, path = nil) ⇒ Object


10
11
12
13
14
15
16
# File 'lib/vagrant-skytap/api/busyable.rb', line 10

def update_with_retry(attrs, path=nil)
  retry_while_resource_busy do
    resp = api_client.put(path || url, JSON.dump(attrs))
    refresh(JSON.load(resp.body))
    break
  end
end