Last active
December 14, 2015 20:08
-
-
Save pterk/5141448 to your computer and use it in GitHub Desktop.
fabfile to be used in conjunction with beeswithmachineguns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" fabfile to be used in conjunction with beeswithmachineguns | |
(Note, at time of wrinting (2013-03-12): use the version from | |
github. pip install beeswithmachineguns will install an old version | |
that does not support setting the zone) | |
Once bees is installed you can use the fabfile to execute fab commands | |
on the unleashed bees. The gist shows how to use ab as an example | |
which is probably better done with 'BWM' but you can see where to take | |
if from here (also note this example doesn't divide the work among the | |
bees -- *all instances* do 1000 requests): | |
# the ami is ubuntu server 12.10 | |
./bees up -z eu-west-1a -l ubuntu -k pterk-fashiolista-aws -g ssh-whitelist -i ami-640a0610 | |
fab install_ab | |
fab ab:n=1000,c=50,url=http://example.com/ | |
./bees down | |
""" | |
from fabric.api import * | |
from fabric.contrib.console import confirm | |
import boto | |
import boto.ec2 | |
from beeswithmachineguns import bees | |
def _get_hosts(instance_ids, zone): | |
if not instance_ids: | |
return [] | |
ec2_connection = boto.ec2.connect_to_region(bees._get_region(zone)) | |
reservations = ec2_connection.get_all_instances(instance_ids=instance_ids) | |
instances = [] | |
for reservation in reservations: | |
instances.extend(reservation.instances) | |
return [instance.public_dns_name for instance in instances] | |
env.user, key_name, zone, instance_ids = bees._read_server_list() | |
env.key_filename = bees._get_pem_path(key_name) | |
env.hosts = _get_hosts(instance_ids, zone) | |
@parallel | |
def install_ab(): | |
sudo('apt-get install -y apache2-utils') | |
@parallel | |
def ab(c, n, url): | |
run('ab -c {}, -n {} {}'.format(c,n,url)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment