From 5ffeba96ed307ef64f247b43efd072e7c6e660bc Mon Sep 17 00:00:00 2001 From: Alexander Stepchenko Date: Tue, 24 Oct 2023 21:08:11 +0300 Subject: [PATCH] refactor: use specific IDs for VMs --- main.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index e38a1e3..cafb879 100644 --- a/main.py +++ b/main.py @@ -46,27 +46,38 @@ def main(): 'worker1': f'{prefix}-node1', 'worker2': f'{prefix}-node2', } + vm_ids = { + 'master': 500, + 'worker1': 501, + 'worker2': 502, + } vm_id_master, upid_master = clone_template( proxmox, node, template_id, + newid=vm_ids['master'], name=vm_names['master'], ) + assert vm_id_master == vm_ids['master'] vm_id_worker1, upid_worker1 = clone_template( proxmox, node, template_id, + newid=vm_ids['worker1'], name=vm_names['worker1'], ) + assert vm_id_worker1 == vm_ids['worker1'] vm_id_worker2, upid_worker2 = clone_template( proxmox, node, template_id, + newid=vm_ids['worker2'], name=vm_names['worker2'], ) + assert vm_id_worker2 == vm_ids['worker2'] logger.info('Waiting for clone tasks to complete...') wait_status( @@ -81,14 +92,14 @@ def main(): logger.info('Tasks completed!') logger.info('Starting VMs...') - proxmox.nodes(node).qemu(vm_id_master).status.start.post() - proxmox.nodes(node).qemu(vm_id_worker1).status.start.post() - proxmox.nodes(node).qemu(vm_id_worker2).status.start.post() + proxmox.nodes(node).qemu(vm_ids['master']).status.start.post() + proxmox.nodes(node).qemu(vm_ids['worker1']).status.start.post() + proxmox.nodes(node).qemu(vm_ids['worker2']).status.start.post() wait_status( [ - proxmox.nodes(node).qemu(vm_id_master).status.current.get, - proxmox.nodes(node).qemu(vm_id_worker1).status.current.get, - proxmox.nodes(node).qemu(vm_id_worker2).status.current.get, + proxmox.nodes(node).qemu(vm_ids['master']).status.current.get, + proxmox.nodes(node).qemu(vm_ids['worker1']).status.current.get, + proxmox.nodes(node).qemu(vm_ids['worker2']).status.current.get, ], 'running' ) @@ -96,9 +107,9 @@ def main(): sleep(40) logger.info('VMs are running!') - vm_ip_master = get_vm_ip(proxmox, node, vm_id_master) - vm_ip_worker1 = get_vm_ip(proxmox, node, vm_id_worker1) - vm_ip_worker2 = get_vm_ip(proxmox, node, vm_id_worker2) + vm_ip_master = get_vm_ip(proxmox, node, vm_ids['master']) + vm_ip_worker1 = get_vm_ip(proxmox, node, vm_ids['worker1']) + vm_ip_worker2 = get_vm_ip(proxmox, node, vm_ids['worker2']) proxmox.logout() with open('run/vm_ids' ,'w') as ofile: