summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2020-12-27 20:28:00 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2020-12-27 20:28:00 +0100
commit64c0fb097a6c9482460f1bebbcb393b617956ca3 (patch)
tree83f79d36d516a45f630ec14316c9b324369024ac /main.py
parent9f3e8bce09100a539ff3a0c67da1db028ce51f73 (diff)
downloadrules-sandbox-64c0fb097a6c9482460f1bebbcb393b617956ca3.tar.gz
rules-sandbox-64c0fb097a6c9482460f1bebbcb393b617956ca3.tar.bz2
rules-sandbox-64c0fb097a6c9482460f1bebbcb393b617956ca3.tar.xz
rules-sandbox-64c0fb097a6c9482460f1bebbcb393b617956ca3.zip
Saving output from first phase too
Diffstat (limited to 'main.py')
-rw-r--r--main.py71
1 files changed, 14 insertions, 57 deletions
diff --git a/main.py b/main.py
index b628966..f64c37e 100644
--- a/main.py
+++ b/main.py
@@ -1,13 +1,12 @@
from durable.engine import MessageObservedException
from durable.lang import *
-import os
-import os.path
-import yaml
+
+from utils import *
class VimScore:
@staticmethod
def make(env: str, tag: str):
- return {"type": "vimscore-application", "env": env, "tag": tag}
+ return {"type": "vimscore-application", "key": env, "env": env, "tag": tag}
@staticmethod
def declare_rules():
@@ -30,7 +29,7 @@ class VimScore:
class VsOperations:
@staticmethod
def make():
- return {"type": "vimscore-ops"}
+ return {"type": "vimscore-ops", "key": "vimscore-ops"}
@staticmethod
def declare_rules():
@@ -59,7 +58,7 @@ class DockerBasedApplications:
dba = DockerBasedApplications
-with ruleset("my-rules"):
+with ruleset("phase-1"):
VimScore.declare_rules()
VsOperations.declare_rules()
@@ -112,17 +111,17 @@ vimscoreCi = VimScore.make("ci", "development")
vimscoreProduction = VimScore.make("production", "master")
vsOps = VsOperations.make()
-#x = assert_fact("my-rules", vimscoreCi); print(f"x: {x}")
-x = assert_fact("my-rules", vimscoreProduction); print(f"x: {x}")
-#x = assert_fact("my-rules", vsOps); print(f"x: {x}")
+#x = assert_fact("phase-1", vimscoreCi); print(f"x: {x}")
+x = assert_fact("phase-1", vimscoreProduction); print(f"x: {x}")
+#x = assert_fact("phase-1", vsOps); print(f"x: {x}")
if True:
print("Facts:")
- for f in get_facts("my-rules"):
+ for f in get_facts("phase-1"):
print(f"fact: {f}")
print("dba-clusters:")
- for f in [f for f in get_facts("my-rules") if f["type"] == "dba-cluster"]:
+ for f in [f for f in get_facts("phase-1") if f["type"] == "dba-cluster"]:
cluster_name = f["key"]
del f["key"]
@@ -131,11 +130,13 @@ if True:
print(f" json: {f}")
print(" dba-containers:")
- for f in [f for f in get_facts("my-rules") if f.get("cluster") == cluster_name and f["type"] == "dba-container"]:
+ for f in [f for f in get_facts("phase-1") if f.get("cluster") == cluster_name and f["type"] == "dba-container"]:
del f["cluster"]
del f["type"]
print(f" container: {f}")
+write_facts("phase-1")
+
with ruleset("phase-2"):
@when_all(+s.exception)
@@ -176,51 +177,7 @@ with ruleset("phase-2"):
print("PHASE 2")
-for f in [f for f in get_facts("my-rules") if f["type"] in ("dba-cluster", "dba-container")]:
+for f in [f for f in get_facts("phase-1") if f["type"] in ("dba-cluster", "dba-container")]:
assert_fact("phase-2", f)
-def write_facts(ruleset: set):
- facts = get_facts(ruleset)
-
- types = set((f.get("type") for f in facts))
-
- print(f"types: {types}")
-
- out_dir = "out"
- if not os.path.exists(out_dir):
- os.mkdir(out_dir)
-
- basedir = os.path.join(out_dir, ruleset)
- if os.path.exists(basedir):
- for f in os.listdir(basedir):
- p = os.path.join(basedir, f)
- if os.path.isdir(p):
- for f2 in os.listdir(p):
- os.remove(os.path.join(p, f2))
- os.rmdir(p)
- else:
- os.remove(p)
- os.rmdir(basedir)
- os.mkdir(basedir)
-
- for t in types:
- typedir = os.path.join(basedir, t)
- os.mkdir(typedir)
-
- fs = []
- for f in facts:
- if f["type"] != t:
- continue
- del f["sid"]
- fs.append(f)
-
- i = 0
- 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)
- i = i + 1
-
write_facts("phase-2")