stratosphere.py 文件源码

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

项目:stratosphere 作者: victortrac 项目源码 文件源码
def apply_deployment(project, template):
    body = {
        'name': template.name,
        'description': 'project: {}, name: {}'.format(project, template.name),
        'target': {
            'config': {
                'content': str(template)
            }
        }
    }
    result = None
    try:
        deployment = get_deployment(project, template.name)
        if deployment:
            logging.info('Deployment already exists. Getting changes for {}...'.format(template.name))
            body['fingerprint'] = deployment.get('fingerprint')
            changed = False
            existing_template = get_manifest(project, deployment)['config']['content']
            for diff in color_diff(difflib.unified_diff(existing_template.splitlines(),
                                                        str(template).splitlines(),
                                                        fromfile='Existing template', tofile='Proposed template')):
                changed = True
                print(diff)
            if changed and confirm_action():
                result = dm.deployments().update(project=project, deployment=template.name, body=body).execute()
            else:
                logging.info('No changes in the template.')
                sys.exit(0)
        else:
            logging.info('Generated template:\n{}\n'.format(template))
            logging.info('Launching a new deployment: {}'.format(template.name))
            if confirm_action():
                result = dm.deployments().insert(project=project, body=body).execute()
    except errors.HttpError as e:
        raise e
    if result:
        return wait_for_completion(project, result)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号