Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/mgrs/snapshot.py: 100%
20 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-03 15:56 -0600
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-03 15:56 -0600
1"""Snapshot Entity Manager Class"""
3import typing as t
4import logging
5from es_testbed.helpers.es_api import do_snap
6from es_testbed.mgrs.entity import EntityMgr
8if t.TYPE_CHECKING:
9 from elasticsearch8 import Elasticsearch
10 from dotmap import DotMap
12logger = logging.getLogger(__name__)
15class SnapshotMgr(EntityMgr):
16 """Snapshot Entity Manager Class"""
18 kind = 'snapshot'
19 listname = 'snapshots'
21 def __init__(
22 self,
23 client: t.Union['Elasticsearch', None] = None,
24 plan: t.Union['DotMap', None] = None,
25 ):
26 super().__init__(client=client, plan=plan)
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 logger.info(msg)
32 do_snap(self.client, self.plan.repository, self.name, index, tier=tier)
33 self.appender(self.name)
34 logger.info('Successfully created snapshot "%s"', self.last)
36 def add_existing(self, name: str) -> None:
37 """Add a snapshot that's already been created, e.g. by ILM promotion"""
38 logger.info('Adding snapshot %s to list...', name)
39 self.appender(name)