Exemplo n.º 1
0
def launch(pname, instance_id=None, alt_config='standalone', *repolist):
    stackname = cfn.generate_stack_from_input(pname, instance_id, alt_config)
    pdata = core.project_data_for_stackname(stackname)
    # ensure given alt config has masterless=True
    ensure(pdata['aws-alt'], "project has no alternate configurations")
    ensure(alt_config in pdata['aws-alt'],
           "unknown alt-config %r" % alt_config)
    ensure(pdata['aws-alt'][alt_config]['ec2']['masterless'],
           "alternative configuration %r has masterless=False" % alt_config)

    formula_revisions = parse_validate_repolist(pdata, *repolist)

    LOG.info('attempting to create masterless stack:')
    LOG.info('stackname:\t' + stackname)
    LOG.info('region:\t' + pdata['aws']['region'])
    LOG.info('formula_revisions:\t%s' % pformat(formula_revisions))

    if core.is_master_server_stack(stackname):
        checks.ensure_can_access_builder_private(pname)
    checks.ensure_stack_does_not_exist(stackname)

    bootstrap.create_stack(stackname)

    LOG.info('updating stack %s', stackname)
    bootstrap.update_stack(stackname,
                           service_list=['ec2', 'sqs', 's3'],
                           formula_revisions=formula_revisions)
Exemplo n.º 2
0
def switch_revision_update_instance(stackname,
                                    revision=None,
                                    concurrency='serial'):
    buildvars.switch_revision(stackname, revision)
    bootstrap.update_stack(stackname,
                           service_list=['ec2'],
                           concurrency=concurrency_for(stackname, concurrency))
Exemplo n.º 3
0
def update(master_stackname=None):
    "same as `cfn.update` but also removes any orphaned minion keys"
    master_stackname = master_stackname or core.find_master(utils.find_region())
    bootstrap.update_stack(master_stackname, service_list=[
        'ec2' # master-server should be a self-contained EC2 instance
    ])
    bootstrap.remove_all_orphaned_keys(master_stackname)
Exemplo n.º 4
0
def launch(pname, instance_id=None, alt_config='standalone', *repolist):
    stackname = cfn.generate_stack_from_input(pname, instance_id, alt_config)
    pdata = core.project_data_for_stackname(stackname)

    # ensure given alt config has masterless=True
    # todo: can the choices presented to the user remove non-masterless alt-configs?
    ensure(pdata['aws-alt'], "project has no alternate configurations")
    ensure(alt_config in pdata['aws-alt'], "unknown alt-config %r" % alt_config)
    ensure(pdata['aws-alt'][alt_config]['ec2']['masterless'], "alternative configuration %r has masterless=False" % alt_config)

    formula_revisions = parse_validate_repolist(pdata, *repolist)

    # todo: this is good UX but was simply debug output that got left in.
    # a better summary of what is to be created could be printed out,
    # preferably after the templates are printed out but before confirmation.
    LOG.info('attempting to create masterless stack:')
    LOG.info('stackname:\t' + stackname)
    LOG.info('region:\t' + pdata['aws']['region'])
    LOG.info('formula_revisions:\t%s' % pformat(formula_revisions))

    if core.is_master_server_stack(stackname):
        checks.ensure_can_access_builder_private(pname)
    checks.ensure_stack_does_not_exist(stackname)

    bootstrap.create_stack(stackname)

    LOG.info('updating stack %s', stackname)
    bootstrap.update_stack(stackname, service_list=['ec2', 'sqs', 's3'], formula_revisions=formula_revisions)
Exemplo n.º 5
0
def update(master_stackname=None):
    "same as `cfn.update` but also removes any orphaned minion keys"
    master_stackname = master_stackname or core.find_master(utils.find_region())
    bootstrap.update_stack(master_stackname, service_list=[
        'ec2' # master-server should be a self-contained EC2 instance
    ])
    bootstrap.remove_all_orphaned_keys(master_stackname)
Exemplo n.º 6
0
def create_update(stackname):
    if not core.stack_is_active(stackname):
        print 'stack does not exist, creating'
        bootstrap.create_stack(stackname)
    print 'updating stack'
    bootstrap.update_stack(stackname)
    return stackname
Exemplo n.º 7
0
def switch_revision_update_instance(stackname,
                                    revision=None,
                                    concurrency='serial'):
    "changes the revision of the stack's project and then calls highstate."
    buildvars.switch_revision(stackname, revision)
    bootstrap.update_stack(stackname,
                           service_list=['ec2'],
                           concurrency=concurrency_for(stackname, concurrency))
Exemplo n.º 8
0
def update_infrastructure(stackname, skip=None, start=['ec2']):
    """Limited update of the Cloudformation template and/or Terraform template.

    Resources can be added, but most of the existing ones are immutable.

    Some resources are updatable in place.

    Moreover, we never add anything related to EC2 instances as they are
    not supported anyway (they will come up as part of the template
    but without any software being on it)

    Moreover, EC2 instances must be running while this is executed or their
    resources like PublicIP will be inaccessible.

    Allows to skip EC2, SQS, S3 updates by passing `skip=ec2\\,sqs\\,s3`

    By default starts EC2 instances but this can be avoid by passing `start=`"""

    skip = skip.split(",") if skip else []
    start = start.split(",") if isinstance(start, str) else start or []

    (pname, _) = core.parse_stackname(stackname)
    more_context = {}
    context, delta, current_context = cfngen.regenerate_stack(
        stackname, **more_context)

    if _are_there_existing_servers(current_context) and 'ec2' in start:
        core_lifecycle.start(stackname)
    LOG.info("Create: %s", pformat(delta.plus))
    LOG.info("Update: %s", pformat(delta.edit))
    LOG.info("Delete: %s", pformat(delta.minus))
    LOG.info("Terraform delta: %s", delta.terraform)

    # see: `buildercore.config.BUILDER_NON_INTERACTIVE` for skipping confirmation prompts
    utils.confirm(
        'Confirming changes to CloudFormation and Terraform templates?')

    context_handler.write_context(stackname, context)

    cloudformation.update_template(stackname, delta.cloudformation)
    terraform.update_template(stackname)

    # TODO: move inside bootstrap.update_stack
    # EC2
    if _are_there_existing_servers(context) and not 'ec2' in skip:
        # the /etc/buildvars.json file may need to be updated
        buildvars.refresh(stackname, context)
        update(stackname)

    # SQS
    if context.get('sqs', {}) and not 'sqs' in skip:
        bootstrap.update_stack(stackname, service_list=['sqs'])

    # S3
    if context.get('s3', {}) and not 's3' in skip:
        bootstrap.update_stack(stackname, service_list=['s3'])
Exemplo n.º 9
0
def update_infrastructure(stackname, skip=None, start=['ec2']):
    """Limited update of the Cloudformation template and/or Terraform template.

    Resources can be added, but most of the existing ones are immutable.

    Some resources are updatable in place.

    Moreover, we never add anything related to EC2 instances as they are
    not supported anyway (they will come up as part of the template
    but without any software being on it)

    Moreover, EC2 instances must be running while this is executed or their
    resources like PublicIP will be inaccessible.

    Allows to skip EC2, SQS, S3 updates by passing `skip=ec2\\,sqs\\,s3`

    By default starts EC2 instances but this can be avoid by passing `start=`"""

    skip = skip.split(",") if skip else []
    start = start.split(",") if isinstance(start, str) else start or []

    (pname, _) = core.parse_stackname(stackname)
    more_context = {}
    context, delta, current_context = cfngen.regenerate_stack(stackname, **more_context)

    if _are_there_existing_servers(current_context) and 'ec2' in start:
        core_lifecycle.start(stackname)
    LOG.info("Create: %s", pformat(delta.plus))
    LOG.info("Update: %s", pformat(delta.edit))
    LOG.info("Delete: %s", pformat(delta.minus))
    LOG.info("Terraform delta: %s", delta.terraform)
    utils.confirm('Confirming changes to CloudFormation and Terraform templates?')

    context_handler.write_context(stackname, context)

    cloudformation.update_template(stackname, delta.cloudformation)
    terraform.update_template(stackname)

    # TODO: move inside bootstrap.update_stack
    # EC2
    if _are_there_existing_servers(context) and not 'ec2' in skip:
        # the /etc/buildvars.json file may need to be updated
        buildvars.refresh(stackname, context)
        update(stackname)

    # SQS
    if context.get('sqs', {}) and not 'sqs' in skip:
        bootstrap.update_stack(stackname, service_list=['sqs'])

    # S3
    if context.get('s3', {}) and not 's3' in skip:
        bootstrap.update_stack(stackname, service_list=['s3'])
Exemplo n.º 10
0
def remaster_minion(stackname):
    """tell minion who their new master is. 
    
    deletes the master's key on the minion
    updates the minion, which re-writes the minion config and eventually calls highstate

    * assumes you don't have ssh access to the minion
    * assumes writing keypairs to S3 is turned on"""
    print 're-mastering',stackname
    expected_key = core.stack_pem(stackname)
    if not os.path.exists(expected_key):
        download_keypair(stackname)
    with core.stack_conn(stackname, username=config.BOOTSTRAP_USER):
        sudo("rm -f /etc/salt/pki/minion/minion_master.pub")  # destroy the old master key we have
    bootstrap.update_stack(stackname)
Exemplo n.º 11
0
def update(stackname, autostart="0", concurrency='serial'):
    """Updates the environment within the stack's ec2 instance.
    Does *not* call Cloudformation's `update` command on the stack (see `update_infrastructure`)."""
    instances = _check_want_to_be_running(stackname, utils.strtobool(autostart))
    if not instances:
        return
    return bootstrap.update_stack(stackname, service_list=['ec2'], concurrency=concurrency)
Exemplo n.º 12
0
def update(stackname, autostart="0", concurrency='serial'):
    """Updates the environment within the stack's ec2 instance.
    does *not* call Cloudformation's `update` command on the stack"""
    instances = _check_want_to_be_running(stackname, strtobool(autostart))
    if not instances:
        return
    return bootstrap.update_stack(stackname, service_list=['ec2'], concurrency=concurrency)
Exemplo n.º 13
0
def remaster_minion(stackname):
    """tell minion who their new master is.

    deletes the master's key on the minion
    updates the minion, which re-writes the minion config and eventually calls highstate

    * assumes you don't have ssh access to the minion
    * assumes writing keypairs to S3 is turned on"""
    print 're-mastering', stackname
    expected_key = core.stack_pem(stackname)
    if not os.path.exists(expected_key):
        download_keypair(stackname)
    with core.stack_conn(stackname, username=config.BOOTSTRAP_USER):
        sudo("rm -f /etc/salt/pki/minion/minion_master.pub"
             )  # destroy the old master key we have
    bootstrap.update_stack(stackname)
Exemplo n.º 14
0
def launch(pname, instance_id=None, alt_config=None):
    stackname = generate_stack_from_input(pname, instance_id, alt_config)
    pdata = core.project_data_for_stackname(stackname)

    LOG.info('attempting to create %s (AWS region %s)', stackname,
             pdata['aws']['region'])

    if core.is_master_server_stack(stackname):
        checks.ensure_can_access_builder_private(pname)

    bootstrap.create_stack(stackname)

    LOG.info('updating stack %s', stackname)
    # TODO: highstate.sh (think it's run inside here) doesn't detect:
    # [34.234.95.137] out: [CRITICAL] The Salt Master has rejected this minion's public key!
    bootstrap.update_stack(stackname, service_list=['ec2', 'sqs', 's3'])
    setdefault('.active-stack', stackname)
Exemplo n.º 15
0
def update(stackname, autostart="0"):
    """Updates the environment within the stack's ec2 instance.
    does *not* call Cloudformation's `update` command on the stack"""
    instances = _check_want_to_be_running(stackname,
                                          bool(strtobool(autostart)))
    if not instances:
        return
    return bootstrap.update_stack(stackname,
                                  service_list=[],
                                  concurrency='serial')
Exemplo n.º 16
0
def launch(pname, instance_id=None, alt_config=None):
    try:
        stackname = generate_stack_from_input(pname, instance_id, alt_config)
    except checks.StackAlreadyExistsProblem as e:
        LOG.info('stack %s already exists', e.stackname)
        return

    pdata = core.project_data_for_stackname(stackname)

    LOG.info('attempting to create %s (AWS region %s)', stackname, pdata['aws']['region'])

    if core.is_master_server_stack(stackname):
        checks.ensure_can_access_builder_private(pname)

    bootstrap.create_stack(stackname)

    LOG.info('updating stack %s', stackname)
    # TODO: highstate.sh (think it's run inside here) doesn't detect:
    # [34.234.95.137] out: [CRITICAL] The Salt Master has rejected this minion's public key!
    bootstrap.update_stack(stackname, service_list=['ec2', 'sqs', 's3'])
    setdefault('.active-stack', stackname)
Exemplo n.º 17
0
def launch(pname, instance_id=None, alt_config='standalone', *repolist):
    stackname = cfn.generate_stack_from_input(pname, instance_id, alt_config)
    pdata = core.project_data_for_stackname(stackname)
    # ensure given alt config has masterless=True
    ensure(pdata['aws-alt'], "project has no alternate configurations")
    ensure(alt_config in pdata['aws-alt'], "unknown alt-config %r" % alt_config)
    ensure(pdata['aws-alt'][alt_config]['ec2']['masterless'], "alternative configuration %r has masterless=False" % alt_config)

    formula_revisions = parse_validate_repolist(pdata, *repolist)

    LOG.info('attempting to create masterless stack:')
    LOG.info('stackname:\t' + stackname)
    LOG.info('region:\t' + pdata['aws']['region'])
    LOG.info('formula_revisions:\t%s' % pformat(formula_revisions))

    if core.is_master_server_stack(stackname):
        checks.ensure_can_access_builder_private(pname)
    checks.ensure_stack_does_not_exist(stackname)

    bootstrap.create_stack(stackname)

    LOG.info('updating stack %s', stackname)
    bootstrap.update_stack(stackname, service_list=['ec2', 'sqs', 's3'], formula_revisions=formula_revisions)
Exemplo n.º 18
0
def update(stackname):
    """Updates the environment within the stack's ec2 instance. 

    does *not* call Cloudformation's `update` command on the stack"""
    return bootstrap.update_stack(stackname)
Exemplo n.º 19
0
def switch_revision_update_instance(stackname, revision=None):
    buildvars.switch_revision(stackname, revision)
    bootstrap.update_stack(stackname)
Exemplo n.º 20
0
def fix_bootstrap(stackname):
    """uploads the bootstrap script and re-runs the bootstrap process.
    Used when stack creation succeeds but the bootstrap script failed for some reason."""
    LOG.info('bootstrapping stack %s', stackname)
    bootstrap.update_stack(stackname)
    setdefault('.active-stack', stackname)
Exemplo n.º 21
0
def update_master():
    return bootstrap.update_stack(core.find_master(aws.find_region()))
Exemplo n.º 22
0
def update_master():
    return bootstrap.update_stack(core.find_master(aws.find_region()))
Exemplo n.º 23
0
def switch_revision_update_instance(stackname, revision=None, concurrency='serial'):
    buildvars.switch_revision(stackname, revision)
    bootstrap.update_stack(stackname, service_list=['ec2'], concurrency=concurrency_for(stackname, concurrency))
Exemplo n.º 24
0
def update(stackname, *service_list):
    """Updates the environment within the stack's ec2 instance.
    does *not* call Cloudformation's `update` command on the stack"""
    return bootstrap.update_stack(stackname, service_list)