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

1"""Option schema definitions"""

2 from six import string_types

3 from voluptuous import All, Any, Boolean, Coerce, Optional, Range, Required

4

5# pylint: disable=line-too-long,missing-docstring

6# pylint: disable=E1120

7# Action Options

8

9 def allocation_type():

10 return {Optional('allocation_type', default='require'): All(Any(*string_types), Any('require', 'include', 'exclude'))}

11

12 def allow_ilm_indices():

13 return {Optional('allow_ilm_indices', default=False): Any(bool, All(Any(*string_types), Boolean()))}

14

15 def conditions():

16 return {Optional('conditions'): {Optional('max_age'): Any(*string_types), Optional('max_docs'): Coerce(int), Optional('max_size'): Any(*string_types)}}

17

18 def continue_if_exception():

19 return {Optional('continue_if_exception', default=False): Any(bool, All(Any(*string_types), Boolean()))}

20

21 def count():

22 return {Required('count'): All(Coerce(int), Range(min=0, max=10))}

23

24 def delay():

25 return {Optional('delay', default=0): All(Coerce(float), Range(min=0.0, max=3600.0))}

26

27 def copy_aliases():

28 return {Optional('copy_aliases', default=False): Any(bool, All(Any(*string_types), Boolean()))}

29

30 def delete_after():

31 return {Optional('delete_after', default=True): Any(bool, All(Any(*string_types), Boolean()))}

32

33 def delete_aliases():

34 return {Optional('delete_aliases', default=False): Any(bool, All(Any(*string_types), Boolean()))}

35

36 def skip_flush():

37 return {Optional('skip_flush', default=False): Any(bool, All(Any(*string_types), Boolean()))}

38

39 def disable_action():

40 return {Optional('disable_action', default=False): Any(bool, All(Any(*string_types), Boolean()))}

41

42 def extra_settings():

43 return {Optional('extra_settings', default={}): dict}

44

45 def ignore_empty_list():

46 return {Optional('ignore_empty_list', default=False): Any(bool, All(Any(*string_types), Boolean()))}

47

48 def ignore_existing():

49 return {Optional('ignore_existing', default=False): Any(bool, All(Any(*string_types), Boolean()))}

50

51 def ignore_sync_failures():

52 return {Optional('ignore_sync_failures', default=False): Any(bool, All(Any(*string_types), Boolean()))}

53

54 def ignore_unavailable():

55 return {Optional('ignore_unavailable', default=False): Any(bool, All(Any(*string_types), Boolean()))}

56

57 def include_aliases():

58 return {Optional('include_aliases', default=False): Any(bool, All(Any(*string_types), Boolean()))}

59

60 def include_global_state(action):

61 default = False

62 if action == 'snapshot':

63 default = True

64 return {Optional('include_global_state', default=default): Any(bool, All(Any(*string_types), Boolean()))}

65

66 def index_settings():

67 return {Required('index_settings'): {'index': dict}}

68

69 def indices():

70 return {Optional('indices', default=None): Any(None, list)}

71

72 def key():

73 return {Required('key'): Any(*string_types)}

74

75 def max_num_segments():

76 return {Required('max_num_segments'): All(Coerce(int), Range(min=1, max=32768))}

77

78 def max_wait(action):

79 # The separation is here in case I want to change defaults later...

80 value = -1

81 # if action in ['allocation', 'cluster_routing', 'replicas']:

82 # value = -1

83 # elif action in ['restore', 'snapshot', 'reindex', 'shrink']:

84 # value = -1

85 return {Optional('max_wait', default=value): Any(-1, Coerce(int), None)}

86

87 def migration_prefix():

88 return {Optional('migration_prefix', default=''): Any(None, *string_types)}

89

90 def migration_suffix():

91 return {Optional('migration_suffix', default=''): Any(None, *string_types)}

92

93 def name(action):

94 if action in ['alias', 'create_index', 'rollover']:

95 return {Required('name'): Any(*string_types)}

96 elif action == 'snapshot':

97 return {Optional('name', default='curator-%Y%m%d%H%M%S'): Any(*string_types)}

98 elif action == 'restore':

99 return {Optional('name'): Any(*string_types)}

100

101

102 def new_index():

103 return {Optional('new_index', default=None): Any(None, *string_types)}

104

105 def node_filters():

106 return {

107 Optional('node_filters', default={}): {

108 Optional('permit_masters', default=False): Any(bool, All(Any(*string_types), Boolean())),

109 Optional('exclude_nodes', default=[]): Any(list, None)

110 }

111 }

112

113 def number_of_replicas():

114 return {Optional('number_of_replicas', default=1): All(Coerce(int), Range(min=0, max=10))}

115

116 def number_of_shards():

117 return {Optional('number_of_shards', default=1): All(Coerce(int), Range(min=1, max=99))}

118

119 def partial():

120 return {Optional('partial', default=False): Any(bool, All(Any(*string_types), Boolean()))}

121

122 def post_allocation():

123 return {

124 Optional('post_allocation', default={}):

125 Any(

126 {},

127 All(

128 {

129 Required('allocation_type', default='require'): All(Any(*string_types), Any('require', 'include', 'exclude')),

130 Required('key'): Any(*string_types),

131 Required('value', default=None): Any(None, *string_types)

132 }

133 )

134 )

135 }

136

137 def preserve_existing():

138 return {Optional('preserve_existing', default=False): Any(bool, All(Any(*string_types), Boolean()))}

139

140 def refresh():

141 return {Optional('refresh', default=True): Any(bool, All(Any(*string_types), Boolean()))}

142

143 def remote_aws_key():

144 return {Optional('remote_aws_key', default=None): Any(None, *string_types)}

145

146 def remote_aws_secret_key():

147 return {Optional('remote_aws_secret_key', default=None): Any(None, *string_types)}

148

149 def remote_aws_region():

150 return {Optional('remote_aws_region', default=None): Any(None, *string_types)}

151

152 def remote_certificate():

153 return {Optional('remote_certificate', default=None): Any(None, *string_types)}

154

155 def remote_client_cert():

156 return {Optional('remote_client_cert', default=None): Any(None, *string_types)}

157

158 def remote_client_key():

159 return {Optional('remote_client_key', default=None): Any(None, *string_types)}

160

161 def remote_filters():

162 # This is really just a basic check here. The real check is in the

163 # validate_actions() method in utils.py

164 return {

165 Optional(

166 'remote_filters',

167 default=[

168 {

169 'filtertype': 'pattern',

170 'kind': 'regex',

171 'value': '.*',

172 'exclude': True,

173 }

174 ]

175 ): Any(list, None)

176 }

177

178 def remote_ssl_no_validate():

179 return {Optional('remote_ssl_no_validate', default=False): Any(bool, All(Any(*string_types), Boolean()))}

180

181 def remote_url_prefix():

182 return {Optional('remote_url_prefix', default=''): Any(None, *string_types)}

183

184 def rename_pattern():

185 return {Optional('rename_pattern'): Any(*string_types)}

186

187 def rename_replacement():

188 return {Optional('rename_replacement'): Any(*string_types)}

189

190 def repository():

191 return {Required('repository'): Any(*string_types)}

192

193 def request_body():

194 return {

195 Required('request_body'): {

196 Optional('conflicts'): Any(*string_types),

197 Optional('size'): Coerce(int),

198 Required('source'): {

199 Required('index'): Any(Any(*string_types), list),

200 Optional('remote'): {

201 Optional('host'): Any(*string_types),

202 Optional('headers'): Any(*string_types),

203 Optional('username'): Any(*string_types),

204 Optional('password'): Any(*string_types),

205 Optional('socket_timeout'): Any(*string_types),

206 Optional('connect_timeout'): Any(*string_types),

207 },

208 Optional('size'): Coerce(int),

209 Optional('type'): Any(Any(*string_types), list),

210 Optional('query'): dict,

211 Optional('sort'): dict,

212 Optional('_source'): Any(Any(*string_types), list),

213 },

214 Required('dest'): {

215 Required('index'): Any(*string_types),

216 Optional('type'): Any(Any(*string_types), list),

217 Optional('op_type'): Any(*string_types),

218 Optional('version_type'): Any(*string_types),

219 Optional('routing'): Any(*string_types),

220 Optional('pipeline'): Any(*string_types),

221 },

222 Optional('script'): dict,

223 }

224 }

225

226 def requests_per_second():

227 return {Optional('requests_per_second', default=-1): Any(-1, Coerce(int), None)}

228

229 def retry_count():

230 return {Optional('retry_count', default=3): All(Coerce(int), Range(min=0, max=100))}

231

232 def retry_interval():

233 return {Optional('retry_interval', default=120): All(Coerce(int), Range(min=1, max=600))}

234

235 def routing_type():

236 return {Required('routing_type'): Any('allocation', 'rebalance')}

237

238 def cluster_routing_setting():

239 return {Required('setting'): Any('enable')}

240

241 def cluster_routing_value():

242 return {Required('value'): Any('all', 'primaries', 'none', 'new_primaries', 'replicas')}

243

244 def shrink_node():

245 return {Required('shrink_node'): Any(*string_types)}

246

247 def shrink_prefix():

248 return {Optional('shrink_prefix', default=''): Any(None, *string_types)}

249

250 def shrink_suffix():

251 return {Optional('shrink_suffix', default='-shrink'): Any(None, *string_types)}

252

253 def skip_repo_fs_check():

254 return {Optional('skip_repo_fs_check', default=False): Any(bool, All(Any(*string_types), Boolean()))}

255

256 def slices():

257 return {Optional('slices', default=1): Any(All(Coerce(int), Range(min=1, max=500)), None)}

258

259 def timeout(action):

260 # if action == 'reindex':

261 value = 60

262 return {Optional('timeout', default=value): Any(Coerce(int), None)}

263

264 def timeout_override(action):

265 if action in ['forcemerge', 'restore', 'snapshot']:

266 value = 21600

267 elif action == 'close':

268 value = 180

269 elif action == 'delete_snapshots':

270 value = 300

271 else:

272 value = None

273

274 return {

275 Optional('timeout_override', default=value): Any(Coerce(int), None)

276 }

277

278 def value():

279 return {Required('value', default=None): Any(None, *string_types)}

280

281 def wait_for_active_shards(action):

282 value = 0

283 if action in ['reindex', 'shrink']:

284 value = 1

285 return {

286 Optional('wait_for_active_shards', default=value): Any(

287 Coerce(int), 'all', None)

288 }

289

290 def wait_for_completion(action):

291 # if action in ['reindex', 'restore', 'snapshot']:

292 value = True

293 if action in ['allocation', 'cluster_routing', 'replicas']:

294 value = False

295 return {Optional('wait_for_completion', default=value): Any(bool, All(Any(*string_types), Boolean()))}

296

297 def wait_for_rebalance():

298 return {Optional('wait_for_rebalance', default=True): Any(bool, All(Any(*string_types), Boolean()))}

299

300 def wait_interval(action):

301 minval = 1

302 maxval = 30

303 # if action in ['allocation', 'cluster_routing', 'replicas']:

304 value = 3

305 if action in ['restore', 'snapshot', 'reindex', 'shrink']:

306 value = 9

307 return {Optional('wait_interval', default=value): Any(All(

308 Coerce(int), Range(min=minval, max=maxval)), None)}

309

310 def warn_if_no_indices():

311 return {Optional('warn_if_no_indices', default=False): Any(bool, All(Any(*string_types), Boolean()))}