def _count_allocated_capacity(self, ctxt, volume):
    pool = vol_utils.extract_host(volume['host'], 'pool')
    if (pool is None):
        try:
            pool = self.driver.get_pool(volume)
        except Exception:
            LOG.exception(_LE('Fetch volume pool name failed.'), resource=volume)
            return
        if pool:
            new_host = vol_utils.append_host(volume['host'], pool)
            self.db.volume_update(ctxt, volume['id'], {'host': new_host})
        else:
            pool = (self.driver.configuration.safe_get('volume_backend_name') or vol_utils.extract_host(volume['host'], 'pool', True))
    try:
        pool_stat = self.stats['pools'][pool]
    except KeyError:
        self.stats['pools'][pool] = dict(allocated_capacity_gb=0)
        pool_stat = self.stats['pools'][pool]
    pool_sum = pool_stat['allocated_capacity_gb']
    pool_sum += volume['size']
    self.stats['pools'][pool]['allocated_capacity_gb'] = pool_sum
    self.stats['allocated_capacity_gb'] += volume['size']
def _count_allocated_capacity(self, ctxt, volume):
    pool = vol_utils.extract_host(volume['host'], 'pool')
    if (pool is None):
        try:
            pool = self.driver.get_pool(volume)
        except Exception:
            LOG.exception(_LE('Fetch volume pool name failed.'), resource=volume)
            return
        if pool:
            new_host = vol_utils.append_host(volume['host'], pool)
            self.db.volume_update(ctxt, volume['id'], {'host': new_host})
        else:
            pool = (self.driver.configuration.safe_get('volume_backend_name') or vol_utils.extract_host(volume['host'], 'pool', True))
    try:
        pool_stat = self.stats['pools'][pool]
    except KeyError:
        self.stats['pools'][pool] = dict(allocated_capacity_gb=0)
        pool_stat = self.stats['pools'][pool]
    pool_sum = pool_stat['allocated_capacity_gb']
    pool_sum += volume['size']
    self.stats['pools'][pool]['allocated_capacity_gb'] = pool_sum
    self.stats['allocated_capacity_gb'] += volume['size']