'The method deletes the bdm records and, if a bdm is a volume, call
the terminate connection and the detach volume via the Volume API.'

def _local_cleanup_bdm_volumes(self, bdms, instance, context):

    elevated = context.elevated()
    for bdm in bdms:
        if bdm.is_volume:
            try:
                if bdm.attachment_id:
                    self.volume_api.attachment_delete(context, bdm.attachment_id)
                else:
                    connector = self._get_stashed_volume_connector(bdm, instance)
                    if connector:
                        self.volume_api.terminate_connection(context, bdm.volume_id, connector)
                    else:
                        LOG.debug('Unable    to    find    connector    for    volume    %s,    not    attempting    terminate_connection.', bdm.volume_id, instance=instance)
                    self.volume_api.detach(elevated, bdm.volume_id, instance.uuid)
                if bdm.delete_on_termination:
                    self.volume_api.delete(context, bdm.volume_id)
            except Exception as exc:
                LOG.warning('Ignoring    volume    cleanup    failure    due    to    %s', exc, instance=instance)
        bdm.destroy()
