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)
评论列表
文章目录