def update_migrated_volume(self, ctxt, volume, new_volume, volume_status):
    'Finalize migration process on backend device.'
    model_update = None
    model_update_default = {'_name_id': new_volume.name_id, 'provider_location': new_volume.provider_location}
    try:
        model_update = self.driver.update_migrated_volume(ctxt, volume, new_volume, volume_status)
    except NotImplementedError:
        model_update = model_update_default
    if model_update:
        model_update_default.update(model_update)
        model_update_new = dict()
        for key in model_update:
            if (key == 'metadata'):
                if volume.get('volume_metadata'):
                    model_update_new[key] = {metadata['key']: metadata['value'] for metadata in volume.volume_metadata}
            elif (key == 'admin_metadata'):
                model_update_new[key] = {metadata['key']: metadata['value'] for metadata in volume.volume_admin_metadata}
            else:
                model_update_new[key] = volume[key]
        with new_volume.obj_as_admin():
            new_volume.update(model_update_new)
            new_volume.save()
    with volume.obj_as_admin():
        volume.update(model_update_default)
        volume.save()
Finalize migration process on backend device.
def update_migrated_volume(self, ctxt, volume, new_volume, volume_status):
    
    model_update = None
    model_update_default = {'_name_id': new_volume.name_id, 'provider_location': new_volume.provider_location}
    try:
        model_update = self.driver.update_migrated_volume(ctxt, volume, new_volume, volume_status)
    except NotImplementedError:
        model_update = model_update_default
    if model_update:
        model_update_default.update(model_update)
        model_update_new = dict()
        for key in model_update:
            if (key == 'metadata'):
                if volume.get('volume_metadata'):
                    model_update_new[key] = {metadata['key']: metadata['value'] for metadata in volume.volume_metadata}
            elif (key == 'admin_metadata'):
                model_update_new[key] = {metadata['key']: metadata['value'] for metadata in volume.volume_admin_metadata}
            else:
                model_update_new[key] = volume[key]
        with new_volume.obj_as_admin():
            new_volume.update(model_update_new)
            new_volume.save()
    with volume.obj_as_admin():
        volume.update(model_update_default)
        volume.save()