Coverage for curator/defaults/settings.py: 100%

33 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-08-16 15:27 -0600

1"""Utilities/Helpers for defaults and schemas""" 

2from os import path 

3from six import string_types 

4from voluptuous import Any, Boolean, Coerce, Optional 

5 

6# Elasticsearch versions supported 

7def version_max(): 

8 """Return the maximum Elasticsearch version Curator supports""" 

9 return (7, 17, 99) 

10def version_min(): 

11 """Return the minimum Elasticsearch version Curator supports""" 

12 return (7, 0, 0) 

13 

14# Default Config file location 

15def config_file(): 

16 """Return the default config file location""" 

17 return path.join(path.expanduser('~'), '.curator', 'curator.yml') 

18 

19# Default filter patterns (regular expressions) 

20def regex_map(): 

21 """Return a dictionary of pattern filter 'kind's with their associated regular expression""" 

22 return { 

23 'timestring': r'^.*{0}.*$', 

24 'regex': r'{0}', 

25 'prefix': r'^{0}.*$', 

26 'suffix': r'^.*{0}$', 

27 } 

28 

29def date_regex(): 

30 """Return a dictionary/map of the strftime string characters and their string length""" 

31 return { 

32 'Y' : '4', 

33 'G' : '4', 

34 'y' : '2', 

35 'm' : '2', 

36 'W' : '2', 

37 'V' : '2', 

38 'U' : '2', 

39 'd' : '2', 

40 'H' : '2', 

41 'M' : '2', 

42 'S' : '2', 

43 'j' : '3', 

44 } 

45 

46# Actions 

47 

48def cluster_actions(): 

49 """Return a list of supported cluster actions""" 

50 return ['cluster_routing'] 

51 

52def index_actions(): 

53 """Return a list of supported index actions""" 

54 return [ 

55 'alias', 

56 'allocation', 

57 'close', 

58 'create_index', 

59 'delete_indices', 

60 'forcemerge', 

61 'freeze', 

62 'index_settings', 

63 'open', 

64 'reindex', 

65 'replicas', 

66 'rollover', 

67 'shrink', 

68 'snapshot', 

69 'unfreeze', 

70 ] 

71 

72def snapshot_actions(): 

73 """Return a list of supported snapshot actions""" 

74 return ['delete_snapshots', 'restore'] 

75 

76def all_actions(): 

77 """Return a sorted list of all supported actions: cluster, index, and snapshot""" 

78 return sorted(cluster_actions() + index_actions() + snapshot_actions()) 

79 

80def index_filtertypes(): 

81 """Return a list of supported index filter types""" 

82 return [ 

83 'alias', 

84 'allocated', 

85 'age', 

86 'closed', 

87 'count', 

88 'empty', 

89 'forcemerged', 

90 'ilm', 

91 'kibana', 

92 'none', 

93 'opened', 

94 'pattern', 

95 'period', 

96 'space', 

97 'shards', 

98 'size', 

99 ] 

100 

101def snapshot_filtertypes(): 

102 """Return a list of supported snapshot filter types""" 

103 return ['age', 'count', 'none', 'pattern', 'period', 'state'] 

104 

105def all_filtertypes(): 

106 """Return a sorted list of all supported filter types (both snapshot and index)""" 

107 return sorted(list(set(index_filtertypes() + snapshot_filtertypes()))) 

108 

109def default_options(): 

110 """Set default values for these options""" 

111 return { 

112 'allow_ilm_indices': False, 

113 'continue_if_exception': False, 

114 'disable_action': False, 

115 'ignore_empty_list': False, 

116 'timeout_override': None, 

117 } 

118 

119def default_filters(): 

120 """If no filters are set, add a 'none' filter""" 

121 return {'filters': [{'filtertype': 'none'}]} 

122 

123def structural_filter_elements(): 

124 """Barebones schemas for initial validation of filters""" 

125 # pylint: disable=E1120 

126 return { 

127 Optional('aliases'): Any(list, *string_types), 

128 Optional('allocation_type'): Any(*string_types), 

129 Optional('count'): Coerce(int), 

130 Optional('date_from'): Any(None, *string_types), 

131 Optional('date_from_format'): Any(None, *string_types), 

132 Optional('date_to'): Any(None, *string_types), 

133 Optional('date_to_format'): Any(None, *string_types), 

134 Optional('direction'): Any(*string_types), 

135 Optional('disk_space'): float, 

136 Optional('epoch'): Any(Coerce(int), None), 

137 Optional('exclude'): Any(None, bool, int, *string_types), 

138 Optional('field'): Any(None, *string_types), 

139 Optional('intersect'): Any(None, bool, int, *string_types), 

140 Optional('key'): Any(*string_types), 

141 Optional('kind'): Any(*string_types), 

142 Optional('max_num_segments'): Coerce(int), 

143 Optional('number_of_shards'): Coerce(int), 

144 Optional('pattern'): Any(*string_types), 

145 Optional('period_type'): Any(*string_types), 

146 Optional('reverse'): Any(None, bool, int, *string_types), 

147 Optional('range_from'): Coerce(int), 

148 Optional('range_to'): Coerce(int), 

149 Optional('shard_filter_behavior'): Any(*string_types), 

150 Optional('size_behavior'): Any(*string_types), 

151 Optional('size_threshold'): Any(Coerce(float)), 

152 Optional('source'): Any(*string_types), 

153 Optional('state'): Any(*string_types), 

154 Optional('stats_result'): Any(None, *string_types), 

155 Optional('timestring'): Any(None, *string_types), 

156 Optional('threshold_behavior'): Any(*string_types), 

157 Optional('unit'): Any(*string_types), 

158 Optional('unit_count'): Coerce(int), 

159 Optional('unit_count_pattern'): Any(*string_types), 

160 Optional('use_age'): Boolean(), 

161 Optional('value'): Any(int, float, bool, *string_types), 

162 Optional('week_starts_on'): Any(None, *string_types), 

163 }