Coverage for /Users/buh/.pyenv/versions/3.12.9/envs/es-testbed/lib/python3.12/site-packages/es_testbed/mgrs/snapshot.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-21 21:08 -0600

1"""Snapshot Entity Manager Class""" 

2 

3import typing as t 

4import logging 

5from ..debug import debug, begin_end 

6from ..es_api import do_snap 

7from .entity import EntityMgr 

8 

9if t.TYPE_CHECKING: 

10 from elasticsearch8 import Elasticsearch 

11 from dotmap import DotMap 

12 

13logger = logging.getLogger(__name__) 

14 

15 

16class SnapshotMgr(EntityMgr): 

17 """Snapshot Entity Manager Class""" 

18 

19 kind = "snapshot" 

20 listname = "snapshots" 

21 

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") 

30 

31 @begin_end() 

32 def add(self, index: str, tier: str) -> None: 

33 """Perform a snapshot and add it to the entity_list""" 

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 

40 @begin_end() 

41 def add_existing(self, name: str) -> None: 

42 """Add a snapshot that's already been created, e.g. by ILM promotion""" 

43 debug.lv3(f"Adding snapshot {name} to list...") 

44 self.appender(name)