Module: Sfn::CommandModule::Base::InstanceMethods
- Defined in:
- lib/sfn/command_module/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.
-
#as_title(string) ⇒ String
Format snake cased key to title.
-
#attribute_allowed?(attr) ⇒ TrueClass, FalseClass
Check if attribute is allowed for display.
-
#config ⇒ Smash
Override config method to memoize the result allowing for modifications to the configuration during runtime.
-
#default_attributes ⇒ Array<String>
Default attributes to display.
-
#get_things(stack = nil, message = nil) { ... } ⇒ Object
Wrapper for information retrieval.
-
#name_args ⇒ Array<String>
Simple compat proxy method.
-
#poll_stack(name) ⇒ Object
Poll events on stack.
- #provider ⇒ KnifeCloudformation::Provider
-
#stack(name) ⇒ Miasma::Models::Orchestration::Stack
Get stack.
Instance Method Details
#_debug(e, *args) ⇒ Object
Write exception information if debug is enabled
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sfn/command_module/base.rb', line 31 def _debug(e, *args) if(config[:verbose]) ui.fatal "Exception information: #{e.class}: #{e.}" if(ENV['DEBUG']) puts "#{e.backtrace.join("\n")}\n" if(e.is_a?(Miasma::Error::ApiError)) ui.fatal "Response body: #{e.response.body.to_s.inspect}" end end args.each do |string| ui.fatal string end end end |
#allowed_attributes ⇒ Array<String>
Returns attributes to display.
63 64 65 |
# File 'lib/sfn/command_module/base.rb', line 63 def allowed_attributes opts.fetch(:attributes, config.fetch(:attributes, default_attributes)) end |
#as_title(string) ⇒ String
Format snake cased key to title
50 51 52 |
# File 'lib/sfn/command_module/base.rb', line 50 def as_title(string) string.to_s.split('_').map(&:capitalize).join(' ') end |
#attribute_allowed?(attr) ⇒ TrueClass, FalseClass
Check if attribute is allowed for display
76 77 78 |
# File 'lib/sfn/command_module/base.rb', line 76 def attribute_allowed?(attr) opts.fetch(:all_attributes, config[:all_attributes], allowed_attributes.include?(attr)) end |
#config ⇒ Smash
callback requires are also loaded here
Override config method to memoize the result allowing for modifications to the configuration during runtime
130 131 132 133 134 135 136 137 138 |
# File 'lib/sfn/command_module/base.rb', line 130 def config memoize(:config) do result = super result.fetch(:callbacks, :require, []).each do |c_loader| require c_loader end result end end |
#default_attributes ⇒ Array<String>
Returns default attributes to display.
68 69 70 |
# File 'lib/sfn/command_module/base.rb', line 68 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
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sfn/command_module/base.rb', line 107 def get_things(stack=nil, =nil) begin yield rescue => e ui.fatal "#{ || 'Failed to retrieve information'}#{" for requested stack: #{stack}" if stack}" ui.fatal "Reason: #{e}" _debug(e) exit 1 end end |
#name_args ⇒ Array<String>
Simple compat proxy method
121 122 123 |
# File 'lib/sfn/command_module/base.rb', line 121 def name_args arguments end |
#poll_stack(name) ⇒ Object
Poll events on stack
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sfn/command_module/base.rb', line 83 def poll_stack(name) provider.connection.stacks.reload retry_attempts = 0 begin events = Sfn::Command::Events.new({:poll => true}, [name]).execute! rescue => e if(retry_attempts < config.fetch(:max_poll_retries, 5).to_i) 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sfn/command_module/base.rb', line 12 def provider memoize(:provider, :direct) do result = Sfn::Provider.new( :miasma => config[:credentials], :async => false, :fetch => false ) result.connection.data[:retry_ui] = ui result.connection.data[:retry_type] = config.fetch(:retry, :type, :exponential) result.connection.data[:retry_interval] = config.fetch(:retry, :interval, 5) result.connection.data[:retry_max] = config.fetch(:retry, :max_attempts, 20) result end end |
#stack(name) ⇒ Miasma::Models::Orchestration::Stack
Get stack
58 59 60 |
# File 'lib/sfn/command_module/base.rb', line 58 def stack(name) provider.stacks.get(name) end |