'Make the RPC call to restore a volume backup.'

def restore(self, context, backup_id, volume_id=None, name=None):

    check_policy(context, 'restore')
    backup = self.get(context, backup_id)
    if (backup['status'] != fields.BackupStatus.AVAILABLE):
        msg = _('Backup    status    must    be    available')
        raise exception.InvalidBackup(reason=msg)
    size = backup['size']
    if (size is None):
        msg = _('Backup    to    be    restored    has    invalid    size')
        raise exception.InvalidBackup(reason=msg)
    if (volume_id is None):
        if (name is None):
            name = ('restore_backup_%s' % backup_id)
        description = 'auto-created_from_restore_from_backup'
        LOG.info('Creating    volume    of    %(size)s    GB    for    restore    of    backup    %(backup_id)s.', {'size': size, 'backup_id': backup_id})
        volume = self.volume_api.create(context, size, name, description)
        volume_id = volume['id']
        while True:
            volume = self.volume_api.get(context, volume_id)
            if (volume['status'] != 'creating'):
                break
            greenthread.sleep(1)
        if (volume['status'] == 'error'):
            msg = (_('Error    while    creating    volume    %(volume_id)s    for    restoring    backup    %(backup_id)s.') % {'volume_id': volume_id, 'backup_id': backup_id})
            raise exception.InvalidVolume(reason=msg)
    else:
        volume = self.volume_api.get(context, volume_id)
    if (volume['status'] != 'available'):
        msg = _('Volume    to    be    restored    to    must    be    available')
        raise exception.InvalidVolume(reason=msg)
    LOG.debug('Checking    backup    size    %(bs)s    against    volume    size    %(vs)s', {'bs': size, 'vs': volume['size']})
    if (size > volume['size']):
        msg = (_('volume    size    %(volume_size)d    is    too    small    to    restore    backup    of    size    %(size)d.') % {'volume_size': volume['size'], 'size': size})
        raise exception.InvalidVolume(reason=msg)
    LOG.info('Overwriting    volume    %(volume_id)s    with    restore    of    backup    %(backup_id)s', {'volume_id': volume_id, 'backup_id': backup_id})
    backup.host = self._get_available_backup_service_host(backup.host, backup.availability_zone)
    backup.status = fields.BackupStatus.RESTORING
    backup.restore_volume_id = volume.id
    backup.save()
    self.db.volume_update(context, volume_id, {'status': 'restoring-backup'})
    self.backup_rpcapi.restore_backup(context, backup.host, backup, volume_id)
    d = {'backup_id': backup_id, 'volume_id': volume_id, 'volume_name': volume['display_name']}
    return d
