#NEWLINE# def filter_by_space( self , disk_space = None , reverse = True , use_age = False , source = 'creation_date' , timestring = None , field = None , stats_result = 'min_value' , exclude = False ) : #NEWLINE# #INDENT# '\n        Remove indices from the actionable list based on space\n        consumed, sorted reverse-alphabetically by default.  If you set\n        `reverse` to `False`, it will be sorted alphabetically.\n\n        The default is usually what you will want. If only one kind of index is\n        provided--for example, indices matching ``logstash-%Y.%m.%d``--then\n        reverse alphabetical sorting will mean the oldest will remain in the\n        list, because lower numbers in the dates mean older indices.\n\n        By setting `reverse` to `False`, then ``index3`` will be deleted before\n        ``index2``, which will be deleted before ``index1``\n\n        `use_age` allows ordering indices by age. Age is determined by the index\n        creation date by default, but you can specify an `source` of ``name``,\n        ``max_value``, or ``min_value``.  The ``name`` `source` requires the\n        timestring argument.\n\n        :arg disk_space: Filter indices over *n* gigabytes\n        :arg reverse: The filtering direction. (default: `True`).  Ignored if\n            `use_age` is `True`\n        :arg use_age: Sort indices by age.  ``source`` is required in this\n            case.\n        :arg source: Source of index age. Can be one of ``name``,\n            ``creation_date``, or ``field_stats``. Default: ``creation_date``\n        :arg timestring: An strftime string to match the datestamp in an index\n            name. Only used if `source` ``name`` is selected.\n        :arg field: A timestamp field name.  Only used if `source`\n            ``field_stats`` is selected.\n        :arg stats_result: Either `min_value` or `max_value`.  Only used if\n            `source` ``field_stats`` is selected. It determines whether to\n            reference the minimum or maximum value of `field` in each index.\n        :arg exclude: If `exclude` is `True`, this filter will remove matching\n            indices from `indices`. If `exclude` is `False`, then only matching\n            indices will be kept in `indices`.\n            Default is `False`\n        ' #NEWLINE# self . loggit . debug ( 'Filtering indices by disk space' ) #NEWLINE# if ( not disk_space ) : #NEWLINE# #INDENT# raise MissingArgument ( 'No value for "disk_space" provided' ) #NEWLINE# #UNINDENT# disk_space = float ( disk_space ) #NEWLINE# disk_usage = 0.0 #NEWLINE# disk_limit = ( disk_space * ( 2 ** 30 ) ) #NEWLINE# self . loggit . info ( 'Cannot get disk usage info from closed indices.  Omitting any closed indices.' ) #NEWLINE# self . filter_closed ( ) #NEWLINE# working_list = self . working_list ( ) #NEWLINE# if use_age : #NEWLINE# #INDENT# keyfield = source #NEWLINE# if ( source not in [ 'creation_date' , 'name' , 'field_stats' ] ) : #NEWLINE# #INDENT# raise ValueError ( 'Invalid value for "source": {0}' . format ( source ) ) #NEWLINE# #UNINDENT# if ( source == 'field_stats' ) : #NEWLINE# #INDENT# if ( not field ) : #NEWLINE# #INDENT# raise MissingArgument ( 'No value for "field" provided. "field" is required with source "field_stats"' ) #NEWLINE# #UNINDENT# if ( stats_result not in [ 'min_value' , 'max_value' ] ) : #NEWLINE# #INDENT# raise ConfigurationError ( 'Incorrect value for "stats_result" provided: {0}. Must be either "min_value" or "max_value"' . format ( stats_result ) ) #NEWLINE# #UNINDENT# keyfield = stats_result #NEWLINE# self . _get_field_stats_dates ( field = field ) #NEWLINE# #UNINDENT# if ( source == 'name' ) : #NEWLINE# #INDENT# if ( not timestring ) : #NEWLINE# #INDENT# raise MissingArgument ( 'No value for "timestring" provided. "timestring" is required with source "name"' ) #NEWLINE# #UNINDENT# self . _get_name_based_ages ( timestring ) #NEWLINE# #UNINDENT# intermediate = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for index in working_list : #NEWLINE# #INDENT# intermediate [ index ] = self . index_info [ index ] [ 'age' ] [ keyfield ] #NEWLINE# #UNINDENT# sorted_tuple = sorted ( intermediate . items ( ) , key = ( lambda k : k [ 1 ] ) , reverse = True ) #NEWLINE# sorted_indices = [ x [ 0 ] for x in sorted_tuple ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sorted_indices = sorted ( working_list , reverse = reverse ) #NEWLINE# #UNINDENT# for index in sorted_indices : #NEWLINE# #INDENT# disk_usage += self . index_info [ index ] [ 'size_in_bytes' ] #NEWLINE# msg = '{0}, summed disk usage is {1} and disk limit is {2}.' . format ( index , byte_size ( disk_usage ) , byte_size ( disk_limit ) ) #NEWLINE# self . __excludify ( ( disk_usage > disk_limit ) , exclude , index , msg )