'Backup a server instance.
Images now have an `image_type` associated with them, which can be
\'snapshot\' or the backup type, like \'daily\' or \'weekly\'.
If the image_type is backup-like, then the rotation factor can be
included and that will cause the oldest backups that exceed the
rotation factor to be deleted.'

@wsgi.response(202)
@extensions.expected_errors((400, 403, 404, 409))
@wsgi.action('createBackup')
@validation.schema(create_backup.create_backup_v20, '2.0', '2.0')
@validation.schema(create_backup.create_backup, '2.1')
def _create_backup(self, req, id, body):

    context = req.environ['nova.context']
    context.can(cb_policies.BASE_POLICY_NAME)
    entity = body['createBackup']
    image_name = common.normalize_name(entity['name'])
    backup_type = entity['backup_type']
    rotation = int(entity['rotation'])
    props = {}
    metadata = entity.get('metadata', {})
    if api_version_request.is_supported(req, max_version=api_version_request.MAX_IMAGE_META_PROXY_API_VERSION):
        common.check_img_metadata_properties_quota(context, metadata)
    props.update(metadata)
    instance = common.get_instance(self.compute_api, context, id)
    try:
        image = self.compute_api.backup(context, instance, image_name, backup_type, rotation, extra_properties=props)
    except exception.InstanceUnknownCell as e:
        raise webob.exc.HTTPNotFound(explanation=e.format_message())
    except exception.InstanceInvalidState as state_error:
        common.raise_http_conflict_for_instance_invalid_state(state_error, 'createBackup', id)
    except exception.InvalidRequest as e:
        raise webob.exc.HTTPBadRequest(explanation=e.format_message())
    if api_version_request.is_supported(req, '2.45'):
        return {'image_id': image['id']}
    resp = webob.Response(status_int=202)
    if (rotation > 0):
        image_id = str(image['id'])
        image_ref = common.url_join(req.application_url, 'images', image_id)
        resp.headers['Location'] = image_ref
    return resp
