Module: KnifeCloudformation::Knife::Base::InstanceMethods

Defined in:
lib/knife-cloudformation/knife/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



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_attributesArray<String>



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_chefObject

Disable chef configuration. Let the dep loader do that for us so it doesn’t squash config values set via options



89
90
91
# File 'lib/knife-cloudformation/knife/base.rb', line 89

def configure_chef
  true
end

#default_attributesArray<String>



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

Yields:

  • block to wrap error handling



76
77
78
79
80
81
82
83
84
85
# File 'lib/knife-cloudformation/knife/base.rb', line 76

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

#poll_stack(name) ⇒ Object

Poll events on stack



62
63
64
65
66
67
# File 'lib/knife-cloudformation/knife/base.rb', line 62

def poll_stack(name)
  knife_events = Chef::Knife::CloudformationEvents.new
  knife_events.name_args.push(name)
  Chef::Config[:knife][:cloudformation][:poll] = true
  knife_events.run
end

#providerKnifeCloudformation::Provider



13
14
15
# File 'lib/knife-cloudformation/knife/base.rb', line 13

def provider
  self.class.provider
end

#runObject

Wrapper to allow consistent exception handling



94
95
96
97
98
99
100
101
102
# File 'lib/knife-cloudformation/knife/base.rb', line 94

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