def mount_index()

in src/es_pii_tool/helpers/elastic_api.py [0:0]


def mount_index(var: 'DotMap') -> None:
    """Mount index as a searchable snapshot

    :param var: A collection of variables from
        :py:attr:`~.es_pii_tool.redacters.snapshot.RedactSnapshot.var`

    :type var: DotMap
    """
    response = {}
    msg = (
        f'Mounting {var.redaction_target} renamed as {var.mount_name} '
        f'from repository: {var.repository}, snapshot: {var.new_snap_name} '
        f'with storage={var.storage}'
    )
    logger.debug(msg)
    while index_exists(var.client, var.mount_name):
        logger.warning('Index %s exists. Deleting before remounting', var.mount_name)
        delete_index(var.client, var.mount_name)
        time.sleep(3.0)
    try:
        response = dict(
            var.client.searchable_snapshots.mount(
                repository=var.repository,
                snapshot=var.new_snap_name,
                index=var.redaction_target,
                renamed_index=var.mount_name,
                storage=var.storage,
            )
        )
    except (ApiError, NotFoundError, TransportError, BadRequestError) as err:
        logger.error("Attempt to mount index '%s' failed: %s", var.mount_name, err)
        logger.debug(response)
        raise BadClientResult('Error when mount index attempted', err)
    logger.info('Ensuring searchable snapshot mount is in "green" health state...')
    pause, timeout = timing('health')
    logger.debug(f'ENV pause = {pause}, timeout = {timeout}')
    try:
        es_waiter(
            var.client,
            Health,
            check_type='status',
            indices=var.mount_name,
            pause=pause,
            timeout=timeout,
        )
    except BadClientResult as exc:
        logger.error('Exception: %s', exc)
        raise FatalError('Failed to mount index from snapshot', exc)
    logger.info("Index '%s' mounted from snapshot succesfully", var.mount_name)