1+ #!/usr/bin/env python
2+
13import argparse
24import re
35import sys
46import boto .ec2
7+ import time
58
69
710AMIS_TO_USER = {
@@ -55,6 +58,7 @@ def main():
5558 parser .add_argument ('--user' , help = 'override the ssh username for all hosts' )
5659 parser .add_argument ('--default-user' , help = 'default ssh username to use if we cannot detect from AMI name' )
5760 parser .add_argument ('--prefix' , default = '' , help = 'specify a prefix to prepend to all host names' )
61+ parser .add_argument ('--keydir' , default = '~/.ssh/' , help = 'location of private keys' )
5862
5963 args = parser .parse_args ()
6064
@@ -63,6 +67,11 @@ def main():
6367 counts_incremental = {}
6468 amis = {}
6569
70+ print "# Generated on " + time .asctime (time .localtime (time .time ()))
71+ print "# " + " " .join (sys .argv )
72+ print "# "
73+ print
74+
6675 for region in boto .ec2 .regions ():
6776 if region .name in BLACKLISTED_REGIONS :
6877 continue
@@ -132,7 +141,10 @@ def main():
132141 counts_incremental [id ] += 1
133142 id += '-' + str (counts_incremental [id ])
134143
135- print 'Host ' + args .prefix + id
144+ hostid = args .prefix + id
145+ hostid = hostid .replace (' ' , '_' ) # get rid of spaces
146+
147+ print 'Host ' + hostid
136148 print ' HostName ' + ip
137149
138150 try :
@@ -141,7 +153,12 @@ def main():
141153 except :
142154 pass
143155
144- print ' IdentityFile ~/.ssh/' + instance .key_name + '.pem'
156+ if args .keydir :
157+ keydir = args .keydir
158+ else :
159+ keydir = '~/.ssh/'
160+
161+ print ' IdentityFile ' + keydir + instance .key_name + '.pem'
145162 print ' StrictHostKeyChecking no' # just for me, removing this is usually a good choice
146163 print
147164
0 commit comments