Class: Chef::Provisioning::GoogleDriver::Client::OperationsBase

Inherits:
GoogleBase
  • Object
show all
Defined in:
lib/chef/provisioning/google_driver/client/operations_base.rb

Direct Known Subclasses

GlobalOperations, ZoneOperations

Constant Summary

Constants inherited from GoogleBase

GoogleBase::NOT_FOUND, GoogleBase::OK, GoogleBase::SLEEP_SECONDS, GoogleBase::TRIES

Instance Attribute Summary

Attributes inherited from GoogleBase

#google, #project, #zone

Instance Method Summary collapse

Methods inherited from GoogleBase

#compute, #default_parameters, #initialize, #is_not_found?, #make_request, #operation_response, #raise_if_error

Constructor Details

This class inherits a constructor from Chef::Provisioning::GoogleDriver::Client::GoogleBase

Instance Method Details

#get(operation) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/chef/provisioning/google_driver/client/operations_base.rb', line 18

def get(operation)
  response = make_request(
    operations_service.get,
    { operation: operation.name }
  )
  operation_response(response)
end

#operations_serviceObject

The operations service that should be used, i.e. global_operations or zone_operations.

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/chef/provisioning/google_driver/client/operations_base.rb', line 14

def operations_service
  raise NotImplementedError
end

#wait_for_done(action_handler, operation) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chef/provisioning/google_driver/client/operations_base.rb', line 26

def wait_for_done(action_handler, operation)
  Retryable.retryable(:tries => TRIES, :sleep => SLEEP_SECONDS, :matching => /not be completed/) do |retries, exception|
    # TODO the operation name isn't useful output
    action_handler.report_progress("  waited #{retries * SLEEP_SECONDS}/#{TRIES * SLEEP_SECONDS}s for operation #{operation.name} to complete")
    # TODO it is really awesome that there are 3 types of operations, and the only way of telling
    # which is which is to parse the full `:selfLink` from the response body.  Update this method
    # to take the full operation response from Google so it can tell which operation endpoint
    # to hit
    response_operation = get(operation)
    raise GoogleComputeError, "Operation #{operation.name} could not be completed." unless response_operation.done?
    response_operation
  end
end