__init__.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:clouds-aws 作者: elias5000 项目源码 文件源码
def update(args):
    """update or create a stack in AWS."""
    stack = args.stack

    if stack not in local_stacks():
        LOG.error('no such stack: ' + stack)
        return

    if stack not in remote_stacks().keys() and not args.create_missing:
        LOG.warning(
            'stack ' + stack + ' does not exist in AWS, add --create_missing to create a new stack')
        return

    # read template and parameters
    tpl_body = load_template(stack, True)
    params = load_parameters(stack)

    # action
    cfn = get_cfn()
    last_event = None

    try:
        if stack in remote_stacks().keys():
            LOG.info('updating stack %s', stack)
            last_event = fetch_all_stack_events(stack)[-1]['Timestamp']
            stack_id = cfn.update_stack(
                StackName=stack,
                TemplateBody=tpl_body,
                Parameters=params,
                Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']
            )['StackId']
            LOG.info('created stack with physical id %s', stack_id)
        else:
            LOG.info('creating stack %s', stack)
            stack_id = cfn.create_stack(
                StackName=stack,
                TemplateBody=tpl_body,
                Parameters=params,
                Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']
            )['StackId']
            LOG.info('created stack with physical id %s', stack_id)
    except botocore.exceptions.ClientError as err:
        LOG.warning(str(err))
        return
    except botocore.exceptions.ParamValidationError as err:
        LOG.warning(str(err))
        return

    # synchronous mode
    if args.wait or args.events:
        wait(stack, show_events=args.events, last_event=last_event)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号