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
144
145
146
147
148
149
150
151
152
|
# File 'lib/chef/knife/ec2_server_list.rb', line 86
def run
$stdout.sync = true
validate_aws_config!
servers_list = [
ui.color("Instance ID", :bold),
if config[:name]
ui.color("Name", :bold)
end,
ui.color("Public IP", :bold),
ui.color("Private IP", :bold),
ui.color("Flavor", :bold),
if config[:az]
ui.color("AZ", :bold)
end,
ui.color("Image", :bold),
ui.color("SSH Key", :bold),
ui.color("Security Groups", :bold),
if config[:tags]
config[:tags].split(",").collect do |tag_name|
ui.color("Tag:#{tag_name}", :bold)
end
end,
if config[:iamprofile]
ui.color("IAM Profile", :bold)
end,
ui.color("State", :bold),
].flatten.compact
output_column_count = servers_list.length
unless config[:region]
ui.warn "No region was specified in knife.rb/config.rb or as an argument. The default region, us-east-1, will be used:"
end
if config[:format] == "summary"
server_hashes.each do |v|
servers_list << v["instance_id"]
servers_list << v["name"] if config[:name]
servers_list << v["public_ip_address"]
servers_list << v["private_ip_address"]
servers_list << v["instance_type"]
servers_list << ui.color(v["az"], azcolor(v["az"])) if config[:az]
servers_list << v["image_id"]
servers_list << v["key_name"]
servers_list << v["security_groups"].join(",")
if config[:tags]
config[:tags].split(",").collect do |tag_name|
servers_list << v["tags"].find { |tag| tag == tag_name }
end
end
servers_list << v["iam_instance_profile"].to_s if config[:iamprofile]
servers_list << ui.color(v["state"], state_color(v["state"]))
end
puts ui.list(servers_list, :uneven_columns_across, output_column_count)
else
output(format_for_display(server_hashes))
end
end
|