summaryrefslogtreecommitdiff
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
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
-rw-r--r--.gitignore1
-rw-r--r--main.py71
-rw-r--r--out/phase-1/dba-cluster/vimscore-production.yaml2
-rw-r--r--out/phase-1/dba-container/vimscore-production_4tune-api.yaml7
-rw-r--r--out/phase-1/dba-container/vimscore-production_4tune-web.yaml7
-rw-r--r--out/phase-1/dba-container/vimscore-production_mdb.yaml7
-rw-r--r--out/phase-1/dba-container/vimscore-production_pdb.yaml7
-rw-r--r--out/phase-1/dba-container/vimscore-production_statera-console.yaml9
-rw-r--r--out/phase-1/dba-container/vimscore-production_statera.yaml9
-rw-r--r--out/phase-1/vimscore-application/production.yaml4
-rw-r--r--utils.py51
11 files changed, 118 insertions, 57 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bee8a64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+__pycache__
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")
diff --git a/out/phase-1/dba-cluster/vimscore-production.yaml b/out/phase-1/dba-cluster/vimscore-production.yaml
new file mode 100644
index 0000000..4390af6
--- /dev/null
+++ b/out/phase-1/dba-cluster/vimscore-production.yaml
@@ -0,0 +1,2 @@
+key: vimscore-production
+type: dba-cluster
diff --git a/out/phase-1/dba-container/vimscore-production_4tune-api.yaml b/out/phase-1/dba-container/vimscore-production_4tune-api.yaml
new file mode 100644
index 0000000..3bb27ff
--- /dev/null
+++ b/out/phase-1/dba-container/vimscore-production_4tune-api.yaml
@@ -0,0 +1,7 @@
+cluster: vimscore-production
+image: 4tune-api
+key: vimscore-production/4tune-api
+machineRole: app
+name: 4tune-api
+tag: master
+type: dba-container
diff --git a/out/phase-1/dba-container/vimscore-production_4tune-web.yaml b/out/phase-1/dba-container/vimscore-production_4tune-web.yaml
new file mode 100644
index 0000000..2c7591f
--- /dev/null
+++ b/out/phase-1/dba-container/vimscore-production_4tune-web.yaml
@@ -0,0 +1,7 @@
+cluster: vimscore-production
+image: 4tune-web
+key: vimscore-production/4tune-web
+machineRole: app
+name: 4tune-web
+tag: master
+type: dba-container
diff --git a/out/phase-1/dba-container/vimscore-production_mdb.yaml b/out/phase-1/dba-container/vimscore-production_mdb.yaml
new file mode 100644
index 0000000..56feafe
--- /dev/null
+++ b/out/phase-1/dba-container/vimscore-production_mdb.yaml
@@ -0,0 +1,7 @@
+cluster: vimscore-production
+image: mongodb
+key: vimscore-production/mdb
+machineRole: db
+name: mdb
+tag: '3.2'
+type: dba-container
diff --git a/out/phase-1/dba-container/vimscore-production_pdb.yaml b/out/phase-1/dba-container/vimscore-production_pdb.yaml
new file mode 100644
index 0000000..6d29602
--- /dev/null
+++ b/out/phase-1/dba-container/vimscore-production_pdb.yaml
@@ -0,0 +1,7 @@
+cluster: vimscore-production
+image: postgresql
+key: vimscore-production/pdb
+machineRole: db
+name: pdb
+tag: '13'
+type: dba-container
diff --git a/out/phase-1/dba-container/vimscore-production_statera-console.yaml b/out/phase-1/dba-container/vimscore-production_statera-console.yaml
new file mode 100644
index 0000000..3bece40
--- /dev/null
+++ b/out/phase-1/dba-container/vimscore-production_statera-console.yaml
@@ -0,0 +1,9 @@
+cluster: vimscore-production
+image: statera-console
+key: vimscore-production/statera-console
+machineRole: app
+name: statera-console
+ports:
+- 80
+tag: master
+type: dba-container
diff --git a/out/phase-1/dba-container/vimscore-production_statera.yaml b/out/phase-1/dba-container/vimscore-production_statera.yaml
new file mode 100644
index 0000000..fb2d5d4
--- /dev/null
+++ b/out/phase-1/dba-container/vimscore-production_statera.yaml
@@ -0,0 +1,9 @@
+cluster: vimscore-production
+image: statera
+key: vimscore-production/statera
+machineRole: app
+name: statera
+ports:
+- 8090
+tag: master
+type: dba-container
diff --git a/out/phase-1/vimscore-application/production.yaml b/out/phase-1/vimscore-application/production.yaml
new file mode 100644
index 0000000..b9217d7
--- /dev/null
+++ b/out/phase-1/vimscore-application/production.yaml
@@ -0,0 +1,4 @@
+env: production
+key: production
+tag: master
+type: vimscore-application
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..06c6500
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,51 @@
+import os
+import os.path
+import yaml
+from durable.lang import *
+
+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
+ try:
+ del f["sid"]
+ except KeyError:
+ pass
+ 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