Commits

Fabian Topfstedt committed dfbe132

implemented region awareness, defaulting to us-east-1

  • Participants
  • Parent commits f7fbd53

Comments (0)

Files changed (2)

 import urllib2
 
 from boto.ec2.connection import EC2Connection
+from boto.ec2.regioninfo import RegionInfo
 from boto.exception import EC2ResponseError
 try:
     import snapshotter_conf as conf
 MYSQL_SOCKET = getattr(conf, 'MYSQL_SOCKET', None)
 MYSQL_USERNAME = getattr(conf, 'MYSQL_USERNAME', None)
 MYSQL_PASSWORD = getattr(conf, 'MYSQL_PASSWORD', None)
+REGION = getattr(conf, 'REGION', 'us-east-1')
+REGION_INFO = RegionInfo(endpoint='%s.ec2.amazonaws.com' % REGION, name=REGION)
 
 
 class Snapshotter(object):
     to the instance and give them custom descriptions that are easy to parse
     and keep track of.
     """
-    def __init__(self, aws_key, aws_secret, region='us-east-1', mountpoint='/',
-        mysql_host=None, mysql_socket=None, mysql_username=None, 
+    def __init__(self, aws_key, aws_secret, region=REGION, mountpoint='/',
+        mysql_host=None, mysql_socket=None, mysql_username=None,
         mysql_password=None):
         self.aws_key = aws_key
         self.aws_secret = aws_secret
         return response.read()
 
     def _get_instance_by_id(self, instance_id):
-        conn = EC2Connection(self.aws_key, self.aws_secret)
+        conn = EC2Connection(self.aws_key, self.aws_secret, region=REGION_INFO)
         for reservation in conn.get_all_instances([instance_id]):
             for instance in reservation.instances:
                 if instance.id == instance_id:
                 'minute': now.minute,
                 'weekday': now.weekday(),
                 'day_of_year': now.timetuple().tm_yday,
-                'days_since_epoche': (now - datetime(1970, 1, 1)).days, 
+                'days_since_epoche': (now - datetime(1970, 1, 1)).days,
                 'volume_id': volume_id,
             }
 

snapshotter_conf.py.example

 MYSQL_SOCKET = '/var/run/mysqld/mysqld.sock'
 MYSQL_USERNAME = 'user'
 MYSQL_PASSWORD = 'password'
+REGION = 'us-east-1'