def _get_free_lun(client, host, multiattach_enabled, mappings):
 if (not _is_host_full(client, host)):
  unused_luns = _get_unused_lun_ids(mappings)
  if unused_luns:
   chosen_lun = random.sample(unused_luns, 1)
   return chosen_lun[0]
  elif multiattach_enabled:
   msg = _('No unused LUN IDs are available on the host; multiattach is enabled which requires that all LUN IDs to be unique across the entire host group.')
   raise exception.NetAppDriverException(msg)
  used_lun_counts = _get_used_lun_id_counter(mappings)
  for (lun_id, __) in reversed(used_lun_counts.most_common()):
   if _is_lun_id_available_on_host(client, host, lun_id):
    return lun_id
 msg = _('No free LUN IDs left. Maximum number of volumes that can be attached to host (%s) has been exceeded.')
 raise exception.NetAppDriverException((msg % utils.MAX_LUNS_PER_HOST))

def _get_free_lun ( client , host , multiattach_enabled , mappings ) : if ( not _is_host_full ( client , host ) ) : unused_luns = _get_unused_lun_ids ( mappings ) if unused_luns : chosen_lun = random . sample ( unused_luns , 1 ) return chosen_lun [ 0 ] elif multiattach_enabled : msg = _ ( 'No unused LUN IDs are available on the host; multiattach is enabled which requires that all LUN IDs to be unique across the entire host group.' ) raise exception . NetAppDriverException ( msg ) used_lun_counts = _get_used_lun_id_counter ( mappings ) for ( lun_id , __ ) in reversed ( used_lun_counts . most_common ( ) ) : if _is_lun_id_available_on_host ( client , host , lun_id ) : return lun_id msg = _ ( 'No free LUN IDs left. Maximum number of volumes that can be attached to host (%s) has been exceeded.' ) raise exception . NetAppDriverException ( ( msg % utils . MAX_LUNS_PER_HOST ) )
returns least used lun id available on the given host .