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

1"""Snapshot Restore Singleton"""

2 import click

3 from curator.cli_singletons.object_class import cli_action

4 from curator.cli_singletons.utils import get_width, json_to_dict, validate_filter_json

5

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

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

8@click.option('--name', type=str, help='Snapshot name', required=False, default=None)

9@click.option(

10 '--index',

11 multiple=True,

12 help='Index name to restore. (Can invoke repeatedly for multiple indices)'

13)

14@click.option(

15 '--rename_pattern',

16 type=str,

17 help='Rename pattern',

18 required=False,

19 default=None

20)

21@click.option(

22 '--rename_replacement',

23 type=str,

24 help='Rename replacement',

25 required=False,

26 default=None

27)

28@click.option(

29 '--extra_settings',

30 type=str,

31 help='JSON version of extra_settings (see documentation)',

32 callback=json_to_dict

33)

34@click.option(

35 '--include_aliases',

36 is_flag=True,

37 show_default=True,

38 help='Include aliases with restored indices.'

39)

40@click.option(

41 '--ignore_unavailable',

42 is_flag=True,

43 show_default=True,

44 help='Ignore unavailable shards/indices.'

45)

46@click.option(

47 '--include_global_state',

48 is_flag=True,

49 show_default=True,

50 help='Restore cluster global state with snapshot.'

51)

52@click.option(

53 '--partial',

54 is_flag=True,

55 show_default=True,

56 help='Restore partial data (from snapshot taken with --partial).'

57)

58@click.option(

59 '--wait_for_completion/--no-wait_for_completion',

60 default=True,

61 show_default=True,

62 help='Wait for the snapshot to complete'

63)

64@click.option(

65 '--wait_interval',

66 default=9,

67 type=int,

68 help='Seconds to wait between completion checks.'

69)

70@click.option(

71 '--max_wait',

72 default=-1,

73 type=int,

74 help='Maximum number of seconds to wait_for_completion'

75)

76@click.option(

77 '--skip_repo_fs_check',

78 is_flag=True,

79 show_default=True,

80 help='Skip repository filesystem access validation.'

81)

82@click.option(

83 '--ignore_empty_list',

84 is_flag=True,

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

86)

87@click.option(

88 '--allow_ilm_indices/--no-allow_ilm_indices',

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

90 default=False,

91 show_default=True

92)

93@click.option(

94 '--filter_list',

95 callback=validate_filter_json,

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

97 required=True

98)

99@click.pass_context

100 def restore(

101 ctx, repository, name, index, rename_pattern, rename_replacement, extra_settings,

102 include_aliases, ignore_unavailable, include_global_state, partial, wait_for_completion,

103 wait_interval, max_wait, skip_repo_fs_check, ignore_empty_list, allow_ilm_indices,

104 filter_list

105 ):

106 """

107 Restore Indices

108 """

109 indices = list(index)

110 manual_options = {

111 'name': name,

112 'indices': indices,

113 'rename_pattern': rename_pattern,

114 'rename_replacement': rename_replacement,

115 'ignore_unavailable': ignore_unavailable,

116 'include_aliases': include_aliases,

117 'include_global_state': include_global_state,

118 'partial': partial,

119 'skip_repo_fs_check': skip_repo_fs_check,

120 'wait_for_completion': wait_for_completion,

121 'max_wait': max_wait,

122 'wait_interval': wait_interval,

123 'allow_ilm_indices': allow_ilm_indices,

124 }

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

126 action = cli_action(

127 ctx.info_name,

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

129 manual_options,

130 filter_list,

131 ignore_empty_list,

132 repository=repository

133 )

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