Coverage for curator/cli_singletons/delete.py: 100%

1"""Delete Index and Delete Snapshot Singletons"""

2 import click

3 from curator.cli_singletons.object_class import cli_action

4 from curator.cli_singletons.utils import get_width, validate_filter_json

5

6#### Indices ####

7@click.command(context_settings=get_width())

8@click.option(

9 '--ignore_empty_list',

10 is_flag=True,

11 help='Do not raise exception if there are no actionable indices'

12)

13@click.option(

14 '--allow_ilm_indices/--no-allow_ilm_indices',

15 help='Allow Curator to operate on Index Lifecycle Management monitored indices.',

16 default=False,

17 show_default=True

18)

19@click.option(

20 '--filter_list',

21 callback=validate_filter_json,

22 help='JSON array of filters selecting indices to act on.',

23 required=True

24)

25@click.pass_context

26 def delete_indices(ctx, ignore_empty_list, allow_ilm_indices, filter_list):

27 """

28 Delete Indices

29 """

30 # ctx.info_name is the name of the function or name specified in @click.command decorator

31 action = cli_action(

32 'delete_indices',

33 ctx.obj['config']['client'],

34 {'allow_ilm_indices':allow_ilm_indices},

35 filter_list,

36 ignore_empty_list

37 )

38 action.do_singleton_action(dry_run=ctx.obj['dry_run'])

39

40#### Snapshots ####

41@click.command(context_settings=get_width())

42@click.option('--repository', type=str, required=True, help='Snapshot repository name')

43@click.option('--retry_count', type=int, help='Number of times to retry (max 3)')

44@click.option('--retry_interval', type=int, help='Time in seconds between retries')

45@click.option(

46 '--ignore_empty_list',

47 is_flag=True,

48 help='Do not raise exception if there are no actionable snapshots'

49)

50@click.option(

51 '--allow_ilm_indices/--no-allow_ilm_indices',

52 help='Allow Curator to operate on Index Lifecycle Management monitored indices.',

53 default=False,

54 show_default=True

55)

56@click.option(

57 '--filter_list',

58 callback=validate_filter_json,

59 help='JSON array of filters selecting snapshots to act on.',

60 required=True

61)

62@click.pass_context

63 def delete_snapshots(

64 ctx, repository, retry_count, retry_interval,

65 ignore_empty_list, allow_ilm_indices, filter_list

66 ):

67 """

68 Delete Snapshots

69 """

70 manual_options = {

71 'retry_count': retry_count,

72 'retry_interval': retry_interval,

73 'allow_ilm_indices': allow_ilm_indices,

74 }

75 # ctx.info_name is the name of the function or name specified in @click.command decorator

76 action = cli_action(

77 'delete_snapshots',

78 ctx.obj['config']['client'],

79 manual_options,

80 filter_list,

81 ignore_empty_list,

82 repository=repository

83 )

84 action.do_singleton_action(dry_run=ctx.obj['dry_run'])