Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
raise EnvironmentError if no credentials provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Monroy committed Sep 4, 2013
1 parent 1d6350e commit 86227fa
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions celerytasks/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
@task(name='ec2.build_layer')
def build_layer(layer, creds, params):
region = params.get('region', 'us-east-1')
conn = create_ec2_connection(
region, creds['access_key'], creds['secret_key'])
conn = create_ec2_connection(creds, region)
# create a new sg and authorize all ports
# use iptables on the host to firewall ports
sg = conn.create_security_group(layer, 'Created by Deis')
Expand All @@ -56,8 +55,7 @@ def destroy_layer(layer, creds, params):
# let's take a nap
time.sleep(5)
region = params.get('region', 'us-east-1')
conn = create_ec2_connection(
region, creds['access_key'], creds['secret_key'])
conn = create_ec2_connection(creds, region)
try:
conn.delete_security_group(layer)
except EC2ResponseError as e:
Expand All @@ -68,8 +66,7 @@ def destroy_layer(layer, creds, params):
@task(name='ec2.launch_node')
def launch_node(node_id, creds, params, init, ssh_username, ssh_private_key):
region = params.get('region', 'us-east-1')
conn = create_ec2_connection(
region, creds['access_key'], creds['secret_key'])
conn = create_ec2_connection(creds, region)
# find or create the security group for this formation
sg_name = params['layer']
sg = conn.get_all_security_groups(sg_name)[0]
Expand Down Expand Up @@ -134,8 +131,7 @@ def launch_node(node_id, creds, params, init, ssh_username, ssh_private_key):
@task(name='ec2.terminate_node')
def terminate_node(node_id, creds, params, provider_id):
region = params.get('region', 'us-east-1')
conn = create_ec2_connection(
region, creds['access_key'], creds['secret_key'])
conn = create_ec2_connection(creds, region)
if provider_id:
conn.terminate_instances([provider_id])
i = conn.get_all_instances([provider_id])[0].instances[0]
Expand Down Expand Up @@ -174,9 +170,12 @@ def run_node(node_id, ssh_username, fqdn, ssh_private_key, docker_args, command)

# utility functions

def create_ec2_connection(region, access_key, secret_key):
return ec2.connect_to_region(region, aws_access_key_id=access_key,
aws_secret_access_key=secret_key)
def create_ec2_connection(creds, region):
if not creds:
raise EnvironmentError('No credentials provided')
return ec2.connect_to_region(region,
aws_access_key_id=creds['access_key'],
aws_secret_access_key=creds['secret_key'])


def prepare_run_kwargs(params, init):
Expand Down

0 comments on commit 86227fa

Please sign in to comment.