Module: Sfn::CommandModule::Base::InstanceMethods

Defined in:
lib/sfn/command_module/base.rb

Overview

Instance methods for cloudformation command classes

Instance Method Summary collapse

Instance Method Details

#_debug(e, *args) ⇒ Object

Write exception information if debug is enabled

Parameters:

  • e (Exception)
  • args (String)

    extra strings to output



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sfn/command_module/base.rb', line 26

def _debug(e, *args)
  if(config[:verbose])
    ui.fatal "Exception information: #{e.class}: #{e.message}"
    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_attributesArray<String>

Returns attributes to display.

Returns:

  • (Array<String>)

    attributes to display



58
59
60
# File 'lib/sfn/command_module/base.rb', line 58

def allowed_attributes
  opts.fetch(:attributes, config.fetch(:attributes, default_attributes))
end

#as_title(string) ⇒ String

Format snake cased key to title

Parameters:

  • string (String, Symbol)

Returns:

  • (String)

    String



45
46
47
# File 'lib/sfn/command_module/base.rb', line 45

def as_title(string)
  string.to_s.split('_').map(&:capitalize).join(' ')
end

#attribute_allowed?(attr) ⇒ TrueClass, FalseClass

Check if attribute is allowed for display

Parameters:

  • attr (String)

Returns:

  • (TrueClass, FalseClass)


71
72
73
# File 'lib/sfn/command_module/base.rb', line 71

def attribute_allowed?(attr)
  opts.fetch(:all_attributes, config[:all_attributes], allowed_attributes.include?(attr))
end

#configObject



120
121
122
123
124
# File 'lib/sfn/command_module/base.rb', line 120

def config
  memoize(:config) do
    super
  end
end

#default_attributesArray<String>

Returns default attributes to display.

Returns:

  • (Array<String>)

    default attributes to display



63
64
65
# File 'lib/sfn/command_module/base.rb', line 63

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

Parameters:

  • stack (String) (defaults to: nil)

    stack name

  • message (String) (defaults to: nil)

    failure message

Yields:

  • block to wrap error handling

Returns:

  • (Object)

    result of yield



102
103
104
105
106
107
108
109
110
111
# File 'lib/sfn/command_module/base.rb', line 102

def get_things(stack=nil, message=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

#name_argsArray<String>

Simple compat proxy method

Returns:

  • (Array<String>)


116
117
118
# File 'lib/sfn/command_module/base.rb', line 116

def name_args
  arguments
end

#poll_stack(name) ⇒ Object

Poll events on stack

Parameters:

  • name (String)

    name of stack



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sfn/command_module/base.rb', line 78

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

#providerKnifeCloudformation::Provider

Returns:

  • (KnifeCloudformation::Provider)


12
13
14
15
16
17
18
19
20
# File 'lib/sfn/command_module/base.rb', line 12

def provider
  memoize(:provider, :direct) do
    Sfn::Provider.new(
      :miasma => config[:credentials],
      :async => false,
      :fetch => false
    )
  end
end

#stack(name) ⇒ Miasma::Models::Orchestration::Stack

Get stack

Parameters:

  • name (String)

    name of stack

Returns:

  • (Miasma::Models::Orchestration::Stack)


53
54
55
# File 'lib/sfn/command_module/base.rb', line 53

def stack(name)
  provider.stacks.get(name)
end