def _select_datastore(session, data_stores, best_match, datastore_regex=None, storage_policy=None, allowed_ds_types=ALL_SUPPORTED_DS_TYPES):
 if storage_policy:
  matching_ds = _filter_datastores_matching_storage_policy(session, data_stores, storage_policy)
  if (not matching_ds):
   return best_match
 else:
  matching_ds = data_stores
 for obj_content in matching_ds.objects:
  if (not hasattr(obj_content, 'propSet')):
   continue
  propdict = vm_util.propset_dict(obj_content.propSet)
  if _is_datastore_valid(propdict, datastore_regex, allowed_ds_types):
   new_ds = ds_obj.Datastore(ref=obj_content.obj, name=propdict['summary.name'], capacity=propdict['summary.capacity'], freespace=propdict['summary.freeSpace'])
   if ((best_match is None) or (new_ds.freespace > best_match.freespace)):
    best_match = new_ds
 return best_match

def _select_datastore ( session , data_stores , best_match , datastore_regex = None , storage_policy = None , allowed_ds_types = ALL_SUPPORTED_DS_TYPES ) : if storage_policy : matching_ds = _filter_datastores_matching_storage_policy ( session , data_stores , storage_policy ) if ( not matching_ds ) : return best_match else : matching_ds = data_stores for obj_content in matching_ds . objects : if ( not hasattr ( obj_content , 'propSet' ) ) : continue propdict = vm_util . propset_dict ( obj_content . propSet ) if _is_datastore_valid ( propdict , datastore_regex , allowed_ds_types ) : new_ds = ds_obj . Datastore ( ref = obj_content . obj , name = propdict [ 'summary.name' ] , capacity = propdict [ 'summary.capacity' ] , freespace = propdict [ 'summary.freeSpace' ] ) if ( ( best_match is None ) or ( new_ds . freespace > best_match . freespace ) ) : best_match = new_ds return best_match
find the most preferable datastore in a given retrieveresult object .