1
0
mirror of https://github.com/gryf/boxpy.git synced 2026-01-06 02:24:12 +01:00

Some minor tweaks

This commit is contained in:
2021-05-05 20:42:39 +02:00
parent 799efd8633
commit 8df0d31d25
2 changed files with 13 additions and 9 deletions

View File

@@ -58,7 +58,7 @@ use it ad-hoc, or place on your ``.bashrc`` or whatever:
currently there are four commands available: 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 - ``destroy`` - that is probably obvious one
- ``create`` and ``rebuild`` - ``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 ssh_key: vm
cpus: 4 cpus: 4
memory: 4GB memory: 4GB
disk-size: 20GB disk_size: 20GB
Contents of the user script will be merged with the default one, so expect, 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 that user ``ubuntu`` will be there, and magically you'll be able to connect to

18
box.py
View File

@@ -658,6 +658,12 @@ def vmcreate(args):
# give VBox some time to actually change the state of the VM before query # give VBox some time to actually change the state of the VM before query
time.sleep(3) 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 # than, let's try to see if boostraping process has finished
print('Waiting for cloud init to finish ', end='') print('Waiting for cloud init to finish ', end='')
try: try:
@@ -671,16 +677,14 @@ def vmcreate(args):
break break
except KeyboardInterrupt: except KeyboardInterrupt:
print('\nIterrupted, cleaning up.') print('\nIterrupted, cleaning up.')
VBoxManage(args.name).destroy() vbox.poweroff(silent=True)
iso.cleanup() time.sleep(1) # give some time to turn it off
image.cleanup() _cleanup(vbox, iso, image, path_to_iso)
vbox.destroy()
return 1 return 1
# dettach ISO image # dettach ISO image
vbox.storageattach('IDE', 1, 'dvddrive', 'none') _cleanup(vbox, iso, image, path_to_iso)
vbox.closemedium('dvd', path_to_iso)
iso.cleanup()
image.cleanup()
vbox.poweron() vbox.poweron()
print('You can access your VM by issuing:') print('You can access your VM by issuing:')
print(f'ssh -p {args.port} -i {iso.ssh_key_path[:-4]} ubuntu@localhost') print(f'ssh -p {args.port} -i {iso.ssh_key_path[:-4]} ubuntu@localhost')