Skip to content

Commit 9f91d94

Browse files
committed
First succesful end-to-end test without fab.
1 parent 0fd3a9c commit 9f91d94

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

‎beeswithmachineguns/bees.py‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
importos
2929
importre
3030
importtime
31+
importurllib2
3132

3233
importboto
3334
importparamiko
3435

3536
EC2_INSTANCE_TYPE='m1.small'
36-
STATE_FILENAME='~/.bees'
37+
STATE_FILENAME=os.path.expanduser('~/.bees')
3738

3839
username=None
3940
key_name=None
@@ -43,8 +44,8 @@
4344
instance_ids= []
4445
ifos.path.isfile(STATE_FILENAME):
4546
withopen(STATE_FILENAME, 'r') asf:
46-
username=f.readline()
47-
key_name=f.readline()
47+
username=f.readline().strip()
48+
key_name=f.readline().strip()
4849
text=f.read()
4950
instance_ids=text.split('\n')
5051

@@ -58,6 +59,9 @@ def _write_server_list(instances):
5859
f.write('%s\n'%key_name)
5960
f.write('\n'.join([instance.idforinstanceininstances]))
6061

62+
def_get_pem_path(key):
63+
returnos.path.expanduser('~/.ssh/%s.pem'%key)
64+
6165
# Methods
6266

6367
defup(count, group, zone, image_id, login, key):
@@ -76,6 +80,12 @@ def up(count, group, zone, image_id, login, key):
7680

7781
count=int(count)
7882

83+
pem_path=_get_pem_path()
84+
85+
ifnotos.path.isfile(pem_path):
86+
print'No key file found at %s'%pem_path
87+
return
88+
7989
print'Connecting to the hive.'
8090

8191
ec2_connection=boto.connect_ec2()
@@ -162,7 +172,7 @@ def _attack(params):
162172
client.connect(
163173
params['instance_name'],
164174
username=username,
165-
key_filename=key_name)
175+
key_filename=_get_pem_path(key_name))
166176

167177
print'Bee %i is firing his machine gun. Bang bang!'%params['i']
168178

@@ -276,7 +286,7 @@ def attack(url, n, c):
276286
print'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

281291
print'Organizing the swarm.'
282292

‎beeswithmachineguns/main.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def parse_options():
3434
"""
3535
command=sys,
3636
parser=OptionParser(usage="""
37-
bees COMMAND L [options]
37+
bees COMMAND [options]
3838
3939
Bees with Machine Guns
4040
@@ -100,12 +100,12 @@ def parse_options():
100100
ifnotoptions.key:
101101
parser.error('To spin up new instances you need to specify a key-pair name with -k')
102102

103-
bees.up(options.servers, options.group, options.zone, options.instance, options.key)
103+
bees.up(options.servers, options.group, options.zone, options.instance, options.login, options.key)
104104
elifcommand=="attack":
105105
ifnotoptions.url:
106106
parser.error("To run an attack you need to specify a url with -u")
107107

108-
bees.attack(options.url, options.number, options.concurrency)
108+
bees.attack(options.url, options.number, options.concurrent)
109109
elifcommand=="down":
110110
bees.down()
111111

0 commit comments

Comments
(0)