示例#1
0
文件: cfn.py 项目: stephenwf/builder
def generate_stack_from_input(pname, instance_id=None):
    """creates a new CloudFormation file for the given project."""
    if not instance_id:
        default_instance_id = core_utils.ymd()
        instance_id = utils.uin("instance id", default_instance_id)
    stackname = core.mk_stackname(pname, instance_id)
    more_context = {'stackname': stackname}

    # prompt user for alternate configurations
    pdata = project.project_data(pname)
    if 'aws-alt' in pdata:

        def helpfn(altkey):
            try:
                return pdata['aws-alt'][altkey]['description']
            except KeyError:
                return None

        default = 'skip this step'
        alt_config = [default] + pdata['aws-alt'].keys()
        alt_config = utils._pick('alternative config',
                                 alt_config,
                                 helpfn=helpfn)
        if alt_config != default:
            more_context['alt-config'] = alt_config
    cfngen.generate_stack(pname, **more_context)
    return stackname
示例#2
0
def switch_revision(stackname, revision=None):
    bvars = _retrieve_build_vars(stackname)
    if revision is None:
        revision = utils.uin('revision', None)

    _ensure_revision_is_valid(revision)

    if 'revision' in bvars and revision == bvars['revision']:
        print 'FYI, the instance is already on that revision!'
        return

    new_data = bvars
    new_data['revision'] = revision
    _update_remote_bvars(stackname, new_data)    
示例#3
0
def switch_revision(stackname, revision=None, concurrency=None):
    if revision is None:
        revision = utils.uin('revision', None)

    def _switch_revision_single_ec2_node():
        buildvars = _retrieve_build_vars()

        if 'revision' in buildvars and revision == buildvars['revision']:
            print('FYI, the instance is already on that revision!')
            return

        new_data = buildvars
        new_data['revision'] = revision
        _update_remote_bvars(stackname, new_data)

    stack_all_ec2_nodes(stackname, _switch_revision_single_ec2_node, username=BOOTSTRAP_USER, concurrency=concurrency)
示例#4
0
def switch_revision(stackname, revision=None, concurrency=None):
    if revision is None:
        revision = utils.uin('revision', None)

    def _switch_revision_single_ec2_node():
        buildvars = _retrieve_build_vars()

        if 'revision' in buildvars and revision == buildvars['revision']:
            print('FYI, the instance is already on that revision!')
            return

        new_data = buildvars
        new_data['revision'] = revision
        _update_remote_bvars(stackname, new_data)

    stack_all_ec2_nodes(stackname, _switch_revision_single_ec2_node, username=BOOTSTRAP_USER, concurrency=concurrency)
示例#5
0
def generate_stack_from_input(pname, instance_id=None, alt_config=None):
    """creates a new CloudFormation file for the given project."""
    instance_id = instance_id or utils.uin("instance id", core_utils.ymd())
    stackname = core.mk_stackname(pname, instance_id)
    checks.ensure_stack_does_not_exist(stackname)
    more_context = {'stackname': stackname}

    pdata = project.project_data(pname)
    if alt_config:
        ensure(
            'aws-alt' in pdata,
            "alternative configuration name given, but project has no alternate configurations"
        )

    # prompt user for alternate configurations
    if pdata['aws-alt']:
        default = 'skip'

        def helpfn(altkey):
            if altkey == default:
                return 'uses the default configuration'
            try:
                return pdata['aws-alt'][altkey]['description']
            except KeyError:
                return None

        if instance_id in pdata['aws-alt'].keys():
            LOG.info(
                "instance-id found in known alternative configurations. using configuration %r",
                instance_id)
            more_context['alt-config'] = instance_id
        else:
            alt_config_choices = [default] + list(pdata['aws-alt'].keys())
            if not alt_config:
                alt_config = utils._pick('alternative config',
                                         alt_config_choices,
                                         helpfn=helpfn)
            if alt_config != default:
                more_context['alt-config'] = alt_config

    # TODO: return the templates used here, so that they can be passed down to
    # bootstrap.create_stack() without relying on them implicitly existing
    # on the filesystem
    cfngen.generate_stack(pname, **more_context)
    return stackname
示例#6
0
def create_stack(pname):
    """creates a new CloudFormation template for the given project."""
    default_instance_id = core_utils.ymd()
    inst_id = utils.uin("instance id", default_instance_id)
    stackname = core.mk_stackname(pname, inst_id)
    more_context = {'instance_id': stackname}

    # prompt user for alternate configurations
    pdata = project.project_data(pname)
    if pdata.has_key('aws-alt'):
        def helpfn(altkey):
            try:
                return pdata['aws-alt'][altkey]['description']
            except KeyError:
                return None
        default = 'skip this step'
        alt_config = [default] + pdata['aws-alt'].keys()
        alt_config = utils._pick('alternative config', alt_config, helpfn=helpfn)
        if alt_config != default:
            more_context['alt-config'] = alt_config
    cfngen.generate_stack(pname, **more_context)
    return stackname
示例#7
0
def generate_stack_from_input(pname, instance_id=None, alt_config=None):
    """creates a new CloudFormation file for the given project."""
    instance_id = instance_id or utils.uin("instance id", core_utils.ymd())
    stackname = core.mk_stackname(pname, instance_id)
    checks.ensure_stack_does_not_exist(stackname)
    more_context = {'stackname': stackname}

    pdata = project.project_data(pname)
    if alt_config:
        ensure('aws-alt' in pdata, "alternative configuration name given, but project has no alternate configurations")

    # prompt user for alternate configurations
    if pdata['aws-alt']:
        default = 'skip'

        def helpfn(altkey):
            if altkey == default:
                return 'uses the default configuration'
            try:
                return pdata['aws-alt'][altkey]['description']
            except KeyError:
                return None
        if instance_id in pdata['aws-alt'].keys():
            LOG.info("instance-id found in known alternative configurations. using configuration %r", instance_id)
            more_context['alt-config'] = instance_id
        else:
            alt_config_choices = [default] + list(pdata['aws-alt'].keys())
            if not alt_config:
                alt_config = utils._pick('alternative config', alt_config_choices, helpfn=helpfn)
            if alt_config != default:
                more_context['alt-config'] = alt_config

    # TODO: return the templates used here, so that they can be passed down to
    # bootstrap.create_stack() without relying on them implicitly existing
    # on the filesystem
    cfngen.generate_stack(pname, **more_context)
    return stackname
示例#8
0
def new():
    "creates a new project formula"
    pname = utils.uin('project name')
    #assert pname not in project.project_list(), "that project name already exists"
    local('./scripts/new-project.sh %s' % pname)
示例#9
0
 def test_uin_default(self, get_input):
     value = utils.uin('project', default='lax')
     self.assertEqual('lax', value)
示例#10
0
def new():
    "creates a new project formula"
    pname = utils.uin('project name')
    local('./scripts/new-project.sh %s' % pname)
示例#11
0
def check_user_input(pname, instance_id=None, alt_config=None):
    "marshals user input and checks it for correctness"
    instance_id = instance_id or utils.uin("instance id", core_utils.ymd())
    stackname = core.mk_stackname(pname, instance_id)
    pdata = project.project_data(pname)

    # alt-config given, die if it doesn't exist
    if alt_config:
        ensure(
            'aws-alt' in pdata,
            "alt-config %r given, but project has no alternate configurations"
            % alt_config)

    # if the requested instance-id matches a known alt-config, we'll use that alt-config. warn user.
    if instance_id in pdata['aws-alt'].keys():
        LOG.warn("instance-id %r found in alt-config list, using that.",
                 instance_id)
        alt_config = instance_id

    # no alt-config given but alt-config options exist, prompt user
    if not alt_config and pdata['aws-alt']:
        default_choice = 'skip'

        def helpfn(altkey):
            if altkey == default_choice:
                return 'uses the default configuration'
            try:
                return pdata['aws-alt'][altkey]['description']
            except KeyError:
                return None

        alt_config_choice_list = [default_choice] + list(
            pdata['aws-alt'].keys())
        alt_config_choice = utils._pick('alternative config',
                                        alt_config_choice_list,
                                        helpfn=helpfn)
        if alt_config_choice != default_choice:
            alt_config = alt_config_choice

    # check the alt-config isn't unique and if it *is* unique, that an instance using it doesn't exist yet.
    # note: it is *technically* possible that an instance is using a unique configuration but
    # that its instance-id *is not* the name of the alt-config passed in.
    # For example, if `journal--prod` didn't exist, I could create `journal--foo` using the `prod` config.
    if alt_config and alt_config in pdata['aws-alt'] and pdata['aws-alt'][
            alt_config]['unique']:
        dealbreaker = core.mk_stackname(pname, alt_config)
        # "project 'journal' config 'prod' is marked as unique!"
        # "checking for any instance named 'journal--prod' ..."
        print("project %r config %r is marked as unique!" %
              (pname, alt_config))
        print("checking for any instance named %r ..." % (dealbreaker, ))
        try:
            checks.ensure_stack_does_not_exist(dealbreaker)
        except checks.StackAlreadyExistsProblem:
            # "stack 'journal--prod' exists, cannot re-use unique configuration 'prod'"
            msg = "stack %r exists, cannot re-use unique configuration %r." % (
                dealbreaker, alt_config)
            raise TaskExit(msg)

    # check that the instance we want to create doesn't exist
    try:
        print("checking %r doesn't exist." % stackname)
        checks.ensure_stack_does_not_exist(stackname)
    except checks.StackAlreadyExistsProblem as e:
        msg = 'stack %r already exists.' % e.stackname
        raise TaskExit(msg)

    more_context = {'stackname': stackname}
    if alt_config:
        more_context['alt-config'] = alt_config

    return more_context
示例#12
0
 def test_uin_default(self, get_input):
     value = utils.uin('project', default='lax')
     self.assertEqual('lax', value)
示例#13
0
def new():
    "creates a new project formula from a template"
    pname = utils.uin('project name')
    local('./scripts/new-project.sh %s' % pname)