Method: Tunl::Base#create_key_pair

Defined in:
lib/tunl.rb

#create_key_pair(name) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/tunl.rb', line 55

def create_key_pair(name)
	log "create", "key pair tunl_#{name}"
	filepath = key_pair_filepath(name)
	key_pair = ec2.create_key_pair("tunl_#{name}")
	File.open(filepath, 'w') { |f| f.write(key_pair[:aws_material]) }
	FileUtils.chmod 0400, filepath
rescue Aws::AwsError => e
   if e.message =~ /already exists/
     # WARNING : this could be dangerous.
     delete_key_pair(name)
     retry
   else
     raise e
   end
end