#NEWLINE# def safe_dict_min( key , data ) : #NEWLINE# #INDENT# 'Safely find the minimum for a given key in a list of dict objects.\n\n    This will find the minimum integer value for specific dictionary key\n    across a list of dictionaries. The values for the given key MUST be\n    integers, or string representations of an integer.\n\n    The dictionary key does not have to be present in all (or any)\n    of the elements/dicts within the data set.\n\n    :param string key: The dictionary key to search for the minimum value.\n    :param list data: List of dicts to use for the data set.\n\n    :returns: None if the field was not not found in any elements, or\n        the minimum value for the field otherwise.\n    ' #NEWLINE# min_value = None #NEWLINE# for d in data : #NEWLINE# #INDENT# if ( ( key in d ) and ( d [ key ] is not None ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# val = int ( d [ key ] ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise exc . OpenStackCloudException ( 'Search for minimum value failed. Value for {key} is not an integer: {value}' . format ( key = key , value = d [ key ] ) ) #NEWLINE# #UNINDENT# if ( ( min_value is None ) or ( val < min_value ) ) : #NEWLINE# #INDENT# min_value = d #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return min_value