def boot_image(manifest, build_server, bootstrap_info, instance_type=None):

    credentials = {'access-key': build_server.run_settings['ec2-credentials']['access-key'],
                   'secret-key': build_server.run_settings['ec2-credentials']['secret-key']}
    from boto.ec2 import connect_to_region as ec2_connect
    ec2_connection = ec2_connect(bootstrap_info._ec2['region'],
                                 aws_access_key_id=credentials['access-key'],
                                 aws_secret_access_key=credentials['secret-key'])
    from boto.vpc import connect_to_region as vpc_connect
    vpc_connection = vpc_connect(bootstrap_info._ec2['region'],
                                 aws_access_key_id=credentials['access-key'],
                                 aws_secret_access_key=credentials['secret-key'])

    if manifest.volume['backing'] == 'ebs':
        from .images import EBSImage
        image = EBSImage(bootstrap_info._ec2['image'], ec2_connection)
    if manifest.volume['backing'] == 's3':
        from .images import S3Image
        image = S3Image(bootstrap_info._ec2['image'], ec2_connection)

    try:
        with run_instance(image, manifest, instance_type, ec2_connection, vpc_connection) as instance:
            yield instance
    finally:
        image.destroy()
Exemple #2
0
def boot_image(manifest, build_server, bootstrap_info, instance_type=None):

	credentials = {'access-key': build_server.run_settings['ec2-credentials']['access-key'],
	               'secret-key': build_server.run_settings['ec2-credentials']['secret-key']}
	from boto.ec2 import connect_to_region as ec2_connect
	ec2_connection = ec2_connect(bootstrap_info._ec2['region'],
	                             aws_access_key_id=credentials['access-key'],
	                             aws_secret_access_key=credentials['secret-key'])
	from boto.vpc import connect_to_region as vpc_connect
	vpc_connection = vpc_connect(bootstrap_info._ec2['region'],
	                             aws_access_key_id=credentials['access-key'],
	                             aws_secret_access_key=credentials['secret-key'])

	if manifest.volume['backing'] == 'ebs':
		from images import EBSImage
		image = EBSImage(bootstrap_info._ec2['image'], ec2_connection)
	if manifest.volume['backing'] == 's3':
		from images import S3Image
		image = S3Image(bootstrap_info._ec2['image'], ec2_connection)

	try:
		with run_instance(image, manifest, instance_type, ec2_connection, vpc_connection) as instance:
			yield instance
	finally:
		image.destroy()
Exemple #3
0
def main():
    if sys.version_info[:3] > (2, 7, 8):
        print "There is currently an SSL issue with Python 2.7.9 and newer."
        print "Please setup a virtualenv with Python 2.7.8 or less to proceed."
        sys.exit(1)
    new_hash = hashlib.md5(str(time.time())).hexdigest()[:8]
    parser = argparse.ArgumentParser()
    parser.add_argument("action", choices=ALLOWED_ACTIONS, action="store",
                        help="Action to take against the stack(s)")
    parser.add_argument("-l", "--location", nargs='*', action="store",
                        dest="locations", help="""If building, provide the
                        IP Address(es) from which ssh is allowed.\n
                        Example: './go.py build -l xx.xx.xx.xx yy.yy.yy.yy""",
                        type=ip_address_type, default=["0.0.0.0"])
    parser.add_argument('--region', action="store", dest="region",
                        default=DEFAULT_REGION)
    parser.add_argument('--hash', action="store", dest="hash_id",
                        help="""Define the hash to use for multiple
                        deployments.  If left blank, the hash will be
                        generated.""", default=new_hash)
    parser.add_argument('-u', '--user', action="store", dest="jenkins_user",
                        default=JENKINS_USER, help="Username for Jenkins")
    parser.add_argument('-e', '--email', action="store", dest="jenkins_email",
                        default=JENKINS_EMAIL, help="Email for Jenkins")
    parser.add_argument('-p', '--password', action="store_true",
                        dest="password_prompt",
                        help="Prompt for Jenkins Password")
    parser.add_argument('--full', action='store_true',
                        help="Always build all components. (VPC, RDS, etc.)")
    parser.add_argument('--warm', action='store_true',
                        help="Only build VPC, SG, and RDS")
    args = parser.parse_args()
    if args.password_prompt:
        print "WARNING: Password will be passed to CFN in plain text."
        args.jenkins_password = getpass.getpass()
    else:
        args.jenkins_password = JENKINS_PASSWORD
    connections = dict()
    connections['cfn'] = cfn_connect(args.region)
    if args.action == "info":
        info(connections)
        sys.exit(0)
    connections['codedeploy'] = codedeploy_connect(args.region)
    connections['ec2'] = ec2_connect(args.region)
    connections['iam'] = iam_connect(args.region)
    connections['s3'] = s3_connect(args.region)
    if args.action == "test":
        #  Test pieces here
        sys.exit(0)
    if args.action == "build":
        if not args.locations:
            print "Please provide at least one IP Address."
            parser.print_help()
            sys.exit(1)
        build(connections, args)
    elif args.action == "destroy":
        destroy(connections, args)
def main():
    new_hash = hashlib.md5(str(time.time())).hexdigest()[:8]
    parser = argparse.ArgumentParser()
    parser.add_argument("action",
                        choices=ALLOWED_ACTIONS,
                        action="store",
                        help="Action to take against the stack(s)")
    parser.add_argument("-l",
                        "--location",
                        nargs='*',
                        action="store",
                        dest="locations",
                        help="""If building, provide the
                        IP Address(es) from which ssh is allowed.\n
                        Example: './go.py build -l xx.xx.xx.xx yy.yy.yy.yy""",
                        type=ip_address_type,
                        default=["0.0.0.0"])
    parser.add_argument('--region',
                        action="store",
                        dest="region",
                        default=DEFAULT_REGION)
    parser.add_argument('--hash',
                        action="store",
                        dest="hash_id",
                        help="""Define the hash to use for multiple
                        deployments.  If left blank, the hash will be
                        generated.""",
                        default=new_hash)
    parser.add_argument('--full',
                        action='store_true',
                        help="Always build all components. (VPC, RDS, etc.)")
    args = parser.parse_args()
    full = args.full
    connections = dict()
    connections['cfn'] = cfn_connect(args.region)
    if args.action == "info":
        info(connections)
        sys.exit(0)
    connections['codedeploy'] = codedeploy_connect(args.region)
    connections['ec2'] = ec2_connect(args.region)
    connections['iam'] = iam_connect(args.region)
    connections['main_s3'] = s3_connect(MAIN_S3_BUCKET_REGION)
    connections['s3'] = s3_connect(args.region)
    if args.action == "test":
        #  Test pieces here
        sys.exit(0)
    if args.action == "build":
        if not args.locations:
            print "Please provide at least one IP Address."
            parser.print_help()
            sys.exit(1)
        build(connections, args.region, args.locations, args.hash_id, full)
    elif args.action == "destroy":
        destroy(connections, args.region)
Exemple #5
0
def main():
    new_hash = hashlib.md5(str(time.time())).hexdigest()[:8]
    parser = argparse.ArgumentParser()
    parser.add_argument("action", choices=ALLOWED_ACTIONS, action="store",
                        help="Action to take against the stack(s)")
    parser.add_argument("-l", "--location", nargs='*', action="store",
                        dest="locations", help="""If building, provide the
                        IP Address(es) from which ssh is allowed.\n
                        Example: './go.py build -l xx.xx.xx.xx yy.yy.yy.yy""",
                        type=ip_address_type, default=["0.0.0.0"])
    parser.add_argument('--region', action="store", dest="region",
                        default=DEFAULT_REGION)
    parser.add_argument('--hash', action="store", dest="hash_id",
                        help="""Define the hash to use for multiple
                        deployments.  If left blank, the hash will be
                        generated.""", default=new_hash)
    parser.add_argument('--full', action='store_true',
                        help="Always build all components. (VPC, RDS, etc.)")
    args = parser.parse_args()
    full = args.full
    connections = dict()
    connections['cfn'] = cfn_connect(args.region)
    if args.action == "info":
        info(connections)
        sys.exit(0)
    connections['codedeploy'] = codedeploy_connect(args.region)
    connections['ec2'] = ec2_connect(args.region)
    connections['iam'] = iam_connect(args.region)
    connections['main_s3'] = s3_connect(MAIN_S3_BUCKET_REGION)
    connections['s3'] = s3_connect(args.region)
    if args.action == "test":
        #  Test pieces here
        sys.exit(0)
    if args.action == "build":
        if not args.locations:
            print "Please provide at least one IP Address."
            parser.print_help()
            sys.exit(1)
        build(connections, args.region, args.locations, args.hash_id, full)
    elif args.action == "destroy":
        destroy(connections, args.region)
from boto.ec2.blockdevicemapping import BlockDeviceMapping
from urlparse import urljoin
from uuid import uuid4
from sqlalchemy import create_engine, MetaData
from sqlalchemy.sql import select, func
from subprocess import check_output, CalledProcessError
from tempfile import mkstemp
import crontab
import json

# Create flask app
app = Flask(__name__)
app.config.from_object('config')

# Connect to AWS
ec2 = ec2_connect(app.config['AWS_REGION'])
ses = ses_connect('us-east-1')  # only supported region!
s3 = s3_connect(app.config['AWS_REGION'])
bucket = s3.get_bucket(app.config['TEMPORARY_BUCKET'], validate=False)
code_bucket = s3.get_bucket(app.config['CODE_BUCKET'], validate=False)

# Create login manager
login_manager = LoginManager()
login_manager.anonymous_user = AnonymousUser

# Initialize browser id login
browser_id = BrowserID()

# Cron-related constants:
CRON_IDX_MIN = 0
CRON_IDX_HOUR = 1
Exemple #7
0
from flask import Flask, render_template, request, redirect, url_for
from flask.ext.login import LoginManager, login_required, current_user
from flask.ext.browserid import BrowserID
from user import User, AnonymousUser
from boto.ec2 import connect_to_region as ec2_connect
from boto.ses import connect_to_region as ses_connect
from boto.s3 import connect_to_region as s3_connect
from urlparse import urljoin
from uuid import uuid4

# Create flask app
app = Flask(__name__)
app.config.from_object("config")

# Connect to AWS
ec2 = ec2_connect(app.config["AWS_REGION"])
ses = ses_connect("us-east-1")  # only supported region!
s3 = s3_connect(app.config["AWS_REGION"])
bucket = s3.get_bucket(app.config["TEMPORARY_BUCKET"], validate=False)

# Create login manager
login_manager = LoginManager()
login_manager.anonymous_user = AnonymousUser

# Initialize browser id login
browser_id = BrowserID()


def abs_url_for(rule, **options):
    return urljoin(request.url_root, url_for(rule, **options))
Exemple #8
0
#!/usr/bin/env python

from boto.ec2 import connect_to_region as ec2_connect
from boto.ses import connect_to_region as ses_connect
from dateutil.parser import parse as parse_date
from datetime import datetime
import config

ec2 = ec2_connect(config.AWS_REGION)
ses = ses_connect('us-east-1')  # only supported region!


def main():
    reservations = ec2.get_all_reservations(
        filters={'tag:Application': config.INSTANCE_APP_TAG})
    for reservation in reservations:
        for instance in reservation.instances:
            time = datetime.utcnow() - parse_date(instance.launch_time,
                                                  ignoretz=True)
            if time.days >= 1:
                name = instance.tags.get('name', instance.id)
                ses.send_email(
                    source=config.EMAIL_SOURCE,
                    subject="telemetry-analysis worker instance %s terminated!"
                    % name,
                    body=
                    "We've terminated your instance as it has been running for over 24 hours!",
                    to_addresses=[instance.tags['Owner']])
                instance.terminate()

Exemple #9
0
from datetime import datetime, timedelta
from dateutil.parser import parse as parse_date
from subprocess import check_output, CalledProcessError
from tempfile import mkstemp
import crontab
import json
import re
import os.path

# Create flask app
app = Flask(__name__)
app.config.from_object('config')

# Connect to AWS
emr  = emr_connect(app.config['AWS_REGION'])
ec2 = ec2_connect(app.config['AWS_REGION'])
ses = ses_connect(app.config['AWS_REGION'])
s3  = s3_connect(app.config['AWS_REGION'])
bucket = s3.get_bucket(app.config['TEMPORARY_BUCKET'], validate = False)
code_bucket = s3.get_bucket(app.config['CODE_BUCKET'], validate = False)

# Create login manager
login_manager = LoginManager()
login_manager.anonymous_user = AnonymousUser

# Initialize browser id login
browser_id = BrowserID()

# Cron-related constants:
CRON_IDX_MIN  = 0
CRON_IDX_HOUR = 1
#!/usr/bin/env python

from boto.ec2 import connect_to_region as ec2_connect
from boto.ses import connect_to_region as ses_connect
from dateutil.parser import parse as parse_date
from datetime import datetime
import config

ec2 = ec2_connect(config.AWS_REGION)
ses = ses_connect(config.AWS_REGION)

def main():
    reservations = ec2.get_all_reservations(
        filters = {'tag:Application':  config.INSTANCE_APP_TAG}
    )
    for reservation in reservations:
        for instance in reservation.instances:
            time = datetime.utcnow() - parse_date(instance.launch_time, ignoretz = True)
            if time.days >= 1:
                name = instance.tags.get('name', instance.id)
                ses.send_email(
                    source          = config.EMAIL_SOURCE,
                    subject         = "telemetry-analysis worker instance %s terminated!" % name,
                    body            = "We've terminated your instance as it has been running for over 24 hours!",
                    to_addresses    = [instance.tags['Owner']]
                )
                instance.terminate()

if __name__ == '__main__':
    main()