class Chef::Provisioning::AWSDriver::AWSProvider
Constants
- AWSResource
Attributes
Protected Class Methods
Retry a block with an doubling backoff time (maximum wait of 10 seconds). @param retry_on [Exception] An exception to retry on, defaults to RuntimeError
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 292 def self.retry_with_backoff(*retry_on) retry_on ||= [RuntimeError] Retryable.retryable(tries: 10, sleep: ->(n) { [2**n, 16].min }, on: retry_on) do |_retries, exception| Chef::Log.debug("Current exception in retry_with_backoff is #{exception.inspect}") yield end end
Public Instance Methods
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 22 def action_handler @action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self) end
Return the damned value from the block, not whatever weirdness converge_by
normally returns.
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 39 def converge_by(*args) result = nil super(*args) do result = yield end result end
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 31 def region new_resource.driver.aws_config[:region] end
All these need to implement whyrun
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 27 def whyrun_supported? true end
Protected Instance Methods
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 214 def create_aws_object raise NotImplementedError, :create_aws_object end
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 222 def destroy_aws_object(_obj) raise NotImplementedError, :destroy_aws_object end
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 300 def retry_with_backoff(*retry_on, &block) self.class.retry_with_backoff(*retry_on, &block) end
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 218 def update_aws_object(_obj) raise NotImplementedError, :update_aws_object end
Wait until aws_object obtains one of expected_responses
@param aws_object Aws
SDK Object
to check state on @param query_method Method to call on aws_object to get current state @param expected_responses [Symbol,Array<Symbol>] Final state(s) to look for @param acceptable_errors [Exception,Array<Exception>] Acceptable errors that are caught and squelched @param tries [Integer] Number of times to check state, defaults to 60 @param sleep [Integer] Time to wait between checking states, defaults to 5
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 257 def wait_for(opts = {}) aws_object = opts[:aws_object] query_method = opts[:query_method] expected_responses = [opts[:expected_responses]].flatten acceptable_errors = [opts[:acceptable_errors] || []].flatten tries = opts[:tries] || 60 sleep = opts[:sleep] || 5 Retryable.retryable(tries: tries, sleep: sleep) do |retries, exception| action_handler.report_progress "waited #{retries * sleep}/#{tries * sleep}s for <#{aws_object.class}:#{aws_object.id}>##{query_method} state to change to #{expected_responses.inspect}..." Chef::Log.debug("Current exception in wait_for is #{exception.inspect}") if exception begin yield(aws_object) if block_given? if aws_object.class.to_s.eql?("Aws::EC2::Vpc") vpc = new_resource.driver.ec2.describe_vpcs(vpc_ids: [aws_object.vpc_id]).vpcs current_response = "[:#{vpc[0].state}]" elsif aws_object.class.to_s.eql?("Aws::EC2::NetworkInterface") result = new_resource.driver.ec2_resource.network_interface(aws_object.id) current_response = "[:#{result.status}]" current_response = "[:in_use]" if current_response.eql?("[:in-use]") elsif aws_object.class.to_s.eql?("Aws::EC2::NatGateway") current_response = "[:#{aws_object.state}]" end Chef::Log.debug("Current response in wait_for from [#{query_method}] is #{current_response}") unless expected_responses.to_s.include?(current_response) raise StatusTimeoutError.new(aws_object, current_response, expected_responses) end rescue *acceptable_errors end end end
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 237 def wait_for_state(aws_object, expected_states, acceptable_errors = [], tries = 60, sleep = 5) wait_for( aws_object: aws_object, query_method: :state, expected_responses: expected_states, acceptable_errors: acceptable_errors, tries: tries, sleep: sleep ) end
# File lib/chef/provisioning/aws_driver/aws_provider.rb, line 226 def wait_for_status(aws_object, expected_status, acceptable_errors = [], tries = 60, sleep = 5) wait_for( aws_object: aws_object, query_method: :status, expected_responses: expected_status, acceptable_errors: acceptable_errors, tries: tries, sleep: sleep ) end