def migrate_volume_completion(self, ctxt, volume_id, new_volume_id, error=False, volume=None, new_volume=None):
    if ((volume is None) or (new_volume is None)):
        volume = objects.Volume.get_by_id(ctxt, volume_id)
        new_volume = objects.Volume.get_by_id(ctxt, new_volume_id)
    try:
        utils.require_driver_initialized(self.driver)
    except exception.DriverNotInitialized:
        with excutils.save_and_reraise_exception():
            volume.migration_status = 'error'
            volume.save()
    LOG.debug('migrate_volume_completion: completing migration for volume %(vol1)s (temporary volume %(vol2)s', {'vol1': volume.id, 'vol2': new_volume.id})
    rpcapi = volume_rpcapi.VolumeAPI()
    orig_volume_status = volume.previous_status
    if error:
        LOG.info(_LI('migrate_volume_completion is cleaning up an error for volume %(vol1)s (temporary volume %(vol2)s'), {'vol1': volume['id'], 'vol2': new_volume.id})
        rpcapi.delete_volume(ctxt, new_volume)
        updates = {'migration_status': 'error', 'status': orig_volume_status}
        volume.update(updates)
        volume.save()
        return volume.id
    volume.migration_status = 'completing'
    volume.save()
    try:
        if (orig_volume_status == 'in-use'):
            attachments = volume.volume_attachment
            for attachment in attachments:
                self.detach_volume(ctxt, volume.id, attachment['id'])
    except Exception as ex:
        LOG.error(_LE('Detach migration source volume failed:  %(err)s'), {'err': ex}, resource=volume)
    rpcapi.update_migrated_volume(ctxt, volume, new_volume, orig_volume_status)
    volume.refresh()
    new_volume.refresh()
    updated_new = volume.finish_volume_migration(new_volume)
    updates = {'status': orig_volume_status, 'previous_status': volume.status, 'migration_status': 'success'}
    if (orig_volume_status == 'in-use'):
        attachments = volume.volume_attachment
        for attachment in attachments:
            rpcapi.attach_volume(ctxt, volume, attachment['instance_uuid'], attachment['attached_host'], attachment['mountpoint'], 'rw')
    volume.update(updates)
    volume.save()
    try:
        rpcapi.delete_volume(ctxt, updated_new)
    except Exception as ex:
        LOG.error(_LE('Failed to request async delete of migration source vol %(vol)s: %(err)s'), {'vol': volume.id, 'err': ex})
    LOG.info(_LI('Complete-Migrate volume completed successfully.'), resource=volume)
    return volume.id
def migrate_volume_completion(self, ctxt, volume_id, new_volume_id, error=False, volume=None, new_volume=None):
    if ((volume is None) or (new_volume is None)):
        volume = objects.Volume.get_by_id(ctxt, volume_id)
        new_volume = objects.Volume.get_by_id(ctxt, new_volume_id)
    try:
        utils.require_driver_initialized(self.driver)
    except exception.DriverNotInitialized:
        with excutils.save_and_reraise_exception():
            volume.migration_status = 'error'
            volume.save()
    LOG.debug('migrate_volume_completion: completing migration for volume %(vol1)s (temporary volume %(vol2)s', {'vol1': volume.id, 'vol2': new_volume.id})
    rpcapi = volume_rpcapi.VolumeAPI()
    orig_volume_status = volume.previous_status
    if error:
        LOG.info(_LI('migrate_volume_completion is cleaning up an error for volume %(vol1)s (temporary volume %(vol2)s'), {'vol1': volume['id'], 'vol2': new_volume.id})
        rpcapi.delete_volume(ctxt, new_volume)
        updates = {'migration_status': 'error', 'status': orig_volume_status}
        volume.update(updates)
        volume.save()
        return volume.id
    volume.migration_status = 'completing'
    volume.save()
    try:
        if (orig_volume_status == 'in-use'):
            attachments = volume.volume_attachment
            for attachment in attachments:
                self.detach_volume(ctxt, volume.id, attachment['id'])
    except Exception as ex:
        LOG.error(_LE('Detach migration source volume failed:  %(err)s'), {'err': ex}, resource=volume)
    rpcapi.update_migrated_volume(ctxt, volume, new_volume, orig_volume_status)
    volume.refresh()
    new_volume.refresh()
    updated_new = volume.finish_volume_migration(new_volume)
    updates = {'status': orig_volume_status, 'previous_status': volume.status, 'migration_status': 'success'}
    if (orig_volume_status == 'in-use'):
        attachments = volume.volume_attachment
        for attachment in attachments:
            rpcapi.attach_volume(ctxt, volume, attachment['instance_uuid'], attachment['attached_host'], attachment['mountpoint'], 'rw')
    volume.update(updates)
    volume.save()
    try:
        rpcapi.delete_volume(ctxt, updated_new)
    except Exception as ex:
        LOG.error(_LE('Failed to request async delete of migration source vol %(vol)s: %(err)s'), {'vol': volume.id, 'err': ex})
    LOG.info(_LI('Complete-Migrate volume completed successfully.'), resource=volume)
    return volume.id