-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
90 lines (70 loc) · 2.97 KB
/
generate.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
#!/usr/bin/env python3
import glob
import logging
import os
import re
from ruamel.yaml import YAML
yaml = YAML()
yaml.indent(sequence=4, offset=2)
level = logging.INFO
logging.basicConfig(
format="%(asctime)s - %(message)s", level=level, datefmt="%Y-%m-%d %H:%M:%S"
)
ANSIBLE_DIRECTORIES = ["/ceph-ansible", "/kolla-ansible", "/osism-ansible"]
mapping1 = {}
mapping2 = {}
for ansible_directory in ANSIBLE_DIRECTORIES:
logging.info(f"Analyzing {ansible_directory}")
for p in [x[0] for x in os.walk(ansible_directory, followlinks=True)]:
b = os.path.basename(p)
if b in ["defaults"]:
# skip integration tests of the ansible community collections
if "tests/integration" in p:
continue
logging.info(f"Found {b} in {p}")
for f in [
x for x in glob.iglob(p + "**/**", recursive=True) if os.path.isfile(x)
]:
# skip integration tests of the ansible community collections
if "tests/integration" in f:
continue
if "collections/ansible_collections" in f:
pattern = ".*/collections/ansible_collections/(.*)/(.*)/roles/(.*)/defaults"
match = re.search(pattern, f)
rolename = f"{match.group(1)}.{match.group(2)}.{match.group(3)}"
elif "galaxy/roles/" in f:
pattern = ".*/galaxy/roles/(.*)/defaults"
match = re.search(pattern, f)
rolename = f"{match.group(1)}"
elif "galaxy/" in f:
pattern = "galaxy/(.*)/defaults"
match = re.search(pattern, f)
rolename = f"{match.group(1)}"
else:
pattern = "roles/(.*)/defaults"
match = re.search(pattern, f)
if "ceph" in ansible_directory:
rolename = f"ceph.{match.group(1)}"
elif "kolla" in ansible_directory:
rolename = f"kolla.{match.group(1)}"
else:
rolename = f"{match.group(1)}"
if rolename in mapping1:
continue
logging.info(f"Analyzing {rolename}")
mapping1[rolename] = []
with open(f, "r") as fp:
d = yaml.load(fp)
try:
for parameter in d.keys():
logging.info(f"Found parameter {parameter} in {rolename}")
mapping1[rolename].append(parameter)
if parameter not in mapping2:
mapping2[parameter] = []
mapping2[parameter].append(rolename)
except: # noqa
pass
with open("/output/mapping1.yml", "w+") as fp:
yaml.dump(mapping1, fp)
with open("/output/mapping2.yml", "w+") as fp:
yaml.dump(mapping2, fp)