diff --git a/README.rst b/README.rst index 62d2936..f20d462 100644 --- a/README.rst +++ b/README.rst @@ -58,7 +58,7 @@ use it ad-hoc, or place on your ``.bashrc`` or whatever: currently there are four commands available: -- ``list`` - for quickly listing running VMs +- ``list`` - for quickly listing all/running VMs - ``destroy`` - that is probably obvious one - ``create`` and ``rebuild`` @@ -108,7 +108,7 @@ need to provide all the option every time you boot up similar VM. For example: ssh_key: vm cpus: 4 memory: 4GB - disk-size: 20GB + disk_size: 20GB Contents of the user script will be merged with the default one, so expect, that user ``ubuntu`` will be there, and magically you'll be able to connect to diff --git a/box.py b/box.py index eb93800..384260b 100755 --- a/box.py +++ b/box.py @@ -658,6 +658,12 @@ def vmcreate(args): # give VBox some time to actually change the state of the VM before query time.sleep(3) + def _cleanup(vbox, iso, image, path_to_iso): + vbox.storageattach('IDE', 1, 'dvddrive', 'none') + vbox.closemedium('dvd', path_to_iso) + iso.cleanup() + image.cleanup() + # than, let's try to see if boostraping process has finished print('Waiting for cloud init to finish ', end='') try: @@ -671,16 +677,14 @@ def vmcreate(args): break except KeyboardInterrupt: print('\nIterrupted, cleaning up.') - VBoxManage(args.name).destroy() - iso.cleanup() - image.cleanup() + vbox.poweroff(silent=True) + time.sleep(1) # give some time to turn it off + _cleanup(vbox, iso, image, path_to_iso) + vbox.destroy() return 1 # dettach ISO image - vbox.storageattach('IDE', 1, 'dvddrive', 'none') - vbox.closemedium('dvd', path_to_iso) - iso.cleanup() - image.cleanup() + _cleanup(vbox, iso, image, path_to_iso) vbox.poweron() print('You can access your VM by issuing:') print(f'ssh -p {args.port} -i {iso.ssh_key_path[:-4]} ubuntu@localhost')