forked from ispras/vmemperor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
65 lines (57 loc) · 2.1 KB
/
hooks.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
import json
predefined_hooks = {
"Nginx reverse-proxy config": {
"ansible_playbook_file": "ansible/nginx.yml",
"manifest": {
"options": [
{
"legend": "HTTP port on Nginx",
"field": "http_in",
"default_value": "80"
},
{
"legend": "forward to HTTP port on VM",
"field": "http_out",
"default_value": "8080"
},
{
"legend": "HTTPS port on Nginx",
"field": "https_in",
"default_value": "443"
},
{
"legend": "forward to HTTPS port on VM",
"field": "https_out",
"default_value": "443"
},
],
"header": "Nginx reverse-proxy configuration",
"help": "This scenario generates a configuration file to passthrough your HTTP/HTTPS traffic into your virtual machine and puts it on Nginx host. If you don't want it, don't forget to disable checkbox"
}
}
}
def merge_with_dict(other_config_entry):
merged = {hook: False for hook in predefined_hooks}
if other_config_entry:
hooks = json.loads(other_config_entry)
for hook_name, value in hooks.items():
merged[hook_name] = value
return merged
def generate_other_config_entry(hooks):
filtered = {}
for hook_name, value in hooks.items():
if value:
filtered[hook_name] = True
return json.dumps(filtered)
def get_hooks_with_manifest(other_config_entry):
if type(other_config_entry) is str:
hooks = json.loads(other_config_entry)
else:
hooks = other_config_entry
return {hook: predefined_hooks[hook]["manifest"] for hook in hooks}
a = generate_other_config_entry({'Nginx reverse-proxy config': True})
print (a)
b = merge_with_dict(a)
print (b)
c = get_hooks_with_manifest(a)
print (c)