<commit_before>__description__ = """Module that deals with AMI baking!

We bake new AMIs to avoid long deployments and the occasional
runtime bugs that crop up while building brand new machines."""

from buildercore import core, utils, bootstrap, config

def ami_name(stackname):
    # elife-api.2015-12-31
    return "%s.%s" % (core.project_name_from_stackname(stackname), utils.ymd())

@core.requires_active_stack
def create_ami(stackname, name=None):
    "creates an AMI from the running stack"
    with core.stack_conn(stackname, username=config.BOOTSTRAP_USER):
        bootstrap.prep_ec2_instance()
    ec2 = core.find_ec2_instances(stackname)[0]
    kwargs = {
        'Name': ami_name(stackname) if name is None else name,
        'NoReboot': True,
        #'DryRun': True
    }
    # http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Instance.create_image
    ami = ec2.create_image(**kwargs)
    # http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Image
    ami.wait_until_exists()
    return str(ami.id) # this should be used to update the stack templates<commit_msg>Should wait until AMI can be used before returning<commit_after>__description__ = """Module that deals with AMI baking!

We bake new AMIs to avoid long deployments and the occasional
runtime bugs that crop up while building brand new machines."""

from buildercore import core, utils, bootstrap, config

def ami_name(stackname):
    # elife-api.2015-12-31
    return "%s.%s" % (core.project_name_from_stackname(stackname), utils.ymd())

@core.requires_active_stack
def create_ami(stackname, name=None):
    "creates an AMI from the running stack"
    with core.stack_conn(stackname, username=config.BOOTSTRAP_USER):
        bootstrap.prep_ec2_instance()
    ec2 = core.find_ec2_instances(stackname)[0]
    kwargs = {
        'Name': ami_name(stackname) if name is None else name,
        'NoReboot': True,
        #'DryRun': True
    }
    # http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Instance.create_image
    ami = ec2.create_image(**kwargs)
    # http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Image
    ami.wait_until_exists(Filters=[{
        'Name': 'state',
        'Values': ['available'],
    }])
    return str(ami.id) # this should be used to update the stack templates
{'fraction_non_alphanumeric': 0.11201022146507666, 'fraction_numerical': 0.016183986371379896, 'mean_word_length': 3.9348739495798317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3711938', 'n_tokens_mistral': 789, 'n_tokens_neox': 759, 'n_words': 187}