summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2020-12-30 18:08:48 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2020-12-30 18:08:48 +0100
commitea985dfdb3974f3f22381be01c41dcb06a817831 (patch)
treee00f86ca20ea4ad01dd3938c11434f66393219cc
parent023b447ea78380bdec965db04b3ba3621c4d3a5b (diff)
downloadrules-sandbox-ea985dfdb3974f3f22381be01c41dcb06a817831.tar.gz
rules-sandbox-ea985dfdb3974f3f22381be01c41dcb06a817831.tar.bz2
rules-sandbox-ea985dfdb3974f3f22381be01c41dcb06a817831.tar.xz
rules-sandbox-ea985dfdb3974f3f22381be01c41dcb06a817831.zip
Logging when writing files.
Noticing that the none() stuff to prevent duplicate writing of files doesn't work as expected.
-rw-r--r--py/acme/rai/__main__.py52
-rw-r--r--py/acme/rai/terraform.py1
2 files changed, 33 insertions, 20 deletions
diff --git a/py/acme/rai/__main__.py b/py/acme/rai/__main__.py
index 9319ec5..b2664fa 100644
--- a/py/acme/rai/__main__.py
+++ b/py/acme/rai/__main__.py
@@ -174,19 +174,15 @@ with ruleset("phase-3"):
print(f"ignoring {c.m}")
pass
- @when_all(m.type == "meta")
- def ignoreMeta(c):
- print(f"ignoring 2 {c.m}")
- pass
-
@when_all(
- pri(1000),
+ pri(-1),
(m.type == "terraform-machine"),
none(m.done == "platform/terraform/main.tf"),
)
def mainTf(c):
- print(f"WRITING gen/platform/terraform/main.tf")
- with open(f"gen/platform/terraform/main.tf", "w") as f:
+ path = f"gen/platform/terraform/main.tf"
+ print(f"WRITING {path}")
+ with open(path, "w") as f:
f.write("""
terraform {
required_providers {
@@ -197,25 +193,33 @@ terraform {
}
""".strip())
f.write("\n")
- c.assert_fact({"type": "meta", "done": "platform/terraform/main.tf"})
machines = []
for f in c.get_facts():
if f.get("type") != "terraform-machine":
continue
machines.append(f)
- print(f"machine: {f}")
+# print(f"machine: {f}")
template = j2.get_template("terraform-machine-outputs.j2")
- with open(f"gen/platform/terraform/outputs.tf", "w") as f:
+ path = f"gen/platform/terraform/outputs.tf"
+ print(f"WRITING {path}")
+ with open(path, "w") as f:
s = template.render(**{"machines": machines})
f.write(s.strip())
f.write("\n")
+ try:
+ c.assert_fact({"type": "meta", "done": path})
+ except MessageObservedException:
+ pass
+
@when_all((m.type == "terraform-machine"))
def ansibleMachine(c):
template = j2.get_template("platform-ansible.j2")
- with open(f"gen/platform/ansible/{c.m.key}.yml", "w") as f:
+ path = f"gen/platform/ansible/{c.m.key}.yml"
+ print(f"WRITING {path}")
+ with open(path, "w") as f:
s = template.render(**{"m": c.m})
f.write(s.strip())
f.write("\n")
@@ -223,7 +227,9 @@ terraform {
@when_all((m.type == "terraform-machine"))
def terraformMachine(c):
template = j2.get_template("terraform-machine.j2")
- with open(f"gen/platform/terraform/{c.m.key}.tf", "w") as f:
+ path = f"gen/platform/terraform/{c.m.key}.tf"
+ print(f"WRITING {path}")
+ with open(path, "w") as f:
s = template.render(**{"m": c.m})
f.write(s.strip())
f.write("\n")
@@ -231,25 +237,33 @@ terraform {
@when_all((m.type == "terraform-record-set"))
def terraformRecordSet(c):
template = j2.get_template("terraform-record-set.j2")
- with open(f"gen/dns/{c.m.key}.tf", "w") as f:
+ path = f"gen/dns/{c.m.key}.tf"
+ print(f"WRITING {path}")
+ with open(path, "w") as f:
s = template.render(**{"m": c.m})
f.write(s.strip())
f.write("\n")
@when_all(
- (m.type == "terraform-record-set"),
- none(m.done == "dns/inputs.tf"),
+ pri(-1),
+ c.x << (m.type == "terraform-record-set"),
+ none(m.done == "gen/dns/inputs.tf"),
+# c.x << (m.done == "gen/dns/inputs.tf"),
)
def mainTf(c):
- print("WRITING dns/inputs.tf")
- with open(f"gen/dns/inputs.tf", "w") as f:
+ path = f"gen/dns/inputs.tf"
+ print(f"WRITING {path}")
+ with open(path, "w") as f:
f.write("""
variable "addresses" {
type = map(string)
}
""".strip())
f.write("\n")
- c.assert_fact({"type": "meta", "done": "dns/inputs.tf"})
+ try:
+ c.assert_fact({"type": "meta", "done": path})
+ except MessageObservedException:
+ pass
facts = [f for f in get_facts("phase-1") if f["type"] in ("terraform-record-set", "terraform-machine")]
#for f in facts:
diff --git a/py/acme/rai/terraform.py b/py/acme/rai/terraform.py
index c84a7e1..6feedd1 100644
--- a/py/acme/rai/terraform.py
+++ b/py/acme/rai/terraform.py
@@ -24,7 +24,6 @@ class Terraform:
c.machine << ((m.type == "terraform-machine") & (m.key == c.dns.key)),
)
def onDnsEntry(c):
- print("yooooooooooooooooo")
terraformId = c.dns.fqdn.replace(".", "_")
c.assert_fact(Terraform.recordSetForMachine(c.machine.key, terraformId, c.dns.fqdn))