wip: skel for provisioning script

This commit is contained in:
2025-01-18 13:18:32 +00:00
parent 3222b4b437
commit 73106f6d57
2 changed files with 66 additions and 0 deletions

40
provisioning/mac.py Normal file
View File

@@ -0,0 +1,40 @@
import libvirt
import xml.etree.ElementTree as ET
def get_mac_address(domain):
try:
# Connect to the libvirt daemon
conn = libvirt.open()
if conn is None:
raise RuntimeError("Failed to open connection to the hypervisor.")
# Lookup the domain by name
vm = conn.lookupByName(domain)
if vm is None:
raise ValueError(f"Domain '{domain}' not found.")
# Get the XML description of the domain
xml_desc = vm.XMLDesc()
# Parse the XML to extract the MAC address
root = ET.fromstring(xml_desc)
mac_element = root.find(".//mac")
if mac_element is not None:
mac_address = mac_element.attrib.get('address')
return mac_address
else:
raise ValueError("MAC address not found in XML.")
except libvirt.libvirtError as e:
return f"A libvirt error occurred: {e}"
except Exception as e:
return f"An error occurred: {e}"
finally:
if conn:
conn.close()
# Replace 'debian' with your domain name
domain_name = "debian"
mac_address = get_mac_address(domain_name)
print(f"MAC Address: {mac_address}")

26
provisioning/master.py Normal file
View File

@@ -0,0 +1,26 @@
# get new domain name
# create a VM and clone disk
# set CPU & RAM
# get mac
virsh_vm.get_mac(domain)
# change network
network.set_ip_for_mac_domain(domain, mac)
# net destory net start ?
# start vm
# change hostname
# add vm subdomains
# run python script
# run cert script
# reload nginx