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-08-30 19:06 -0600

1"""Snapshot Entity Manager Class""" 

2 

3import typing as t 

4import logging 

5from es_testbed.helpers.es_api import do_snap 

6from es_testbed.mgrs.entity import EntityMgr 

7 

8if t.TYPE_CHECKING: 

9 from elasticsearch8 import Elasticsearch 

10 from dotmap import DotMap 

11 

12logger = logging.getLogger(__name__) 

13 

14 

15class SnapshotMgr(EntityMgr): 

16 """Snapshot Entity Manager Class""" 

17 

18 kind = 'snapshot' 

19 listname = 'snapshots' 

20 

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) 

27 

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) 

35 

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)