Class: Chef::Knife::CfnResources

Inherits:
CfnBase show all
Defined in:
lib/chef/knife/cfn_resources.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



32
33
34
35
36
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
# File 'lib/chef/knife/cfn_resources.rb', line 32

def run
  $stdout.sync = true

  validate!

  stack_name = @name_args[0]
  logical_resource_id = @name_args[1]

  if stack_name.nil?
    show_usage
    ui.error("You must specify a stack name")
    exit 1
  end

  resources_list = [
      ui.color('Logical Resource Id', :bold),
      ui.color('Physical Resource Id', :bold),
      ui.color('Resource Type', :bold),
      ui.color('Resource Status', :bold)
  ]

  connection_params = { "StackName" => stack_name }
  if !logical_resource_id.nil?
    connection_params["LogicalResourceId"] = logical_resource_id
  end

  data = Array.new
  begin
    response = connection.describe_stack_resources(connection_params)
    data = response.body['StackResources']
  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 |resource|
      resources_list << resource['LogicalResourceId']
      resources_list << resource['PhysicalResourceId']
      resources_list << resource['ResourceType']
      resources_list << resource['ResourceStatus']
    end
    puts ui.list(resources_list, :uneven_columns_across, 4)
  end

end