fixed stuffs

This commit is contained in:
Pünkösd Marcell 2021-11-11 02:32:26 +01:00
parent f4bdf8809e
commit fbee178ad2

View File

@ -59,7 +59,7 @@ libvirt = """<domain type="kvm">
<currentMemory unit="MiB">{ram}</currentMemory> <currentMemory unit="MiB">{ram}</currentMemory>
<vcpu placement="static">2</vcpu> <vcpu placement="static">2</vcpu>
<os> <os>
<type arch="x86_64" machine="pc-q35-6.1">hvm</type> <type arch="x86_64" machine="pc-q35-6.0">hvm</type>
<boot dev="hd"/> <boot dev="hd"/>
</os> </os>
<features> <features>
@ -88,9 +88,11 @@ libvirt = """<domain type="kvm">
<target dev="sda" bus="sata"/> <target dev="sda" bus="sata"/>
<readonly/> <readonly/>
</disk> </disk>
<disk type="file" device="disk"> <disk type="block" device="disk">
<driver name="qemu" type="qcow2"/> <driver name="qemu" type="raw" cache="none" io="native"/>
<source file="{hostdrive}"/> <backingStore/>
<source dev="{hostdrive}"/>
<alias name="virtio-disk0"/>
<target dev="vda" bus="virtio"/> <target dev="vda" bus="virtio"/>
</disk> </disk>
<controller type="usb" index="0" model="qemu-xhci" ports="15"> <controller type="usb" index="0" model="qemu-xhci" ports="15">
@ -195,8 +197,8 @@ libvirt = """<domain type="kvm">
def run_iso(hostname:str, ipaddr:str): def run_iso(hostname:str, ipaddr:str):
isoout = "/var/lib/libvirt/images/cloudiso" isoout = "/home/marcsello/ultrabirbcluster/vm_generator_luna/iso"
gateway = '192.168.' + ipaddr.split('.')[3] + '.1' # Ezen Kristóf jót nevetett os.makedirs(isoout, exist_ok=True)
cloudinit_fhandle, cloudinit_fname = tempfile.mkstemp(suffix='.yaml') cloudinit_fhandle, cloudinit_fname = tempfile.mkstemp(suffix='.yaml')
with open(cloudinit_fhandle, "wt") as f: with open(cloudinit_fhandle, "wt") as f:
@ -204,21 +206,23 @@ def run_iso(hostname:str, ipaddr:str):
cloudinit.format(hostname=hostname) cloudinit.format(hostname=hostname)
) )
netplan_fhandle, netplan_fname = tempfile.mkstemp(suffix='.yaml') if ipaddr:
with open(netplan_fhandle, "wt") as f: gateway = '192.168.' + ipaddr.split('.')[2] + '.1' # Ezen Kristóf jót nevetett
f.write( netplan_fhandle, netplan_fname = tempfile.mkstemp(suffix='.yaml')
netplan.format( with open(netplan_fhandle, "wt") as f:
addr=ipaddr, f.write(
gateway=gateway, netplan.format(
addr=ipaddr,
gateway=gateway,
)
) )
) os.system(f'cloud-localds -v {isoout}/cloudinit-{hostname}.iso --network-config={netplan_fname} {cloudinit_fname}')
os.unlink(netplan_fname)
else:
os.system(f'cloud-localds -v {isoout}/cloudinit-{hostname}.iso {cloudinit_fname}')
os.makedirs(isoout, exist_ok=True)
os.system(f'cloud-localds -v {isoout}/cloudinit-{hostname}.iso --network-config={netplan_fname} {cloudinit_fname}')
os.unlink(cloudinit_fname) os.unlink(cloudinit_fname)
os.unlink(netplan_fname)
def run_img(hostname:str, img_src:str): def run_img(hostname:str, img_src:str):
lv_name = hostname.replace('-', '_') lv_name = hostname.replace('-', '_')