コード例 #1
0
 def get_list_object(self):
     if self.action in snapshot_actions(
     ) or self.action == 'show_snapshots':
         self.list_object = SnapshotList(self.client,
                                         repository=self.repository)
     else:
         self.list_object = IndexList(self.client)
コード例 #2
0
def source(**kwargs):
    # This setting is only used with the age filtertype, or with the space
    # filtertype when use_age is set to True.
    if 'action' in kwargs and kwargs['action'] in settings.snapshot_actions():
        valuelist = Any('name', 'creation_date')
    else:
        valuelist = Any('name', 'creation_date', 'field_stats')

    if 'required' in kwargs and kwargs['required']:
        return {Required('source'): valuelist}
    else:
        return {Optional('source'): valuelist}
コード例 #3
0
ファイル: filter_elements.py プロジェクト: untergeek/curator
def source(**kwargs):
    # This setting is only used with the age filtertype, or with the space
    # filtertype when use_age is set to True.
    if 'action' in kwargs and kwargs['action'] in settings.snapshot_actions():
        valuelist = Any('name', 'creation_date')
    else:
        valuelist = Any('name', 'creation_date', 'field_stats')

    if 'required' in kwargs and kwargs['required']:
        return { Required('source'): valuelist }
    else:
        return { Optional('source'): valuelist }
コード例 #4
0
ファイル: cli.py プロジェクト: untergeek/curator
def run(config, action_file, dry_run=False):
    """
    Actually run.
    """
    client_args = process_config(config)
    logger = logging.getLogger(__name__)
    logger.debug('Client and logging options validated.')

    # Extract this and save it for later, in case there's no timeout_override.
    default_timeout = client_args.pop('timeout')
    logger.debug('default_timeout = {0}'.format(default_timeout))
    #########################################
    ### Start working on the actions here ###
    #########################################
    logger.debug('action_file: {0}'.format(action_file))
    action_config = get_yaml(action_file)
    logger.debug('action_config: {0}'.format(password_filter(action_config)))
    action_dict = validate_actions(action_config)
    actions = action_dict['actions']
    logger.debug('Full list of actions: {0}'.format(password_filter(actions)))
    action_keys = sorted(list(actions.keys()))
    for idx in action_keys:
        action = actions[idx]['action']
        action_disabled = actions[idx]['options'].pop('disable_action')
        logger.debug('action_disabled = {0}'.format(action_disabled))
        continue_if_exception = (
            actions[idx]['options'].pop('continue_if_exception'))
        logger.debug(
            'continue_if_exception = {0}'.format(continue_if_exception))
        timeout_override = actions[idx]['options'].pop('timeout_override')
        logger.debug('timeout_override = {0}'.format(timeout_override))
        ignore_empty_list = actions[idx]['options'].pop('ignore_empty_list')
        logger.debug('ignore_empty_list = {0}'.format(ignore_empty_list))
        allow_ilm = actions[idx]['options'].pop('allow_ilm_indices')
        logger.debug('allow_ilm_indices = {0}'.format(allow_ilm))
        ### Filter ILM indices unless expressly permitted
        if not allow_ilm and action not in settings.snapshot_actions():
            if 'filters' in actions[idx]:
                actions[idx]['filters'].append({'filtertype': 'ilm'})
            else:
                actions[idx]['filters'] = [{'filtertype': 'ilm'}]
        ### Skip to next action if 'disabled'
        if action_disabled:
            logger.info(
                'Action ID: {0}: "{1}" not performed because "disable_action" '
                'is set to True'.format(idx, action)
            )
            continue
        else:
            logger.info('Preparing Action ID: {0}, "{1}"'.format(idx, action))
        # Override the timeout, if specified, otherwise use the default.
        if isinstance(timeout_override, int):
            client_args['timeout'] = timeout_override
        else:
            client_args['timeout'] = default_timeout

        # Set up action kwargs
        kwargs = {}
        kwargs['master_timeout'] = (
            client_args['timeout'] if client_args['timeout'] <= 300 else 300)
        kwargs['dry_run'] = dry_run

        # Create a client object for each action...
        client = get_client(**client_args)
        logger.debug('client is {0}'.format(type(client)))
        ##########################
        ### Process the action ###
        ##########################
        try:
            logger.info('Trying Action ID: {0}, "{1}": '
                '{2}'.format(idx, action, actions[idx]['description'])
            )
            process_action(client, actions[idx], **kwargs)
        except Exception as e:
            if isinstance(e, NoIndices) or isinstance(e, NoSnapshots):
                if ignore_empty_list:
                    logger.info(
                        'Skipping action "{0}" due to empty list: '
                        '{1}'.format(action, type(e))
                    )
                else:
                    logger.error(
                        'Unable to complete action "{0}".  No actionable items '
                        'in list: {1}'.format(action, type(e))
                    )
                    sys.exit(1)
            else:
                logger.error(
                    'Failed to complete action: {0}.  {1}: '
                    '{2}'.format(action, type(e), e)
                )
                if continue_if_exception:
                    logger.info(
                        'Continuing execution with next action because '
                        '"continue_if_exception" is set to True for action '
                        '{0}'.format(action)
                    )
                else:
                    sys.exit(1)
        logger.info('Action ID: {0}, "{1}" completed.'.format(idx, action))
    logger.info('Job completed.')
コード例 #5
0
ファイル: object_class.py プロジェクト: untergeek/curator
 def get_list_object(self):
     if self.action in snapshot_actions() or self.action == 'show_snapshots':
         self.list_object = SnapshotList(self.client, repository=self.repository)
     else:
         self.list_object = IndexList(self.client)
コード例 #6
0
ファイル: cli.py プロジェクト: tvernum/curator
def run(config, action_file, dry_run=False):
    """
    Actually run.
    """
    client_args = process_config(config)
    logger = logging.getLogger(__name__)
    logger.debug('Client and logging options validated.')

    # Extract this and save it for later, in case there's no timeout_override.
    default_timeout = client_args.pop('timeout')
    logger.debug('default_timeout = {0}'.format(default_timeout))
    #########################################
    ### Start working on the actions here ###
    #########################################
    logger.debug('action_file: {0}'.format(action_file))
    action_config = get_yaml(action_file)
    logger.debug('action_config: {0}'.format(password_filter(action_config)))
    action_dict = validate_actions(action_config)
    actions = action_dict['actions']
    logger.debug('Full list of actions: {0}'.format(password_filter(actions)))
    action_keys = sorted(list(actions.keys()))
    for idx in action_keys:
        action = actions[idx]['action']
        action_disabled = actions[idx]['options'].pop('disable_action')
        logger.debug('action_disabled = {0}'.format(action_disabled))
        continue_if_exception = (
            actions[idx]['options'].pop('continue_if_exception'))
        logger.debug(
            'continue_if_exception = {0}'.format(continue_if_exception))
        timeout_override = actions[idx]['options'].pop('timeout_override')
        logger.debug('timeout_override = {0}'.format(timeout_override))
        ignore_empty_list = actions[idx]['options'].pop('ignore_empty_list')
        logger.debug('ignore_empty_list = {0}'.format(ignore_empty_list))
        allow_ilm = actions[idx]['options'].pop('allow_ilm_indices')
        logger.debug('allow_ilm_indices = {0}'.format(allow_ilm))

        ### Skip to next action if 'disabled'
        if action_disabled:
            logger.info(
                'Action ID: {0}: "{1}" not performed because "disable_action" '
                'is set to True'.format(idx, action))
            continue
        else:
            logger.info('Preparing Action ID: {0}, "{1}"'.format(idx, action))
        # Override the timeout, if specified, otherwise use the default.
        if isinstance(timeout_override, int):
            client_args['timeout'] = timeout_override
        else:
            client_args['timeout'] = default_timeout

        # Set up action kwargs
        kwargs = {}
        kwargs['master_timeout'] = (client_args['timeout']
                                    if client_args['timeout'] <= 300 else 300)
        kwargs['dry_run'] = dry_run

        # Create a client object for each action...
        logger.info('Creating client object and testing connection')
        try:
            client = get_client(**client_args)
        except (ClientException, ConfigurationError):
            sys.exit(1)

        ### Filter ILM indices unless expressly permitted
        if allow_ilm:
            logger.warning('allow_ilm_indices: true')
            logger.warning(
                'Permitting operation on indices with an ILM policy')
        if not allow_ilm and action not in settings.snapshot_actions():
            if actions[idx]['action'] == 'rollover':
                alias = actions[idx]['options']['name']
                write_index = get_write_index(client, alias)
                try:
                    idx_settings = client.indices.get_settings(
                        index=write_index)
                    if 'name' in idx_settings[write_index]['settings'][
                            'index']['lifecycle']:
                        logger.info(
                            'Alias {0} is associated with ILM policy.'.format(
                                alias))
                        logger.info(
                            'Skipping action {0} because allow_ilm_indices is false.'
                            .format(idx))
                        continue
                except KeyError:
                    logger.debug(
                        'No ILM policies associated with {0}'.format(alias))
            elif 'filters' in actions[idx]:
                actions[idx]['filters'].append({'filtertype': 'ilm'})
            else:
                actions[idx]['filters'] = [{'filtertype': 'ilm'}]
        ##########################
        ### Process the action ###
        ##########################
        try:
            logger.info('Trying Action ID: {0}, "{1}": '
                        '{2}'.format(idx, action, actions[idx]['description']))
            process_action(client, actions[idx], **kwargs)
        except Exception as e:
            if isinstance(e, NoIndices) or isinstance(e, NoSnapshots):
                if ignore_empty_list:
                    logger.info('Skipping action "{0}" due to empty list: '
                                '{1}'.format(action, type(e)))
                else:
                    logger.error(
                        'Unable to complete action "{0}".  No actionable items '
                        'in list: {1}'.format(action, type(e)))
                    sys.exit(1)
            else:
                logger.error('Failed to complete action: {0}.  {1}: '
                             '{2}'.format(action, type(e), e))
                if continue_if_exception:
                    logger.info(
                        'Continuing execution with next action because '
                        '"continue_if_exception" is set to True for action '
                        '{0}'.format(action))
                else:
                    sys.exit(1)
        logger.info('Action ID: {0}, "{1}" completed.'.format(idx, action))
    logger.info('Job completed.')