From 9f3e8bce09100a539ff3a0c67da1db028ce51f73 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 27 Dec 2020 20:20:50 +0100 Subject: Adding keys to facts --- main.py | 31 +++++++++++++--------- out/phase-2/dba-cluster/0.yaml | 2 -- out/phase-2/dba-cluster/vimscore-production.yaml | 2 ++ out/phase-2/dba-container/0.yaml | 8 ------ out/phase-2/dba-container/1.yaml | 8 ------ out/phase-2/dba-container/2.yaml | 8 ------ out/phase-2/dba-container/3.yaml | 10 ------- out/phase-2/dba-container/4.yaml | 10 ------- out/phase-2/dba-container/5.yaml | 8 ------ .../vimscore-production_4tune-api.yaml | 9 +++++++ .../vimscore-production_4tune-web.yaml | 9 +++++++ .../dba-container/vimscore-production_mdb.yaml | 9 +++++++ .../dba-container/vimscore-production_pdb.yaml | 9 +++++++ .../vimscore-production_statera-console.yaml | 11 ++++++++ .../dba-container/vimscore-production_statera.yaml | 11 ++++++++ 15 files changed, 79 insertions(+), 66 deletions(-) delete mode 100644 out/phase-2/dba-cluster/0.yaml create mode 100644 out/phase-2/dba-cluster/vimscore-production.yaml delete mode 100644 out/phase-2/dba-container/0.yaml delete mode 100644 out/phase-2/dba-container/1.yaml delete mode 100644 out/phase-2/dba-container/2.yaml delete mode 100644 out/phase-2/dba-container/3.yaml delete mode 100644 out/phase-2/dba-container/4.yaml delete mode 100644 out/phase-2/dba-container/5.yaml create mode 100644 out/phase-2/dba-container/vimscore-production_4tune-api.yaml create mode 100644 out/phase-2/dba-container/vimscore-production_4tune-web.yaml create mode 100644 out/phase-2/dba-container/vimscore-production_mdb.yaml create mode 100644 out/phase-2/dba-container/vimscore-production_pdb.yaml create mode 100644 out/phase-2/dba-container/vimscore-production_statera-console.yaml create mode 100644 out/phase-2/dba-container/vimscore-production_statera.yaml 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") diff --git a/out/phase-2/dba-cluster/0.yaml b/out/phase-2/dba-cluster/0.yaml deleted file mode 100644 index 1eedbaa..0000000 --- a/out/phase-2/dba-cluster/0.yaml +++ /dev/null @@ -1,2 +0,0 @@ -name: vimscore-production -type: dba-cluster diff --git a/out/phase-2/dba-cluster/vimscore-production.yaml b/out/phase-2/dba-cluster/vimscore-production.yaml new file mode 100644 index 0000000..4390af6 --- /dev/null +++ b/out/phase-2/dba-cluster/vimscore-production.yaml @@ -0,0 +1,2 @@ +key: vimscore-production +type: dba-cluster diff --git a/out/phase-2/dba-container/0.yaml b/out/phase-2/dba-container/0.yaml deleted file mode 100644 index 60dba7a..0000000 --- a/out/phase-2/dba-container/0.yaml +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 5fa9794..0000000 --- a/out/phase-2/dba-container/1.yaml +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 68c3906..0000000 --- a/out/phase-2/dba-container/2.yaml +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index a883361..0000000 --- a/out/phase-2/dba-container/3.yaml +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index d4555f9..0000000 --- a/out/phase-2/dba-container/4.yaml +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 8f82989..0000000 --- a/out/phase-2/dba-container/5.yaml +++ /dev/null @@ -1,8 +0,0 @@ -cluster: vimscore-production -image: postgresql -machineRole: db -name: pdb -ports_classified: true -public_ports: false -tag: '13' -type: dba-container diff --git a/out/phase-2/dba-container/vimscore-production_4tune-api.yaml b/out/phase-2/dba-container/vimscore-production_4tune-api.yaml new file mode 100644 index 0000000..5e9fd63 --- /dev/null +++ b/out/phase-2/dba-container/vimscore-production_4tune-api.yaml @@ -0,0 +1,9 @@ +cluster: vimscore-production +image: 4tune-api +key: vimscore-production/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/vimscore-production_4tune-web.yaml b/out/phase-2/dba-container/vimscore-production_4tune-web.yaml new file mode 100644 index 0000000..c5b87c5 --- /dev/null +++ b/out/phase-2/dba-container/vimscore-production_4tune-web.yaml @@ -0,0 +1,9 @@ +cluster: vimscore-production +image: 4tune-web +key: vimscore-production/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/vimscore-production_mdb.yaml b/out/phase-2/dba-container/vimscore-production_mdb.yaml new file mode 100644 index 0000000..48a760b --- /dev/null +++ b/out/phase-2/dba-container/vimscore-production_mdb.yaml @@ -0,0 +1,9 @@ +cluster: vimscore-production +image: mongodb +key: vimscore-production/mdb +machineRole: db +name: mdb +ports_classified: true +public_ports: false +tag: '3.2' +type: dba-container diff --git a/out/phase-2/dba-container/vimscore-production_pdb.yaml b/out/phase-2/dba-container/vimscore-production_pdb.yaml new file mode 100644 index 0000000..4f7d732 --- /dev/null +++ b/out/phase-2/dba-container/vimscore-production_pdb.yaml @@ -0,0 +1,9 @@ +cluster: vimscore-production +image: postgresql +key: vimscore-production/pdb +machineRole: db +name: pdb +ports_classified: true +public_ports: false +tag: '13' +type: dba-container diff --git a/out/phase-2/dba-container/vimscore-production_statera-console.yaml b/out/phase-2/dba-container/vimscore-production_statera-console.yaml new file mode 100644 index 0000000..dda5ea6 --- /dev/null +++ b/out/phase-2/dba-container/vimscore-production_statera-console.yaml @@ -0,0 +1,11 @@ +cluster: vimscore-production +image: statera-console +key: vimscore-production/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/vimscore-production_statera.yaml b/out/phase-2/dba-container/vimscore-production_statera.yaml new file mode 100644 index 0000000..dcee4fa --- /dev/null +++ b/out/phase-2/dba-container/vimscore-production_statera.yaml @@ -0,0 +1,11 @@ +cluster: vimscore-production +image: statera +key: vimscore-production/statera +machineRole: app +name: statera +ports: +- 8090 +ports_classified: true +public_ports: true +tag: master +type: dba-container -- cgit v1.2.3