summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2020-12-27 20:11:26 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2020-12-27 20:11:26 +0100
commit7800d2086131ae698f859f0797a5670cace48213 (patch)
treefc05ff1a03f82325525d65263ffca3b551a7db12
parent1dcf198c10c554ec43fd762d61f151fb8b04df80 (diff)
downloadrules-sandbox-7800d2086131ae698f859f0797a5670cace48213.tar.gz
rules-sandbox-7800d2086131ae698f859f0797a5670cace48213.tar.bz2
rules-sandbox-7800d2086131ae698f859f0797a5670cace48213.tar.xz
rules-sandbox-7800d2086131ae698f859f0797a5670cace48213.zip
Dumping to yaml files.
-rw-r--r--Makefile8
-rw-r--r--main.py48
-rw-r--r--out/phase-2/dba-cluster/0.yaml2
-rw-r--r--out/phase-2/dba-container/0.yaml8
-rw-r--r--out/phase-2/dba-container/1.yaml8
-rw-r--r--out/phase-2/dba-container/2.yaml8
-rw-r--r--out/phase-2/dba-container/3.yaml10
-rw-r--r--out/phase-2/dba-container/4.yaml10
-rw-r--r--out/phase-2/dba-container/5.yaml8
-rw-r--r--requirements.txt1
10 files changed, 111 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..97a5e0b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+all: env/.cookie
+
+env:
+ virtualenv -p python3 env
+
+env/.cookie: env requirements.txt
+ env/bin/pip install -r requirements.txt
+ touch $@
diff --git a/main.py b/main.py
index 60164f2..445ab5a 100644
--- a/main.py
+++ b/main.py
@@ -1,5 +1,8 @@
from durable.engine import MessageObservedException
from durable.lang import *
+import os
+import os.path
+import yaml
class VimScore:
@staticmethod
@@ -169,3 +172,48 @@ print("PHASE 2")
for f in [f for f in get_facts("my-rules") 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 fs:
+ path = os.path.join(typedir, str(i) + ".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-2/dba-cluster/0.yaml b/out/phase-2/dba-cluster/0.yaml
new file mode 100644
index 0000000..1eedbaa
--- /dev/null
+++ b/out/phase-2/dba-cluster/0.yaml
@@ -0,0 +1,2 @@
+name: vimscore-production
+type: dba-cluster
diff --git a/out/phase-2/dba-container/0.yaml b/out/phase-2/dba-container/0.yaml
new file mode 100644
index 0000000..60dba7a
--- /dev/null
+++ b/out/phase-2/dba-container/0.yaml
@@ -0,0 +1,8 @@
+cluster: vimscore-production
+image: mongodb
+machineRole: db
+name: mdb
+ports_classified: true
+public_ports: false
+tag: '3.2'
+type: dba-container
diff --git a/out/phase-2/dba-container/1.yaml b/out/phase-2/dba-container/1.yaml
new file mode 100644
index 0000000..5fa9794
--- /dev/null
+++ b/out/phase-2/dba-container/1.yaml
@@ -0,0 +1,8 @@
+cluster: vimscore-production
+image: 4tune-api
+machineRole: app
+name: 4tune-api
+ports_classified: true
+public_ports: false
+tag: master
+type: dba-container
diff --git a/out/phase-2/dba-container/2.yaml b/out/phase-2/dba-container/2.yaml
new file mode 100644
index 0000000..68c3906
--- /dev/null
+++ b/out/phase-2/dba-container/2.yaml
@@ -0,0 +1,8 @@
+cluster: vimscore-production
+image: 4tune-web
+machineRole: app
+name: 4tune-web
+ports_classified: true
+public_ports: false
+tag: master
+type: dba-container
diff --git a/out/phase-2/dba-container/3.yaml b/out/phase-2/dba-container/3.yaml
new file mode 100644
index 0000000..a883361
--- /dev/null
+++ b/out/phase-2/dba-container/3.yaml
@@ -0,0 +1,10 @@
+cluster: vimscore-production
+image: statera-console
+machineRole: app
+name: statera-console
+ports:
+- 80
+ports_classified: true
+public_ports: true
+tag: master
+type: dba-container
diff --git a/out/phase-2/dba-container/4.yaml b/out/phase-2/dba-container/4.yaml
new file mode 100644
index 0000000..d4555f9
--- /dev/null
+++ b/out/phase-2/dba-container/4.yaml
@@ -0,0 +1,10 @@
+cluster: vimscore-production
+image: statera
+machineRole: app
+name: statera
+ports:
+- 8090
+ports_classified: true
+public_ports: true
+tag: master
+type: dba-container
diff --git a/out/phase-2/dba-container/5.yaml b/out/phase-2/dba-container/5.yaml
new file mode 100644
index 0000000..8f82989
--- /dev/null
+++ b/out/phase-2/dba-container/5.yaml
@@ -0,0 +1,8 @@
+cluster: vimscore-production
+image: postgresql
+machineRole: db
+name: pdb
+ports_classified: true
+public_ports: false
+tag: '13'
+type: dba-container
diff --git a/requirements.txt b/requirements.txt
index a366f15..c12f7c8 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +1,2 @@
durable_rules==2.0.28
+pyyaml==5.3.1