summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/main.py b/main.py
index 445ab5a..b628966 100644
--- a/main.py
+++ b/main.py
@@ -44,12 +44,18 @@ class VsOperations:
class DockerBasedApplications:
@staticmethod
- def cluster(name: str):
- return {"type": "dba-cluster", "name": name}
+ def cluster(key: str):
+ return {"type": "dba-cluster", "key": key}
@staticmethod
def container(cluster: str, machineRole: str, name: str, image: str, tag: str):
- return {"type": "dba-container", "cluster": cluster, "machineRole": machineRole, "name": name, "image": image, "tag": tag}
+ return {"type": "dba-container",
+ "key": f"{cluster}/{name}",
+ "cluster": cluster,
+ "machineRole": machineRole,
+ "name": name,
+ "image": image,
+ "tag": tag}
dba = DockerBasedApplications
@@ -82,7 +88,7 @@ with ruleset("my-rules"):
# The none() part doesn't work as is, but it is worked around with the try/except block.
@when_all(
(c.container << m.type == "dba-container"),
- none((m.type == "dba-cluster") & (m.name == c.container.cluster)),
+ none((m.type == "dba-cluster") & (m.key == c.container.cluster)),
)
def dbCluster(c):
cluster = c.container.cluster
@@ -94,7 +100,7 @@ with ruleset("my-rules"):
# @when_all(pri(40),
# (c.container << m.type == "dba-container"),
-# (c.cluster << (m.type == "dba-cluster") & (m.name == c.container.cluster)),
+# (c.cluster << (m.type == "dba-cluster") & (m.key == c.container.cluster)),
# )
# def dbCluster(c):
# print("dba-cluster: CATCH ALL")
@@ -117,11 +123,11 @@ if True:
print("dba-clusters:")
for f in [f for f in get_facts("my-rules") if f["type"] == "dba-cluster"]:
- cluster_name = f["name"]
+ cluster_name = f["key"]
- del f["name"]
+ del f["key"]
print(f" cluster:")
- print(f" name: {cluster_name}")
+ print(f" key: {cluster_name}")
print(f" json: {f}")
print(" dba-containers:")
@@ -156,7 +162,7 @@ with ruleset("phase-2"):
@when_all(pri(50),
c.cluster << (m.type == "dba-cluster"),
-# c.container << ((m.type == "dba-container") & (m.cluster == c.cluster.name) & m.ports.anyItem(item > 0))
+# c.container << ((m.type == "dba-container") & (m.cluster == c.cluster.key) & m.ports.anyItem(item > 0))
c.container << ((m.type == "dba-container") & +m.ports_classified & (m.public_ports > 0))
)
def container(c):
@@ -209,11 +215,12 @@ def write_facts(ruleset: set):
fs.append(f)
i = 0
- for fact in fs:
- path = os.path.join(typedir, str(i) + ".yaml")
+ for fact in sorted(fs, key=lambda f: f["key"]):
+ key = fact["key"]
+ path = os.path.join(typedir, f"{key.replace('/', '_')}.yaml")
with open(path, "w") as f:
s = yaml.dump(fact)
- f.write(s)
+ f.write(s)
i = i + 1
write_facts("phase-2")