def restore_backup(request):
"""
Restore from a backup
:Example: curl -X PUT http://localhost:8082/foglamp/backup/1/restore
"""
backup_id = request.match_info.get('backup_id', None)
if not backup_id:
raise web.HTTPBadRequest(reason='Backup id is required')
else:
try:
backup_id = int(backup_id)
except ValueError:
raise web.HTTPBadRequest(reason='Invalid backup id')
try:
# TODO : Fix after actual implementation
Backup.restore_backup.return_value = 1
except Backup.DoesNotExist:
raise web.HTTPNotFound(reason='Backup with {} does not exist'.format(backup_id))
try:
Backup.restore_backup(id=backup_id)
return web.json_response({'message': 'Restore backup with id {} started successfully'.format(backup_id)})
except Backup.RestoreFailed as ex:
return web.json_response({'error': 'Restore backup with id {} failed, reason {}'.format(backup_id, ex)})
评论列表
文章目录