Пример #1
0
    def cli_confirm(self, infra, selector=[], **kwargs):

        c = 0

        defaults = {
            'reverse': False,
            'ask': 'Deploy Stack(s)?'
        }

        defaults.update(kwargs)

        stacks = infra.list_stacks(reverse=defaults['reverse'])

        results = match_stack(selector, stacks)

        for stack in results:
            c += 1
            print("Stack: {}{}/{}{}".format(
                Fore.CYAN + Style.BRIGHT,
                stack.get_stack_name(),
                stack.get_remote_stack_name(),
                Style.RESET_ALL
            ))

        if c <= 0:
            print("NO STACKS SELCTED!")
            return False

        ans = input("{} [y/n]: \n".format(defaults['ask']))

        if ans.lower().startswith("y"):
            return True

        return False
Пример #2
0
def stacks_list(selector=None, dependencies=False, remote=False):

    if len(selector) <= 0:
        selector = None
    else:
        selector = list(selector)

    infra = utils.load_infra_module(INFRA_FILE).infra

    stacks = infra.list_stacks()

    results = match_stack(selector, stacks)

    stacks = results

    for stack in stacks:

        # ty = str(type(v)).split(" ")[1].strip(">")
        ty = type(stack).__name__
        rem = ""
        if remote:
            if stack.stack_info():
                rem = styled_bool(True)
            else:
                rem = styled_bool(False)

        click.echo("{}{} {} {}[{}] {}({}){}".format(
            rem, Style.BRIGHT + Fore.CYAN, stack.get_stack_name(), Fore.YELLOW,
            stack.get_remote_stack_name(), Style.RESET_ALL, ty,
            Style.RESET_ALL))
        if dependencies:
            deps = infra.get_dependent_stacks(stack)
            if len(deps) > 0:
                for k, v in deps.items():
                    rem = "-"
                    if remote:
                        if v.stack_info():
                            rem = styled_bool(True)
                        else:
                            rem = styled_bool(False)
                    ty = type(v).__name__
                    click.echo("  {} {} ({})".format(
                        rem,
                        utils.colors('p') + v.get_stack_name() +
                        Style.RESET_ALL, ty))
Пример #3
0
def template(selector, yaml):

    selector = list(selector)

    infra = utils.load_infra_module(INFRA_FILE).infra

    stacks = infra.list_stacks()

    stacks = match_stack(selector, stacks)

    for stack in stacks:

        t = stack.build_template()

        if yaml:
            print(t.to_yaml())
        else:
            print(t.to_json())
Пример #4
0
    def destroy(self, infra, selector=False, **kw):


        stacks = infra.list_stacks(reverse=True)

        stacks = match_stack(selector, stacks)

        for stack in stacks:

            try:
                start = stack.start_destroy(infra, stack.infra.context)
                if not start:
                    print("{} Skipping destroy..".format(stack.get_stack_name()))
            except Exception as e:
                print(str(e))
                continue
            time.sleep(2)
            while stack.deploying(infra):
                pass
            logger.info("DESTROY COMPLETE: {}".format(stack.get_stack_name()))
Пример #5
0
    def deploy(self, infra, selector=False):

        stacks = infra.get_stacks()

        stacks = match_stack(selector, stacks)

        for stack in stacks:

            dependent_stacks = infra.get_dependent_stacks(stack)

            for k, stk in dependent_stacks.items():
                stk.load_stack_outputs(stack.infra)

            start = stack.start_deploy(infra, stack.infra.context)
            if not start:
                print("{} Skipping deploy..".format(stack.get_stack_name()))
            time.sleep(2)

            while stack.deploying(infra):
                pass
            logger.info("DEPLOY COMPLETE: {}".format(stack.get_stack_name()))
Пример #6
0
def stacks_review(selector=None):

    if len(selector) >= 0:
        selector = list(selector)

    infra = utils.load_infra_module(INFRA_FILE).infra

    stacks = infra.list_stacks()

    results = match_stack(selector, stacks)

    for stack in results:

        wbs = utils.colors('w', True)
        rsall = Style.RESET_ALL

        click.echo("Stack Name: {}{}{}".format(wbs, stack.get_stack_name(),
                                               rsall))

        click.echo("Type: {}{}{}".format(wbs, type(stack).__name__, rsall))
        review = stack.review(infra)

        dep_status = styled_bool(False)
        if review['info']:
            dep_status = styled_bool(True)

        click.echo("Deploy Status: {}".format(dep_status))

        if len(review['dependent_stacks']) <= 0:
            click.echo("No dependent stacks")
        else:
            num_dependent = len(review['dependent_stacks'])
            click.echo("Denpendent Stacks: {}".format(num_dependent))
            click.echo("{} = Deployed | {} = Not Deployed".format(
                styled_bool(True), styled_bool(False)))
            for v in review['dependent_stacks']:
                if not v['stack_info']:
                    deployed = False
                    status = "Not Deployed"
                else:
                    deployed = True
                    status = "Deployed"

                click.echo("  {} {} ({})".format(styled_bool(deployed),
                                                 v['stack'].get_stack_name(),
                                                 type(v['stack']).__name__))

        click.echo("")
        click.echo("Parameter Review:")

        if not review['info'] or not review['info'].get('Parameters'):  # noqa
            params = {}
        else:
            params = {}
            for v in review['info'].get('Parameters'):
                params.update({v['ParameterKey']: v['ParameterValue']})

        # define icons
        nv = "{}?{}".format(utils.colors('y', True), Style.RESET_ALL)
        sv = styled_bool(True)
        cv = styled_bool(False)

        if len(review['parameters']) <= 0:
            click.echo("No Parameters to review")
        else:
            click.echo(
                "{} = New Value | {} = Changed Value | {} = No Change".format(
                    nv, cv, sv))  # noqa

        for v in review['parameters']:
            param_name = v['ParameterKey']
            param_value = v['ParameterValue']
            status = ""
            if not params.get(param_name):
                icon = nv
            elif params.get(param_name) == param_value:
                icon = sv
            else:
                icon = cv
                status = "{}Previous Value: {}{} ".format(
                    utils.colors('b', True), params.get(param_name),
                    Style.RESET_ALL)
            click.echo("{} {}: {}".format(icon, param_name, param_value))
            if len(status) > 0:
                click.echo(dedent(status))