Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Always set Name tag on server create.
Browse files Browse the repository at this point in the history
The Name tag should ways be set to one of the following

(1) an explicitly set Name tag passed with --tags,
(2) the node_name set with -N, or
(3) the instance id of the ec2 instance.
  • Loading branch information
stevendanna committed May 13, 2012
1 parent 000a130 commit 2105fbc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/chef/knife/ec2_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,18 @@ def run

server = connection.servers.create(create_server_def)

unless tags.nil?
hashed_tags={}
tags.map{ |t| key,val=t.split('='); hashed_tags[key]=val}
hashed_tags["Name"] = locate_config_value(:chef_node_name) unless hashed_tags.keys.include? "Name"
hashed_tags={}
tags.map{ |t| key,val=t.split('='); hashed_tags[key]=val} unless tags.nil?

# Always set the Name tag
unless hashed_tags.keys.include? "Name"
hashed_tags["Name"] = locate_config_value(:chef_node_name) || server.id
end

hashed_tags.each_pair do |key,val|
connection.tags.create :key => key, :value => val, :resource_id => server.id
end
hashed_tags.each_pair do |key,val|
connection.tags.create :key => key, :value => val, :resource_id => server.id
end

msg_pair("Instance ID", server.id)
msg_pair("Flavor", server.flavor_id)
msg_pair("Image", server.image_id)
Expand Down

0 comments on commit 2105fbc

Please sign in to comment.