Class: Chef::Provisioning::AWSDriver::AWSTagger
- Inherits:
-
Object
- Object
- Chef::Provisioning::AWSDriver::AWSTagger
- Extended by:
- Forwardable
- Defined in:
- lib/chef/provisioning/aws_driver/aws_tagger.rb
Overview
itself. Fill in the hook methods so it knows how to tag itself.
Instance Attribute Summary collapse
-
#action_handler ⇒ Object
readonly
Returns the value of attribute action_handler.
Instance Method Summary collapse
- #converge_tags ⇒ Object
-
#initialize(tagging_strategy, action_handler) ⇒ AWSTagger
constructor
A new instance of AWSTagger.
Constructor Details
#initialize(tagging_strategy, action_handler) ⇒ AWSTagger
Returns a new instance of AWSTagger.
11 12 13 14 |
# File 'lib/chef/provisioning/aws_driver/aws_tagger.rb', line 11 def initialize(tagging_strategy, action_handler) @tagging_strategy = tagging_strategy @action_handler = action_handler end |
Instance Attribute Details
#action_handler ⇒ Object (readonly)
Returns the value of attribute action_handler.
9 10 11 |
# File 'lib/chef/provisioning/aws_driver/aws_tagger.rb', line 9 def action_handler @action_handler end |
Instance Method Details
#converge_tags ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef/provisioning/aws_driver/aws_tagger.rb', line 18 def if .nil? Chef::Log.debug "aws_tags not provided, nothing to converge" return end # Duplication and normalization # ::Aws::EC2::Errors::InvalidParameterValue: Tag value cannot be null. Use empty string instead. = Hash[.map {|k,v| [k.to_s, v.to_s]}] = Hash[.map {|k,v| [k.to_s, v.to_s]}] = .reject {|k,v| [k] && [k] == v} = .keys - .keys # We don't want to delete `Name`, just all other tags # Tag keys and values are case sensitive - `Name` is special because it # shows as the name in the console .delete('Name') # Tagging frequently fails so we retry with an exponential backoff, a maximum of 10 seconds Retryable.retryable( :tries => 20, :sleep => lambda { |n| [2**n, 10].min }, :on => [AWS::Errors::Base, Aws::Errors::ServiceError,] ) do |retries, exception| if retries > 0 Chef::Log.info "Retrying the tagging, previous try failed with #{exception.inspect}" end unless .empty? action_handler.perform_action "creating tags #{}" do () end = [] end unless .empty? action_handler.perform_action "deleting tags #{}" do () end = [] end end end |