Class: Chef::Knife::CfnOutputs

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

Instance Method Summary collapse

Methods inherited from CfnBase

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

Methods inherited from Chef::Knife

#create_create_def, #create_update_def, #iam_name_from_profile, #ini_parse

Instance Method Details

#runObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/chef/knife/cfn_outputs.rb', line 78

def run
  $stdout.sync = true

  validate!

  stack_name = @name_args[0]
  if stack_name.nil?
    show_usage
    ui.error("You must specify a stack name")
    exit 1
  end

  outputs_list = [
      ui.color("Stack", :bold),
      ui.color('Output Key', :bold),
      ui.color('Output Value', :bold),
      ui.color('Description', :bold)
  ]

  @name_args.each do |stack_name|
    options = {}
    options["StackName"] = stack_name
    data = Array.new
    begin
      response = connection.describe_stacks(options)
      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
      parameter_output=""
      delim=""
      data.each do |stack|
        row1 = true
        parameter_output += delim
        delim="\n"
        parameter_output+=stack["StackName"] + ": "
        outputs_list << stack["StackName"]
        stack["Outputs"].each do |output|
          if !row1
            outputs_list << ""
            parameter_output += ";"
          end
          outputs_list << output["OutputKey"]
          outputs_list << output["OutputValue"]
          outputs_list << output["Description"]
          parameter_output += output["OutputKey"] + "=" + output["OutputValue"]
          row1 = false
        end
      end
      if locate_config_value(:output_format) == "parameter"
        puts parameter_output
      else
        puts ui.list(outputs_list, :uneven_columns_across, 4)
      end

    end
  end
end