Coverage for /Users/buh/.pyenv/versions/3.12.9/envs/es-testbed/lib/python3.12/site-packages/es_testbed/mgrs/snapshot.py: 100%
27 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-31 12:31 -0600
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-31 12:31 -0600
1"""Snapshot Entity Manager Class"""
3import typing as t
4import logging
5import tiered_debug as debug
6from es_testbed.helpers.es_api import do_snap
7from es_testbed.mgrs.entity import EntityMgr
9if t.TYPE_CHECKING:
10 from elasticsearch8 import Elasticsearch
11 from dotmap import DotMap
13logger = logging.getLogger(__name__)
16class SnapshotMgr(EntityMgr):
17 """Snapshot Entity Manager Class"""
19 kind = 'snapshot'
20 listname = 'snapshots'
22 def __init__(
23 self,
24 client: t.Union['Elasticsearch', None] = None,
25 plan: t.Union['DotMap', None] = None,
26 ):
27 debug.lv2('Initializing SnapshotMgr object...')
28 super().__init__(client=client, plan=plan)
29 debug.lv3('SnapshotMgr object initialized')
31 def add(self, index: str, tier: str) -> None:
32 """Perform a snapshot and add it to the entity_list"""
33 debug.lv2('Starting method...')
34 msg = f'Creating snapshot of index {index} and mounting in the {tier} tier...'
35 debug.lv3(msg)
36 do_snap(self.client, self.plan.repository, self.name, index, tier=tier)
37 self.appender(self.name)
38 debug.lv3(f'Successfully created snapshot "{self.last}"')
39 debug.lv3('Exiting method')
41 def add_existing(self, name: str) -> None:
42 """Add a snapshot that's already been created, e.g. by ILM promotion"""
43 debug.lv2('Starting method...')
44 debug.lv3(f'Adding snapshot {name} to list...')
45 self.appender(name)
46 debug.lv3('Exiting method')