mirror of
https://github.com/FAUSheppy/athq-vm-management
synced 2025-12-06 05:41:35 +01:00
feat: add icinga & ansible file generation
This commit is contained in:
@@ -3,7 +3,7 @@ environment = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath="./te
|
||||
|
||||
def createMasterHostConfig(vmList):
|
||||
template = environment.get_template("icinga_host.conf.j2")
|
||||
with open("build/icinga_master_hosts.conf", "w") as f:
|
||||
with open("ansible/files/icinga_master_hosts.conf", "w") as f:
|
||||
for vmo in vmList:
|
||||
|
||||
if not vmo.check:
|
||||
|
||||
11
main.py
11
main.py
@@ -78,3 +78,14 @@ if __name__ == "__main__":
|
||||
|
||||
# dump icinga master
|
||||
icinga.createMasterHostConfig(vmList)
|
||||
|
||||
# dump ansible
|
||||
with open("./ansible/hosts.ini", "w") as f:
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath="./templates"))
|
||||
template = env.get_template("hosts.ini.j2")
|
||||
for vmo in set(vmList):
|
||||
if vmo.ansible:
|
||||
f.write(template.render(hostname=vmo.hostname, ip=vmo.ip))
|
||||
f.write("\n")
|
||||
|
||||
|
||||
|
||||
8
vm.py
8
vm.py
@@ -15,6 +15,7 @@ class VM:
|
||||
self.network = args.get("network") or "default"
|
||||
self.isExternal = args.get("external")
|
||||
self.noTerminateACME = args.get("no-terminate-acme")
|
||||
self.ansible = not args.get("noansible")
|
||||
|
||||
if self.isExternal:
|
||||
self.lease = None
|
||||
@@ -39,6 +40,13 @@ class VM:
|
||||
|
||||
raise ValueError("Hostname {} doesn't have a DHCP lease".format(self.hostname))
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.hostname)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.hostname == other.hostname
|
||||
|
||||
|
||||
def dumpStreamComponents(self):
|
||||
|
||||
# port forwarding components #
|
||||
|
||||
Reference in New Issue
Block a user