'Deletes a volume.'

def delete_volume(self, volume):

    ret = 0
    if volume.group_id:
        group = volume_utils.group_get_by_id(volume.group_id)
        if (group and volume_utils.is_group_a_cg_snapshot_type(group)):
            msg = ''
            try:
                (ret, out) = self.dpl.leave_vg(self._conver_uuid2hex(volume['id']), self._conver_uuid2hex(volume.group_id))
                if ret:
                    LOG.warning('Flexvisor    failed    to    delete    volume    %(id)s    from    the    group    %(vgid)s.', {'id': volume['id'], 'vgid': volume.group_id})
            except Exception as e:
                LOG.warning('Flexvisor    failed    to    delete    volume    %(id)s    from    group    %(vgid)s    due    to    %(status)s.', {'id': volume['id'], 'vgid': volume.group_id, 'status': e})
        if ret:
            ret = 0
    (ret, output) = self.dpl.delete_vdev(self._conver_uuid2hex(volume['id']))
    if (ret == errno.EAGAIN):
        status = self._wait_event(self.dpl.get_vdev, volume['id'])
        if (status['state'] == 'error'):
            msg = (_('Flexvisor    failed    deleting    volume    %(id)s:    %(status)s.') % {'id': volume['id'], 'status': ret})
            raise exception.VolumeBackendAPIException(data=msg)
    elif (ret == errno.ENODATA):
        ret = 0
        LOG.info('Flexvisor    volume    %(id)s    does    not    exist.', {'id': volume['id']})
    elif (ret != 0):
        msg = (_('Flexvisor    failed    to    delete    volume    %(id)s:    %(status)s.') % {'id': volume['id'], 'status': ret})
        raise exception.VolumeBackendAPIException(data=msg)
