From fbee178ad25c52526aa5526efae40deea57fa100 Mon Sep 17 00:00:00 2001 From: marcsello Date: Thu, 11 Nov 2021 02:32:26 +0100 Subject: [PATCH] fixed stuffs --- vm_generator_luna/generate.py | 40 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/vm_generator_luna/generate.py b/vm_generator_luna/generate.py index b52fa83..dd42c41 100644 --- a/vm_generator_luna/generate.py +++ b/vm_generator_luna/generate.py @@ -59,7 +59,7 @@ libvirt = """ {ram} 2 - hvm + hvm @@ -88,9 +88,11 @@ libvirt = """ - - - + + + + + @@ -195,8 +197,8 @@ libvirt = """ def run_iso(hostname:str, ipaddr:str): - isoout = "/var/lib/libvirt/images/cloudiso" - gateway = '192.168.' + ipaddr.split('.')[3] + '.1' # Ezen Kristóf jót nevetett + isoout = "/home/marcsello/ultrabirbcluster/vm_generator_luna/iso" + os.makedirs(isoout, exist_ok=True) cloudinit_fhandle, cloudinit_fname = tempfile.mkstemp(suffix='.yaml') with open(cloudinit_fhandle, "wt") as f: @@ -204,21 +206,23 @@ def run_iso(hostname:str, ipaddr:str): cloudinit.format(hostname=hostname) ) - netplan_fhandle, netplan_fname = tempfile.mkstemp(suffix='.yaml') - with open(netplan_fhandle, "wt") as f: - f.write( - netplan.format( - addr=ipaddr, - gateway=gateway, + if ipaddr: + gateway = '192.168.' + ipaddr.split('.')[2] + '.1' # Ezen Kristóf jót nevetett + netplan_fhandle, netplan_fname = tempfile.mkstemp(suffix='.yaml') + with open(netplan_fhandle, "wt") as f: + f.write( + 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(netplan_fname) - + def run_img(hostname:str, img_src:str): lv_name = hostname.replace('-', '_')