Skip to content

Loading…

Full support for all AWS Availability Zones #41

Merged
merged 2 commits into from

2 participants

@nfarina

This commit allows beeswithmachineguns to operate properly in AWS regions besides N. Virginia. The boto library is simply configured to speak to the appropriate region in order to allow:

  • Launching of Private AMIs in other regions
  • Querying (via report) of instances running in other regions

Additionally, the boto library version has been bumped to a more recent 2.7 version which works great with BWMG.

nfarina added some commits
@nfarina nfarina Update boto library version 3bf82cb
@nfarina nfarina Full support for AWS regions outside us-east-1
- Sets up boto connection with the appropriate region (auto-detected from user-specified zone)
- Instances running in these regions can be queried successfully with "report" command
- Fixes launching of private AMIs outside default us-east-1 region
e9995ad
@cosmin cosmin merged commit 1c79975 into newsapps:master
@nfarina nfarina deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 22, 2013
  1. @nfarina

    Update boto library version

    nfarina committed
  2. @nfarina

    Full support for AWS regions outside us-east-1

    nfarina committed
    - Sets up boto connection with the appropriate region (auto-detected from user-specified zone)
    - Instances running in these regions can be queried successfully with "report" command
    - Fixes launching of private AMIs outside default us-east-1 region
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 12 deletions.
  1. +17 −11 beeswithmachineguns/bees.py
  2. +1 −1 requirements.txt
View
28 beeswithmachineguns/bees.py
@@ -32,6 +32,7 @@
import urllib2
import boto
+import boto.ec2
import paramiko
EC2_INSTANCE_TYPE = 't1.micro'
@@ -48,17 +49,19 @@ def _read_server_list():
with open(STATE_FILENAME, 'r') as f:
username = f.readline().strip()
key_name = f.readline().strip()
+ zone = f.readline().strip()
text = f.read()
instance_ids = text.split('\n')
print 'Read %i bees from the roster.' % len(instance_ids)
- return (username, key_name, instance_ids)
+ return (username, key_name, zone, instance_ids)
-def _write_server_list(username, key_name, instances):
+def _write_server_list(username, key_name, zone, instances):
with open(STATE_FILENAME, 'w') as f:
f.write('%s\n' % username)
f.write('%s\n' % key_name)
+ f.write('%s\n' % zone)
f.write('\n'.join([instance.id for instance in instances]))
def _delete_server_list():
@@ -67,13 +70,16 @@ def _delete_server_list():
def _get_pem_path(key):
return os.path.expanduser('~/.ssh/%s.pem' % key)
+def _get_region(zone):
+ return zone[:-1] # chop off the "d" in the "us-east-1d" to get the "Region"
+
# Methods
def up(count, group, zone, image_id, username, key_name):
"""
Startup the load testing server.
"""
- existing_username, existing_key_name, instance_ids = _read_server_list()
+ existing_username, existing_key_name, zone, instance_ids = _read_server_list()
if instance_ids:
print 'Bees are already assembled and awaiting orders.'
@@ -89,7 +95,7 @@ def up(count, group, zone, image_id, username, key_name):
print 'Connecting to the hive.'
- ec2_connection = boto.connect_ec2()
+ ec2_connection = boto.ec2.connect_to_region(_get_region(zone))
print 'Attempting to call up %i bees.' % count
@@ -119,7 +125,7 @@ def up(count, group, zone, image_id, username, key_name):
ec2_connection.create_tags(instance_ids, { "Name": "a bee!" })
- _write_server_list(username, key_name, reservation.instances)
+ _write_server_list(username, key_name, zone, reservation.instances)
print 'The swarm has assembled %i bees.' % len(reservation.instances)
@@ -127,13 +133,13 @@ def report():
"""
Report the status of the load testing servers.
"""
- username, key_name, instance_ids = _read_server_list()
+ username, key_name, zone, instance_ids = _read_server_list()
if not instance_ids:
print 'No bees have been mobilized.'
return
- ec2_connection = boto.connect_ec2()
+ ec2_connection = boto.ec2.connect_to_region(_get_region(zone))
reservations = ec2_connection.get_all_instances(instance_ids=instance_ids)
@@ -149,7 +155,7 @@ def down():
"""
Shutdown the load testing server.
"""
- username, key_name, instance_ids = _read_server_list()
+ username, key_name, zone, instance_ids = _read_server_list()
if not instance_ids:
print 'No bees have been mobilized.'
@@ -157,7 +163,7 @@ def down():
print 'Connecting to the hive.'
- ec2_connection = boto.connect_ec2()
+ ec2_connection = boto.ec2.connect_to_region(_get_region(zone))
print 'Calling off the swarm.'
@@ -274,7 +280,7 @@ def attack(url, n, c):
"""
Test the root url of this site.
"""
- username, key_name, instance_ids = _read_server_list()
+ username, key_name, zone, instance_ids = _read_server_list()
if not instance_ids:
print 'No bees are ready to attack.'
@@ -282,7 +288,7 @@ def attack(url, n, c):
print 'Connecting to the hive.'
- ec2_connection = boto.connect_ec2()
+ ec2_connection = boto.ec2.connect_to_region(_get_region(zone))
print 'Assembling bees.'
View
2 requirements.txt
@@ -1,2 +1,2 @@
-boto==2.0
+boto==2.7.0
paramiko==1.7.7.1
Something went wrong with that request. Please try again.