From ed5535cd4e04bf00bf0823acdfea61361dd70b13 Mon Sep 17 00:00:00 2001 From: gryf Date: Wed, 5 May 2021 17:25:59 +0200 Subject: [PATCH] Guard against interruption during invalid cloud config. --- box.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/box.py b/box.py index 116b37c..96fbd95 100755 --- a/box.py +++ b/box.py @@ -578,14 +578,20 @@ def vmcreate(args): # than, let's try to see if boostraping process has finished print('Waiting for cloud init to finish ', end='') - while True: - if vbox.vm_info['uuid'] in vbox.get_running_vms(): - print('.', end='') - sys.stdout.flush() - time.sleep(3) - else: - print(' done.') - break + try: + while True: + if vbox.vm_info['uuid'] in vbox.get_running_vms(): + print('.', end='') + sys.stdout.flush() + time.sleep(3) + else: + print(' done.') + break + except KeyboardInterrupt: + print('\nIterrupted, cleaning up.') + VBoxManage(args.name).destroy() + return 1 + # dettach ISO image vbox.storageattach('IDE', 1, 'dvddrive', 'none') vbox.closemedium('dvd', path_to_iso)