'find lun instance from volume class or volumename on ETERNUS.'

def _find_lun(self, volume):

    LOG.debug('_find_lun,    volume    id:    %s.', volume['id'])
    volumeinstance = None
    volumename = self._create_volume_name(volume['id'])
    try:
        location = ast.literal_eval(volume['provider_location'])
        classname = location['classname']
        bindings = location['keybindings']
        if (classname and bindings):
            LOG.debug('_find_lun,    classname:    %(classname)s,    bindings:    %(bindings)s.', {'classname': classname, 'bindings': bindings})
            volume_instance_name = self._create_eternus_instance_name(classname, bindings)
            LOG.debug('_find_lun,    volume_insatnce_name:    %(volume_instance_name)s.', {'volume_instance_name': volume_instance_name})
            vol_instance = self._get_eternus_instance(volume_instance_name)
            if (vol_instance['ElementName'] == volumename):
                volumeinstance = vol_instance
    except Exception:
        volumeinstance = None
        LOG.debug('_find_lun,    Cannot    get    volume    instance    from    provider    location,    Search    all    volume    using    EnumerateInstanceNames.')
    if (volumeinstance is None):
        LOG.debug('_find_lun,    volumename:    %(volumename)s.', {'volumename': volumename})
        try:
            namelist = self._enum_eternus_instance_names('FUJITSU_StorageVolume')
        except Exception:
            msg = (_('_find_lun,    volumename:    %(volumename)s,    EnumerateInstanceNames,    cannot    connect    to    ETERNUS.') % {'volumename': volumename})
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        for name in namelist:
            try:
                vol_instance = self._get_eternus_instance(name)
                if (vol_instance['ElementName'] == volumename):
                    volumeinstance = vol_instance
                    path = volumeinstance.path
                    LOG.debug('_find_lun,    volumename:    %(volumename)s,    vol_instance:    %(vol_instance)s.', {'volumename': volumename, 'vol_instance': path})
                    break
            except Exception:
                continue
        else:
            LOG.debug('_find_lun,    volumename:    %(volumename)s,    volume    not    found    on    ETERNUS.', {'volumename': volumename})
    LOG.debug('_find_lun,    ret:    %s.', volumeinstance)
    return volumeinstance
