Coverage for curator/cli_singletons/rollover.py: 100%
21 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-16 15:27 -0600
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-16 15:27 -0600
1"""Index Rollover Singleton"""
2import click
3from curator.cli_singletons.object_class import cli_action
4from curator.cli_singletons.utils import get_width, json_to_dict, validate_filter_json
6@click.command(context_settings=get_width())
7@click.option('--name', type=str, help='Alias name', required=True)
8@click.option('--max_age', type=str, help='max_age condition value (see documentation)')
9@click.option('--max_docs', type=str, help='max_docs condition value (see documentation)')
10@click.option('--max_size', type=str, help='max_size condition value (see documentation)')
11@click.option(
12 '--extra_settings',
13 type=str,
14 help='JSON version of extra_settings (see documentation)',
15 callback=json_to_dict
16)
17@click.option(
18 '--new_index',
19 type=str,
20 help='Optional new index name (see documentation)'
21)
22@click.option(
23 '--wait_for_active_shards',
24 type=int,
25 default=1,
26 show_default=True,
27 help='Wait for number of shards to be active before returning'
28)
29@click.option(
30 '--allow_ilm_indices/--no-allow_ilm_indices',
31 help='Allow Curator to operate on Index Lifecycle Management monitored indices.',
32 default=False,
33 show_default=True
34)
35@click.pass_context
36def rollover(
37 ctx, name, max_age, max_docs, max_size, extra_settings, new_index, wait_for_active_shards,
38 allow_ilm_indices
39 ):
40 """
41 Rollover Index associated with Alias
42 """
43 conditions = {}
44 for cond in ['max_age', 'max_docs', 'max_size']:
45 if eval(cond) is not None:
46 conditions[cond] = eval(cond)
47 manual_options = {
48 'name': name,
49 'conditions': conditions,
50 'allow_ilm_indices': allow_ilm_indices,
51 }
52 # ctx.info_name is the name of the function or name specified in @click.command decorator
53 action = cli_action(
54 ctx.info_name, ctx.obj['config']['client'], manual_options, [], True,
55 extra_settings=extra_settings,
56 new_index=new_index,
57 wait_for_active_shards=wait_for_active_shards
58 )
59 action.do_singleton_action(dry_run=ctx.obj['dry_run'])