Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/classes/entitymgrs/snapshotmgr.py: 88%
24 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-27 20:59 -0600
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-27 20:59 -0600
1"""Snapshot Entity Manager Class"""
3import typing as t
4from es_testbed.helpers import es_api
5from es_testbed.helpers.utils import getlogger
6from .entitymgr import EntityMgr
8if t.TYPE_CHECKING: 8 ↛ 9line 8 didn't jump to line 9, because the condition on line 8 was never true
9 from elasticsearch8 import Elasticsearch
10 from dotmap import DotMap
12# pylint: disable=missing-docstring
15class SnapshotMgr(EntityMgr):
16 kind = 'snapshot'
17 listname = 'snapshots'
19 def __init__(
20 self,
21 client: t.Union['Elasticsearch', None] = None,
22 plan: t.Union['DotMap', None] = None,
23 autobuild: t.Optional[bool] = False,
24 ):
25 super().__init__(client=client, plan=plan, autobuild=autobuild)
26 self.logger = getlogger('es_testbed.SnapshotMgr')
28 def add(self, index: str, tier: str) -> None:
29 """Perform a snapshot and add it to the entity_list"""
30 msg = f'Creating snapshot of index {index} and mounting in the {tier} tier...'
31 self.logger.info(msg)
32 es_api.do_snap(self.client, self.plan.repository, self.name, index, tier=tier)
33 self.appender(self.name)
34 self.logger.info('Successfully created snapshot "%s"', self.last)
35 self.success = True
37 def add_existing(self, name: str) -> None:
38 """Add a snapshot that's already been created, e.g. by ILM promotion"""
39 self.logger.info('Adding snapshot %s to list...', name)
40 self.appender(name)
41 self.success = True