mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
Cleanup adfter keyboard interrupts (also do a better job of cleaning up)
This commit is contained in:
parent
87f2d889b7
commit
0fe3c9e984
2 changed files with 22 additions and 11 deletions
|
@ -85,10 +85,10 @@ class VirtualBoxInstance(Instance):
|
|||
self.create()
|
||||
try:
|
||||
self.boot()
|
||||
except Exception as e:
|
||||
except (Exception, KeyboardInterrupt) as e:
|
||||
self.shutdown()
|
||||
raise e
|
||||
except Exception as e:
|
||||
except (Exception, KeyboardInterrupt) as e:
|
||||
self.destroy()
|
||||
raise e
|
||||
|
||||
|
|
|
@ -35,12 +35,18 @@ class BootableManifest(object):
|
|||
handle, image_path = tempfile.mkstemp()
|
||||
import os
|
||||
os.close(handle)
|
||||
try:
|
||||
build_server.download(bootstrap_info.volume.image_path, image_path)
|
||||
except (Exception, KeyboardInterrupt) as e:
|
||||
os.remove(image_path)
|
||||
raise e
|
||||
finally:
|
||||
build_server.delete(bootstrap_info.volume.image_path)
|
||||
image_type = {'virtualbox': VirtualBoxImage}
|
||||
return image_type.get(self.manifest_data['provider']['name'])(manifest, image_path)
|
||||
|
||||
def __enter__(self):
|
||||
try:
|
||||
self.build_server = self.pick_build_server()
|
||||
self.manifest = self.get_manifest(self.build_server)
|
||||
self.bootstrap_info = self.bootstrap(self.manifest, self.build_server)
|
||||
|
@ -48,6 +54,11 @@ class BootableManifest(object):
|
|||
self.image.open()
|
||||
self.instance = self.image.get_instance()
|
||||
self.instance.up()
|
||||
except (Exception, KeyboardInterrupt) as e:
|
||||
if hasattr(self, 'image'):
|
||||
self.image.close()
|
||||
self.image.destroy()
|
||||
raise e
|
||||
return self.instance
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
|
|
Loading…
Add table
Reference in a new issue