-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathabc_tylstore.py
115 lines (93 loc) · 3.09 KB
/
abc_tylstore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import abc
from CONSTS import C
__version__ = '0.1.6'
class TYLHelpers(object):
@classmethod
def get_hostnames_from_tfstate(cls, json_obj):
if not json_obj:
return []
import json
from jsonpath import jsonpath
if isinstance(json_obj, str):
json_obj = json.loads(json_obj)
path = '$.modules[*].resources.[?(@.type in ["%s"])].type' % '", "'.join(C.HELPER_HOSTNAME_QUERY_MAP.keys())
resource_types = set(jsonpath(json_obj, path) or [])
host_list = []
for resource_type in resource_types:
host_list += jsonpath(json_obj, C.HELPER_HOSTNAME_QUERY_MAP[resource_type])
return host_list
class TYLPersistent(object):
__metaclass__ = abc.ABCMeta
_lock_state_ = C.LOCK_STATE_UNLOCKED
@abc.abstractmethod
def set_locked(self, state_obj, raw=''):
"""
:param state_obj: Object (from json) with the lock ID and details of who made the lock.
:param raw: The raw json text
:return: True on successful lock, False if something prevented the lock from happening.
"""
pass
@abc.abstractmethod
def set_unlocked(self, state_obj, raw=''):
"""
:param state_obj: Object (from json) with the lock ID and details of who made the lock.
:param raw: The raw json text
"""
pass
@abc.abstractmethod
def get_lock_state(self):
"""
:return: The request/JSON string provided by terraform of the current lock, None if there is no lock.
"""
pass
@abc.abstractmethod
def store_tfstate(self, tfstate_obj, raw=''):
"""
:param tfstate_obj: JSON string of the current terraform.tfstate file.
:param raw: The raw json text
:return:
"""
pass
@abc.abstractmethod
def get_tfstate(self):
"""
:return: JSON string of the current terraform.tfstate file.
"""
pass
def backend_status(self):
"""
:return: Health and status information in a JSON compatible format.
"""
return None
class TYLNonpersistent(object):
__metaclass__ = abc.ABCMeta
_logged_errors_ = 0
_recent_error_ = ''
@abc.abstractmethod
def on_locked(self, state_obj, raw=''):
"""
:param state_obj: Object (from json) with the lock ID and details of who made the lock.
:param raw: The raw json text
:return: None
"""
pass
@abc.abstractmethod
def on_unlocked(self, state_obj, raw=''):
"""
:param state_obj: Object (from json) with the lock ID and details of who made the lock.
:param raw: The raw json text
"""
pass
@abc.abstractmethod
def process_tfstate(self, tfstate_obj, raw=''):
"""
:param tfstate_obj: JSON string of the current terraform.tfstate file.
:param raw: The raw json text
:return:
"""
pass
def post_processor_status(self):
"""
:return: Health and status object in a JSON compatible format.
"""
return None