Skip to content

Commit 0fd3a9c

Browse files
committed
Rewrote help text. Made login user configurable.
1 parent 47e1ccc commit 0fd3a9c

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

‎beeswithmachineguns/bees.py‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@
3333
importparamiko
3434

3535
EC2_INSTANCE_TYPE='m1.small'
36+
STATE_FILENAME='~/.bees'
3637

37-
STATE_FILENAME='theswarm.txt'
38+
username=None
39+
key_name=None
3840

3941
# Load state from file
4042

4143
instance_ids= []
4244
ifos.path.isfile(STATE_FILENAME):
4345
withopen(STATE_FILENAME, 'r') asf:
46+
username=f.readline()
47+
key_name=f.readline()
4448
text=f.read()
4549
instance_ids=text.split('\n')
4650

@@ -50,14 +54,22 @@
5054

5155
def_write_server_list(instances):
5256
withopen(STATE_FILENAME, 'w') asf:
57+
f.write('%s\n'%username)
58+
f.write('%s\n'%key_name)
5359
f.write('\n'.join([instance.idforinstanceininstances]))
5460

5561
# Methods
5662

57-
defup(count, group, zone, image_id, key_name):
63+
defup(count, group, zone, image_id, login, key):
5864
"""
5965
Startup the load testing server.
6066
"""
67+
globalusername
68+
globalkey_name
69+
70+
username=login
71+
key_name=key
72+
6173
ifinstance_ids:
6274
print'Bees are already assembled and awaiting orders.'
6375
return
@@ -140,14 +152,17 @@ def _attack(params):
140152
141153
Intended for use with multiprocessing.
142154
"""
155+
globalusername
156+
globalkey_name
157+
143158
print'Bee %i is joining the swarm.'%params['i']
144159

145160
client=paramiko.SSHClient()
146161
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
147162
client.connect(
148163
params['instance_name'],
149-
username='newsapps',
150-
key_filename='/Users/sk/.ssh/frakkingtoasters.pem')
164+
username=username,
165+
key_filename=key_name)
151166

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

‎beeswithmachineguns/main.py‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,59 +34,65 @@ def parse_options():
3434
"""
3535
command=sys,
3636
parser=OptionParser(usage="""
37-
bwmg COMMAND L [options]
37+
bees COMMAND L [options]
3838
3939
Bees with Machine Guns
4040
4141
A utility for arming (creating) many bees (small EC2 instances) to attack
4242
(load test) targets (web applications).
4343
4444
commands:
45-
up start a batch of load testing servers
46-
attack begin the attack on a specific url
47-
down shutdown and deactivate the load testing servers
45+
up Start a batch of load testing servers.
46+
attack Begin the attack on a specific url.
47+
down Shutdown and deactivate the load testing servers.
4848
""")
4949

50-
up_group=OptionGroup(parser, "up options", "Options for the up command")
50+
up_group=OptionGroup(parser, "up",
51+
"""In order to spin up new servers you will need to specify at least the -k command, which is the name of the EC2 keypair to use for creating and connecting to the new servers. The bees will expect to find a .pem file with this name in ~/.ssh/.""")
52+
53+
# Required
54+
up_group.add_option('-k', '--key', metavar="KEY", nargs=1,
55+
action='store', dest='key', type='string',
56+
help="The ssh key pair name to use to connect to the new servers.")
5157

5258
up_group.add_option('-s', '--servers', metavar="SERVERS", nargs=1,
5359
action='store', dest='servers', type='int', default=5,
54-
help="number of servers to start (default: 5)")
60+
help="The number of servers to start (default: 5).")
5561
up_group.add_option('-g', '--group', metavar="GROUP", nargs=1,
5662
action='store', dest='group', type='string', default='staging',
57-
help="the security group to run the instances under (default: staging)")
63+
help="The security group to run the instances under (default: staging).")
5864
up_group.add_option('-z', '--zone', metavar="ZONE", nargs=1,
5965
action='store', dest='zone', type='string', default='us-east-1d',
60-
help="the availability zone to start the instances in (default: us-east-1d)")
66+
help="The availability zone to start the instances in (default: us-east-1d).")
6167
up_group.add_option('-i', '--instance', metavar="INSTANCE", nargs=1,
6268
action='store', dest='instance', type='string', default='ami-ff17fb96',
63-
help="the instance-id to start each server from (default ami-ff17fb96)")
64-
up_group.add_option('-k', '--key', metavar="KEY", nargs=1,
65-
action='store', dest='key', type='string',
66-
help="the ssh key pair name to use to connect to the new servers")
69+
help="The instance-id to use for each server from (default: ami-ff17fb96).")
70+
up_group.add_option('-l', '--login', metavar="LOGIN", nargs=1,
71+
action='store', dest='login', type='string', default='newsapps',
72+
help="The ssh username name to use to connect to the new servers (default: newsapps).")
6773

6874
parser.add_option_group(up_group)
6975

70-
attack_group=OptionGroup(parser, "attack options", "Options for the attack command.")
76+
attack_group=OptionGroup(parser, "attack", "")
77+
78+
# Required
79+
attack_group.add_option('-u', '--url', metavar="URL", nargs=1,
80+
action='store', dest='url', type='string',
81+
help="URL of the target to attack.")
7182

7283
attack_group.add_option('-n', '--number', metavar="NUMBER", nargs=1,
7384
action='store', dest='number', type='int', default=1000,
74-
help="number of total connections to make to the target (default: 1000)")
75-
85+
help="The number of total connections to make to the target (default: 1000).")
7686
attack_group.add_option('-c', '--concurrent', metavar="CONCURRENT", nargs=1,
7787
action='store', dest='concurrent', type='int', default=100,
78-
help="number of concurrent connections to make to the target (default: 100)")
79-
80-
attack_group.add_option('-u', '--url', metavar="URL", nargs=1,
81-
action='store', dest='url', type='string',
82-
help="url of the target to attack")
88+
help="The number of concurrent connections to make to the target (default: 100).")
8389

8490
parser.add_option_group(attack_group)
8591

8692
(options, args) =parser.parse_args()
8793

8894
iflen(args) <=0:
89-
parser.error("Please enter a command")
95+
parser.error("Please enter a command.")
9096

9197
command=args[0]
9298

0 commit comments

Comments
(0)