From 023b447ea78380bdec965db04b3ba3621c4d3a5b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 30 Dec 2020 17:33:04 +0100 Subject: Organizing code. --- py/acme/rai/terraform.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 py/acme/rai/terraform.py (limited to 'py/acme/rai/terraform.py') diff --git a/py/acme/rai/terraform.py b/py/acme/rai/terraform.py new file mode 100644 index 0000000..c84a7e1 --- /dev/null +++ b/py/acme/rai/terraform.py @@ -0,0 +1,42 @@ +from durable.lang import * + +class Terraform: + @staticmethod + def recordSetForMachine(machineKey: str, terraformId: str, fqdn: str): + return {"type": "terraform-record-set", + "key": machineKey, + "terraformId": terraformId, + "fqdn": fqdn, + "rrType": "A", + "rrData": f"scaleway_instance_ip.{machineKey}.address", + } + + @staticmethod + def machine(key: str): + return {"type": "terraform-machine", + "key": key, + } + + @staticmethod + def declare_rules(): + @when_all( + c.dns << (m.type == "dns-entry"), + 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)) + + @when_all((m.type == "terraform-record-set")) + def defaultTerraformRecordSet(c): + pass + + @when_all((m.type == "machine")) + def onDnsEntry(c): + print(f"matched machine: {c.m}") + c.assert_fact(Terraform.machine(c.m.key)) + + @when_all((m.type == "terraform-machine")) + def defaultTerraformMachine(c): + print(f"matched terraform-machine: {c.m}") -- cgit v1.2.3