11"""Alias action"""
2+
23import logging
4+
35# pylint: disable=import-error
46from curator .exceptions import ActionError , MissingArgument , NoIndices
57from curator .helpers .date_ops import parse_date_pattern , parse_datemath
68from curator .helpers .testers import verify_index_list
79from curator .helpers .utils import report_failure
810
11+
912class Alias :
1013 """Alias Action Class"""
14+
1115 # pylint: disable=unused-argument
1216 def __init__ (self , name = None , extra_settings = None , ** kwargs ):
1317 """
1418 :param name: The alias name
15- :param extra_settings: Extra settings, including filters and routing. For more information
16- see `here </https://www.elastic.co/guide/en/elasticsearch/reference/8.6/indices-aliases.html>`_.
19+ :param extra_settings: Extra settings, including filters and routing.
20+ For more information see `here
21+ </https://www.elastic.co/guide/en/elasticsearch/reference/8.6/indices-aliases.html>`_.
1722
1823 :type name: str
1924 :type extra_settings: dict
@@ -25,14 +30,16 @@ def __init__(self, name=None, extra_settings=None, **kwargs):
2530 #: The :py:func:`~.curator.helpers.date_ops.parse_date_pattern` rendered
2631 #: version of what was passed by param ``name``.
2732 self .name = parse_date_pattern (name )
28- #: The list of actions to perform. Populated by :py:meth:`~.curator.actions.Alias.add` and
33+ #: The list of actions to perform. Populated by
34+ #: :py:meth:`~.curator.actions.Alias.add` and
2935 #: :py:meth:`~.curator.actions.Alias.remove`
3036 self .actions = []
31- #: The :py:class:`~.elasticsearch.Elasticsearch` client object which will later be set by
32- #: :py:meth:`~.curator.actions.Alias.add` or :py:meth:`~.curator.actions.Alias.remove`
37+ #: The :py:class:`~.elasticsearch.Elasticsearch` client object which will
38+ #: later be set by :py:meth:`~.curator.actions.Alias.add` or
39+ #: :py:meth:`~.curator.actions.Alias.remove`
3340 self .client = None
34- #: Any extra things to add to the alias, like filters, or routing. Gets the value from
35- #: param ``extra_settings``.
41+ #: Any extra things to add to the alias, like filters, or routing. Gets
42+ #: the value from param ``extra_settings``.
3643 self .extra_settings = extra_settings
3744 self .loggit = logging .getLogger ('curator.actions.alias' )
3845 #: Preset default value to ``False``.
@@ -41,7 +48,8 @@ def __init__(self, name=None, extra_settings=None, **kwargs):
4148 def add (self , ilo , warn_if_no_indices = False ):
4249 """
4350 Create ``add`` statements for each index in ``ilo`` for :py:attr:`name`, then
44- append them to :py:attr:`actions`. Add any :py:attr:`extra_settings` that may be there.
51+ append them to :py:attr:`actions`. Add any :py:attr:`extra_settings` that
52+ may be there.
4553
4654 :param ilo: An IndexList Object
4755 :type ilo: :py:class:`~.curator.indexlist.IndexList`
@@ -58,16 +66,20 @@ def add(self, ilo, warn_if_no_indices=False):
5866 if warn_if_no_indices :
5967 self .warn_if_no_indices = True
6068 self .loggit .warning (
61- 'No indices found after processing filters. Nothing to add to %s' , self .name )
69+ 'No indices found after processing filters. Nothing to add to %s' ,
70+ self .name ,
71+ )
6272 return
6373 # Re-raise the exceptions.NoIndices so it will behave as before
6474 raise NoIndices ('No indices to add to alias' ) from exc
6575 for index in ilo .working_list ():
6676 self .loggit .debug (
67- 'Adding index %s to alias %s with extra settings '
68- '%s' , index , self .name , self .extra_settings
77+ 'Adding index %s to alias %s with extra settings %s' ,
78+ index ,
79+ self .name ,
80+ self .extra_settings ,
6981 )
70- add_dict = {'add' : {'index' : index , 'alias' : self .name }}
82+ add_dict = {'add' : {'index' : index , 'alias' : self .name }}
7183 add_dict ['add' ].update (self .extra_settings )
7284 self .actions .append (add_dict )
7385
@@ -92,7 +104,8 @@ def remove(self, ilo, warn_if_no_indices=False):
92104 self .warn_if_no_indices = True
93105 self .loggit .warning (
94106 'No indices found after processing filters. '
95- 'Nothing to remove from %s' , self .name
107+ 'Nothing to remove from %s' ,
108+ self .name ,
96109 )
97110 return
98111
@@ -104,19 +117,24 @@ def remove(self, ilo, warn_if_no_indices=False):
104117 self .loggit .debug ('Index %s in get_aliases output' , index )
105118 # Only remove if the index is associated with the alias
106119 if self .name in aliases [index ]['aliases' ]:
107- self .loggit .debug ('Removing index %s from alias %s' , index , self .name )
120+ self .loggit .debug (
121+ 'Removing index %s from alias %s' , index , self .name
122+ )
108123 self .actions .append (
109- {'remove' : {'index' : index , 'alias' : self .name }})
124+ {'remove' : {'index' : index , 'alias' : self .name }}
125+ )
110126 else :
111127 self .loggit .debug (
112- 'Can not remove: Index %s is not associated with alias %s' , index , self .name
128+ 'Can not remove: Index %s is not associated with alias %s' ,
129+ index ,
130+ self .name ,
113131 )
114132
115133 def check_actions (self ):
116134 """
117135 :returns: :py:attr:`actions` for use with the
118- :py:meth:`~.elasticsearch.client.IndicesClient.update_aliases` API call if actions
119- exist, otherwise an exception is raised.
136+ :py:meth:`~.elasticsearch.client.IndicesClient.update_aliases` API
137+ call if actions exist, otherwise an exception is raised.
120138 """
121139 if not self .actions :
122140 if not self .warn_if_no_indices :
@@ -143,8 +161,8 @@ def do_dry_run(self):
143161
144162 def do_action (self ):
145163 """
146- :py:meth:`~.elasticsearch.client.IndicesClient.update_aliases` for :py:attr:`name` with
147- :py:attr:`actions`
164+ :py:meth:`~.elasticsearch.client.IndicesClient.update_aliases` for
165+ :py:attr:`name` with :py:attr:` actions`
148166 """
149167 self .loggit .info ('Updating aliases...' )
150168 self .loggit .info ('Alias actions: %s' , self .actions )
0 commit comments