-
Notifications
You must be signed in to change notification settings - Fork 65
/
Factory.py
94 lines (76 loc) · 2.71 KB
/
Factory.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
from abc import ABCMeta, abstractmethod
import time
class Platform(metaclass=ABCMeta):
@abstractmethod
def stop_systems(self):
raise NotImplementedError('Please implement the method <stop_systems>!')
@abstractmethod
def start_systems(self):
raise NotImplementedError('Please implement the method <start_systems>!')
@abstractmethod
def heath_check_systems(self):
raise NotImplementedError('Please implement the method <heath_check_systems>!')
class WebServer(Platform):
__nodes = ['web_node_a','web_node_b','web_node_c']
def stop_systems(self):
for system in self.__nodes:
print("Stopping system: {}".format(system))
time.sleep(0.5)
def start_systems(self):
for system in self.__nodes:
print("Starting system: {}".format(system))
time.sleep(0.5)
def heath_check_systems(self):
for system in self.__nodes:
print("Checking system: {}".format(system))
time.sleep(0.5)
class Firewall(Platform):
__nodes = ['fw_node_a','fw_node_b','fw_node_c']
def stop_systems(self):
for system in self.__nodes:
print("Stopping system: {}".format(system))
time.sleep(0.5)
def start_systems(self):
for system in self.__nodes:
print("Starting system: {}".format(system))
time.sleep(0.5)
def heath_check_systems(self):
for system in self.__nodes:
print("Checking system: {}".format(system))
time.sleep(0.5)
class AppServer(Platform):
__nodes = ['jvm_node_a','jvm_node_b','jvm_node_c']
def stop_systems(self):
for system in self.__nodes:
print("Stopping system: {}".format(system))
time.sleep(0.5)
def start_systems(self):
for system in self.__nodes:
print("Starting system: {}".format(system))
time.sleep(0.5)
def heath_check_systems(self):
for system in self.__nodes:
print("Checking system: {}".format(system))
time.sleep(0.5)
class PatchingFactory(object):
def stop_all(self, platform_object):
print('Stopping platfrom: {}'.format(platform_object))
return eval(platform_object)().stop_systems()
def start_all(self, platform_object):
print('Starting platfrom: {}'.format(platform_object))
return eval(platform_object)().start_systems()
def hc_all(self, platform_object):
print('Checking platfrom: {}'.format(platform_object))
return eval(platform_object)().heath_check_systems()
def make_magic_happen(self,platform_object):
self.hc_all(platform_object)
self.stop_all(platform_object)
self.start_all(platform_object)
self.hc_all(platform_object)
PF = PatchingFactory()
PFORMS = ['WebServer','AppServer','Firewall']
for platform_to_stop in PFORMS:
PF.hc_all(platform_to_stop)
PF.stop_all(platform_to_stop)
PF.start_all(platform_to_stop)
PF.hc_all(platform_to_stop)