2828import os
2929import re
3030import time
31+ import urllib2
3132
3233import boto
3334import paramiko
3435
3536EC2_INSTANCE_TYPE = 'm1.small'
36- STATE_FILENAME = '~/.bees'
37+ STATE_FILENAME = os . path . expanduser ( '~/.bees' )
3738
3839username = None
3940key_name = None
4344instance_ids = []
4445if os .path .isfile (STATE_FILENAME ):
4546with open (STATE_FILENAME , 'r' ) as f :
46- username = f .readline ()
47- key_name = f .readline ()
47+ username = f .readline (). strip ()
48+ key_name = f .readline (). strip ()
4849text = f .read ()
4950instance_ids = text .split ('\n ' )
5051
@@ -58,6 +59,9 @@ def _write_server_list(instances):
5859f .write ('%s\n ' % key_name )
5960f .write ('\n ' .join ([instance .id for instance in instances ]))
6061
62+ def _get_pem_path (key ):
63+ return os .path .expanduser ('~/.ssh/%s.pem' % key )
64+
6165# Methods
6266
6367def up (count , group , zone , image_id , login , key ):
@@ -76,6 +80,12 @@ def up(count, group, zone, image_id, login, key):
7680
7781count = int (count )
7882
83+ pem_path = _get_pem_path ()
84+
85+ if not os .path .isfile (pem_path ):
86+ print 'No key file found at %s' % pem_path
87+ return
88+
7989print 'Connecting to the hive.'
8090
8191ec2_connection = boto .connect_ec2 ()
@@ -162,7 +172,7 @@ def _attack(params):
162172client .connect (
163173params ['instance_name' ],
164174username = username ,
165- key_filename = key_name )
175+ key_filename = _get_pem_path ( key_name ) )
166176
167177print 'Bee %i is firing his machine gun. Bang bang!' % params ['i' ]
168178
@@ -276,7 +286,7 @@ def attack(url, n, c):
276286print 'Stinging URL so it will be cached for the attack.'
277287
278288# Ping url so it will be cached for testing
279- local ( 'curl %s >> /dev/null' % url )
289+ urllib2 . urlopen ( url )
280290
281291print 'Organizing the swarm.'
282292
0 commit comments