bootstrap-vz/providers/ec2/tasks/connection.py
Anders Ingemann 96028f96e1 Various improvements and additions.
I couldn't be bothered to untangle this, so here it goes:
* Log colors depending on loglevel
* Simplified Filelogger
* Remove description=None from basetask
* create_list creates task list from argument now
* Task rollback feature: If a task fails, the tasklist calls rollback() on the completed tasks in reverse order
* Added TaskException to common.exceptions as a base to extend from
* Added TriggerRollback task to common.tasks for development purposes
* An EBS volume for bootstrapping is now created and attached to the instance (including rollback actions)
* EC2 Connect task now depends on host.GetInfo
2013-07-08 23:14:00 +02:00

42 lines
1.6 KiB
Python

from base import Task
from common import phases
import host
class GetCredentials(Task):
description = 'Getting AWS credentials'
phase = phases.preparation
def run(self, info):
super(GetCredentials, self).run(info)
info.credentials = self.get_credentials(info.manifest)
def get_credentials(self, manifest):
from os import getenv
# manifest overrides environment
if(manifest.credentials['access-key'] and manifest.credentials['secret-key']):
return {'access_key': manifest.credentials['access-key'],
'secret_key': manifest.credentials['secret-key']}
if(getenv('EC2_ACCESS_KEY') and getenv('EC2_SECRET_KEY')):
return {'access_key': getenv('EC2_ACCESS_KEY'),
'secret_key': getenv('EC2_SECRET_KEY')}
if(bool(manifest.credentials['access-key']) != bool(manifest.credentials['secret-key'])):
raise RuntimeError('Both the access key and secret key must be specified in the manifest.')
if(bool(getenv('EC2_ACCESS_KEY')) != bool(getenv('EC2_SECRET_KEY'))):
raise RuntimeError('Both the access key and secret key must be specified as environment variables.')
raise RuntimeError('No ec2 credentials found.')
class Connect(Task):
description = 'Connecting to EC2'
phase = phases.preparation
after = [GetCredentials, host.GetInfo]
def run(self, info):
super(Connect, self).run(info)
from boto.ec2 import connect_to_region
info.connection = connect_to_region(info.host['region'],
aws_access_key_id=info.credentials['access_key'],
aws_secret_access_key=info.credentials['secret_key'])