'Import a backup.'

@wsgi.response(http_client.CREATED)
def import_record(self, req, body):

    LOG.debug('Importing    record    from    %s.', body)
    self.assert_valid_body(body, 'backup-record')
    context = req.environ['cinder.context']
    import_data = body['backup-record']
    try:
        backup_service = import_data['backup_service']
        backup_url = import_data['backup_url']
    except KeyError:
        msg = _('Incorrect    request    body    format.')
        raise exc.HTTPBadRequest(explanation=msg)
    LOG.debug('Importing    backup    using    %(service)s    and    url    %(url)s.', {'service': backup_service, 'url': backup_url})
    try:
        new_backup = self.backup_api.import_record(context, backup_service, backup_url)
    except exception.InvalidBackup as error:
        raise exc.HTTPBadRequest(explanation=error.msg)
    except exception.ServiceNotFound as error:
        raise exc.HTTPServiceUnavailable(explanation=error.msg)
    retval = self._view_builder.summary(req, dict(new_backup))
    LOG.debug('Import    record    output:    %s.', retval)
    return retval
