Exemple #1
0
def _check_want_to_be_running(stackname, autostart=False):
    try:
        context = context_handler.load_context(stackname)

        if 'ec2' in context:
            # early check can only be made if the instance actually declares
            # ec2 True/False in its context
            # otherwise, don't make assumptions and go ahead
            if not context['ec2']:
                return False

    except context_handler.MissingContextFile as e:
        LOG.warn(e)

    instance_list = core.find_ec2_instances(stackname, allow_empty=True)
    num_instances = len(instance_list)
    if num_instances >= 1:
        return instance_list

    if not autostart:
        should_start = utils._pick(
            'should_start', [True, False],
            message='Stack not running. Should it be started?')
        if not should_start:
            return False

    core_lifecycle.start(stackname)
    # to get the ip addresses that are assigned to the now-running instances
    # and that weren't there before
    return core.find_ec2_instances(stackname)
Exemple #2
0
def _check_want_to_be_running(stackname, autostart=False):
    try:
        context = context_handler.load_context(stackname)
        if not _are_there_existing_servers(context):
            return False

    except context_handler.MissingContextFile as e:
        LOG.warn(e)

    instance_list = core.find_ec2_instances(stackname, allow_empty=True)
    num_instances = len(instance_list)
    if num_instances >= 1:
        return instance_list

    if not autostart:
        should_start = utils._pick(
            'should_start', [True, False],
            message='Stack not running. Should it be started?')
        if not should_start:
            return False

    core_lifecycle.start(stackname)
    # another call to get the ip addresses that are assigned to the now-running
    # instances and that weren't there before
    return core.find_ec2_instances(stackname)
Exemple #3
0
def _check_want_to_be_running(stackname):
    instance_list = core.find_ec2_instances(stackname)
    num_instances = len(instance_list)
    if num_instances >= 1:
        return instance_list

    should_start = utils._pick(
        'should_start', [True, False],
        message='Stack not running. Should it be started?')
    if not should_start:
        return False

    core_lifecycle.start(stackname)
    # to get the ip addresses that are assigned to the now-running instances
    # and that weren't there before
    return core.find_ec2_instances(stackname)
Exemple #4
0
def _check_want_to_be_running(stackname, autostart=False):
    try:
        context = context_handler.load_context(stackname)
        if not _are_there_existing_servers(context):
            return False

    except context_handler.MissingContextFile as e:
        LOG.warn(e)

    instance_list = core.find_ec2_instances(stackname, allow_empty=True)
    num_instances = len(instance_list)
    if num_instances >= 1:
        return instance_list

    if not autostart:
        should_start = utils._pick('should_start', [True, False], message='Stack not running. Should it be started?')
        if not should_start:
            return False

    core_lifecycle.start(stackname)
    # another call to get the ip addresses that are assigned to the now-running
    # instances and that weren't there before
    return core.find_ec2_instances(stackname)
    def test_restart_one_stopped(self):
        "multiple nodes can be restarted from a mixed state"
        node1 = core.find_ec2_instances(self.stackname)[0]
        node1.stop()
        node1.wait_until_stopped()
        history = lifecycle.restart(self.stackname)

        # two nodes rebooting in serial, node 1 first, node1 stopped
        expected_history = [
            # node1, stopped -> running
            [(1, 'stopped'), (2, 'running')],
            [(1, 'running'), (2, 'running')],

            # node2, running -> stopped -> running
            [(1, 'running'), (2, 'stopped')],
            [(1, 'running'), (2, 'running')]
        ]
        self.assertEqual(expected_history, self._remove_transient_states(history))
Exemple #6
0
def create_ami(stackname, name=None):
    "creates an AMI from the running stack"
    with core.stack_conn(stackname, username=config.BOOTSTRAP_USER):
        bootstrap.clean_stack_for_ami()
    ec2 = core.find_ec2_instances(stackname)[0]
    kwargs = {
        'Name': name or ami_name(stackname),
        '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
Exemple #7
0
def create_ami(stackname, name=None):
    "creates an AMI from the running stack"
    with core.stack_conn(stackname, username=config.BOOTSTRAP_USER):
        bootstrap.clean_stack_for_ami()
    ec2 = core.find_ec2_instances(stackname)[0]
    kwargs = {
        'Name': name or ami_name(stackname),
        '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
    def test_restart_one_stopped(self):
        "multiple nodes can be restarted from a mixed state"
        node1 = core.find_ec2_instances(self.stackname)[0]
        node1.stop()
        node1.wait_until_stopped()
        history = lifecycle.restart(self.stackname)

        # two nodes rebooting in serial, node 1 first, node1 stopped
        expected_history = [
            # node1, stopped -> running
            [(1, 'stopped'), (2, 'running')],
            [(1, 'running'), (2, 'running')],

            # node2, running -> stopped -> running
            [(1, 'running'), (2, 'stopped')],
            [(1, 'running'), (2, 'running')]
        ]
        self.assertEqual(expected_history,
                         self._remove_transient_states(history))
Exemple #9
0
def create_ami(stackname):
    "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 = {
        'instance_id': ec2.id,
        'name': core.ami_name(stackname),
        'no_reboot': True,
        #'dry_run': True
    }
    conn = core.connect_aws_with_stack(stackname, 'ec2')
    ami_id = conn.create_image(**kwargs)

    # image.__dict__ == {'root_device_type': u'ebs', 'ramdisk_id': None, 'id': u'ami-6bc99d0e', 'owner_alias': None, 'billing_products': [], 'tags': {}, 'platform': None, 'state': u'pending', 'location': u'512686554592/elife-lax.2015-10-15', 'type': u'machine', 'virtualization_type': u'hvm', 'sriov_net_support': u'simple', 'architecture': u'x86_64', 'description': None, 'block_device_mapping': {}, 'kernel_id': None, 'owner_id': u'512686554592', 'is_public': False, 'instance_lifecycle': None, 'creationDate': u'2015-10-15T16:07:21.000Z', 'name': u'elife-lax.2015-10-15', 'hypervisor': u'xen', 'region': RegionInfo:us-east-1, 'item': u'\n        ', 'connection': EC2Connection:ec2.us-east-1.amazonaws.com, 'root_device_name': None, 'ownerId': u'512686554592', 'product_codes': []}
    def is_pending():
        image = conn.get_all_images(image_ids=[ami_id])[0]
        return image.state == 'pending'

    utils.call_while(is_pending,
                     update_msg="Waiting for AWS to bake AMI %s ... " % ami_id)
    return str(ami_id)  # this should be used to update the stack templates
 def test_find_ec2_instances(self):
     self.assertEqual([], core.find_ec2_instances('dummy1--prod', allow_empty=True))
 def test_find_ec2_instances(self):
     self.assertEquals([], core.find_ec2_instances('dummy1--prod'))
Exemple #12
0
 def test_core_find_ec2_instances(self):
     self.assertEqual(len(core.find_ec2_instances(self.stackname)), 1) # 1 node is running
     self.assertEqual(len(core.find_ec2_instances(self.stackname, state='stopped', allow_empty=True)), 0) # 0 nodes are stopped
 def test_find_ec2_instances(self):
     self.assertEqual([], core.find_ec2_instances('dummy1--prod', allow_empty=True))