def process_action()

in curator/cli.py [0:0]


def process_action(client, action_def, dry_run=False):
    """
    Do the ``action`` in ``action_def.action``, using the associated options and
    any ``kwargs``.

    :param client: A client connection object
    :param action_def: The ``action`` object

    :type client: :py:class:`~.elasticsearch.Elasticsearch`
    :type action_def: :py:class:`~.curator.classdef.ActionDef`
    :rtype: None
    """
    logger = logging.getLogger(__name__)
    logger.debug('Configuration dictionary: %s', action_def.action_dict)
    mykwargs = {}

    logger.debug('INITIAL Action kwargs: %s', mykwargs)
    # Add some settings to mykwargs...
    if action_def.action == 'delete_indices':
        mykwargs['master_timeout'] = 30

    # Update the defaults with whatever came with opts, minus any Nones
    mykwargs.update(prune_nones(action_def.options))

    # Pop out the search_pattern option, if present.
    ptrn = mykwargs.pop('search_pattern', '*')
    hidn = mykwargs.pop('include_hidden', False)

    logger.debug('Action kwargs: %s', mykwargs)
    logger.debug('Post search_pattern & include_hidden Action kwargs: %s', mykwargs)

    # Set up the action
    logger.debug('Running "%s"', action_def.action.upper())
    if action_def.action == 'alias':
        # Special behavior for this action, as it has 2 index lists
        action_def.instantiate('action_cls', **mykwargs)
        action_def.instantiate(
            'alias_adds', client, search_pattern=ptrn, include_hidden=hidn
        )
        action_def.instantiate(
            'alias_removes', client, search_pattern=ptrn, include_hidden=hidn
        )
        if 'remove' in action_def.action_dict:
            logger.debug('Removing indices from alias "%s"', action_def.options['name'])
            action_def.alias_removes.iterate_filters(action_def.action_dict['remove'])
            action_def.action_cls.remove(
                action_def.alias_removes,
                warn_if_no_indices=action_def.options['warn_if_no_indices'],
            )
        if 'add' in action_def.action_dict:
            logger.debug('Adding indices to alias "%s"', action_def.options['name'])
            action_def.alias_adds.iterate_filters(action_def.action_dict['add'])
            action_def.action_cls.add(
                action_def.alias_adds,
                warn_if_no_indices=action_def.options['warn_if_no_indices'],
            )
    elif action_def.action in ['cluster_routing', 'create_index', 'rollover']:
        action_def.instantiate('action_cls', client, **mykwargs)
    else:
        if action_def.action in ['delete_snapshots', 'restore']:
            mykwargs.pop('repository')  # We don't need to send this value to the action
            action_def.instantiate(
                'list_obj', client, repository=action_def.options['repository']
            )
        else:
            action_def.instantiate(
                'list_obj', client, search_pattern=ptrn, include_hidden=hidn
            )
        action_def.list_obj.iterate_filters({'filters': action_def.filters})
        logger.debug(f'Pre Instantiation Action kwargs: {mykwargs}')
        action_def.instantiate('action_cls', action_def.list_obj, **mykwargs)
    # Do the action
    if dry_run:
        action_def.action_cls.do_dry_run()
    else:
        logger.debug('Doing the action here.')
        action_def.action_cls.do_action()