def manage_existing(self, ctxt, volume_id, ref=None):
    try:
        flow_engine = manage_existing.get_flow(ctxt, self.db, self.driver, self.host, volume_id, ref)
    except Exception:
        msg = _('Failed to create manage_existing flow.')
        LOG.exception(msg, resource={'type': 'volume', 'id': volume_id})
        raise exception.CinderException(msg)
    with flow_utils.DynamicLogListener(flow_engine, logger=LOG):
        flow_engine.run()
    vol_ref = flow_engine.storage.fetch('volume')
    pool = vol_utils.extract_host(vol_ref['host'], 'pool')
    if (pool is None):
        pool = (self.driver.configuration.safe_get('volume_backend_name') or vol_utils.extract_host(vol_ref['host'], 'pool', True))
    try:
        self.stats['pools'][pool]['allocated_capacity_gb'] += vol_ref['size']
    except KeyError:
        self.stats['pools'][pool] = dict(allocated_capacity_gb=vol_ref['size'])
    LOG.info(_LI('Manage existing volume completed successfully.'), resource=vol_ref)
    return vol_ref['id']
def manage_existing(self, ctxt, volume_id, ref=None):
    try:
        flow_engine = manage_existing.get_flow(ctxt, self.db, self.driver, self.host, volume_id, ref)
    except Exception:
        msg = _('Failed to create manage_existing flow.')
        LOG.exception(msg, resource={'type': 'volume', 'id': volume_id})
        raise exception.CinderException(msg)
    with flow_utils.DynamicLogListener(flow_engine, logger=LOG):
        flow_engine.run()
    vol_ref = flow_engine.storage.fetch('volume')
    pool = vol_utils.extract_host(vol_ref['host'], 'pool')
    if (pool is None):
        pool = (self.driver.configuration.safe_get('volume_backend_name') or vol_utils.extract_host(vol_ref['host'], 'pool', True))
    try:
        self.stats['pools'][pool]['allocated_capacity_gb'] += vol_ref['size']
    except KeyError:
        self.stats['pools'][pool] = dict(allocated_capacity_gb=vol_ref['size'])
    LOG.info(_LI('Manage existing volume completed successfully.'), resource=vol_ref)
    return vol_ref['id']