#NEWLINE# def safe_dict_max( key , data ) : #NEWLINE# #INDENT# 'Safely find the maximum for a given key in a list of dict objects.\n\n    This will find the maximum 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 maximum 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 maximum value for the field otherwise.\n    ' #NEWLINE# max_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 maximum value failed. Value for {key} is not an integer: {value}' . format ( key = key , value = d [ key ] ) ) #NEWLINE# #UNINDENT# if ( ( max_value is None ) or ( val > max_value ) ) : #NEWLINE# #INDENT# max_value = val #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return max_value