Module: KnifeCloudformation::Knife::Base::InstanceMethods
- Defined in:
- lib/knife-cloudformation/knife/base.rb
Overview
Instance methods for cloudformation command classes
Instance Method Summary collapse
-
#_debug(e, *args) ⇒ Object
Write exception information if debug is enabled.
-
#allowed_attributes ⇒ Array<String>
Attributes to display.
-
#attribute_allowed?(attr) ⇒ TrueClass, FalseClass
Check if attribute is allowed for display.
-
#configure_chef ⇒ Object
Disable chef configuration.
-
#default_attributes ⇒ Array<String>
Default attributes to display.
-
#get_things(stack = nil, message = nil) { ... } ⇒ Object
Wrapper for information retrieval.
-
#poll_stack(name) ⇒ Object
Poll events on stack.
- #provider ⇒ KnifeCloudformation::Provider
-
#run ⇒ Object
Wrapper to allow consistent exception handling.
-
#stack(name) ⇒ Miasma::Models::Orchestration::Stack
Get stack.
Instance Method Details
#_debug(e, *args) ⇒ Object
Write exception information if debug is enabled
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/knife-cloudformation/knife/base.rb', line 21 def _debug(e, *args) if(ENV['DEBUG']) ui.fatal "Exception information: #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}\n" if(e.is_a?(Miasma::Error::ApiError)) ui.fatal "Response body: #{e.response.body.to_s.inspect}" end args.each do |string| ui.fatal string end end end |
#allowed_attributes ⇒ Array<String>
Returns attributes to display.
42 43 44 |
# File 'lib/knife-cloudformation/knife/base.rb', line 42 def allowed_attributes Chef::Config[:knife][:cloudformation][:attributes] || default_attributes end |
#attribute_allowed?(attr) ⇒ TrueClass, FalseClass
Check if attribute is allowed for display
55 56 57 |
# File 'lib/knife-cloudformation/knife/base.rb', line 55 def attribute_allowed?(attr) config[:all_attributes] || allowed_attributes.include?(attr) end |
#configure_chef ⇒ Object
Disable chef configuration. Let the dep loader do that for us so it doesn’t squash config values set via options
102 103 104 |
# File 'lib/knife-cloudformation/knife/base.rb', line 102 def configure_chef true end |
#default_attributes ⇒ Array<String>
Returns default attributes to display.
47 48 49 |
# File 'lib/knife-cloudformation/knife/base.rb', line 47 def default_attributes %w(timestamp stack_name id) end |
#get_things(stack = nil, message = nil) { ... } ⇒ Object
Wrapper for information retrieval. Provides consistent error message for failures
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/knife-cloudformation/knife/base.rb', line 89 def get_things(stack=nil, =nil) begin yield rescue => e ui.fatal "#{message || 'Failed to retrieve information'}#{" for requested stack: #{stack}" if stack}" ui.fatal "Reason: #{e}" _debug(e) exit 1 end end |
#poll_stack(name) ⇒ Object
Poll events on stack
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/knife-cloudformation/knife/base.rb', line 62 def poll_stack(name) retry_attempts = 0 begin provider.connection.stacks.reload knife_events = Chef::Knife::CloudformationEvents.new knife_events.name_args.push(name) Chef::Config[:knife][:cloudformation][:poll] = true knife_events.run rescue => e if(retry_attempts < Chef::Config[:knife][:cloudformation].fetch(:max_poll_retries, 5)) retry_attempts += 1 warn "Unexpected error encountered (#{e.class}: #{e}) Retrying [retry count: #{retry_attempts}]" sleep(1) retry else raise end end end |
#provider ⇒ KnifeCloudformation::Provider
13 14 15 |
# File 'lib/knife-cloudformation/knife/base.rb', line 13 def provider self.class.provider end |
#run ⇒ Object
Wrapper to allow consistent exception handling
107 108 109 110 111 112 113 114 115 |
# File 'lib/knife-cloudformation/knife/base.rb', line 107 def run begin _run rescue => e ui.fatal "Unexpected Error: #{e.message}" _debug(e) exit 1 end end |
#stack(name) ⇒ Miasma::Models::Orchestration::Stack
Get stack
37 38 39 |
# File 'lib/knife-cloudformation/knife/base.rb', line 37 def stack(name) provider.stacks.get(name) end |