Class: Chef::Knife::CfnDescribe

Inherits:
CfnBase show all
Defined in:
lib/chef/knife/cfn_describe.rb

Instance Method Summary collapse

Methods inherited from CfnBase

#connection, included, #locate_config_value, #msg_pair, #validate!

Methods inherited from Chef::Knife

#create_create_def, #create_update_def

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/chef/knife/cfn_describe.rb', line 37

def run
  $stdout.sync = true

  validate!

  stack_name = @name_args[0]
  if stack_name.nil?
    @name_args[0] = "__ALL__"
  end

  output_mode = "StackName"
  output_header = "Stack Name"

  if !config[:long_names].nil?
    output_mode = "StackId"
    output_header = "Stack ID"
  end

  stack_list = [
      ui.color(output_header, :bold),
      ui.color('Status', :bold),
      ui.color('Creation Time', :bold),
      ui.color('Disable Rollback', :bold)
  ]

  @name_args.each do |stack_name|
    options = {}
    data = Array.new
    options['StackName'] = stack_name

    begin
      if stack_name == "__ALL__"
        response = connection.describe_stacks()
      else
        response = connection.describe_stacks(options)
      end

      data = response.body['Stacks']
    rescue Excon::Errors::BadRequest => e
      i= e.response.body.index("<Message>")
      j = e.response.body.index("</Message>")
      if !i.nil? and !j.nil?
        ui.error(e.response.body[i+9,j-i-9])
      else
        print "\n#{e.response.body}"
      end
      exit 1
    else
      data.each do |stack|
        stack_list << stack[output_mode]
        stack_list << stack['StackStatus']
        stack_list << stack['CreationTime'].to_s
        stack_list << stack['DisableRollback'].to_s
      end

      puts ui.list(stack_list, :uneven_columns_across, 4)
    end
  end
end