Commit d34c4912 authored by Nikos Skalkotos's avatar Nikos Skalkotos

Add a ismounted property in OSBase class

This can be used to check if the media mounting was successful
parent 2d812a34
......@@ -212,6 +212,7 @@ class OSBase(object):
# This will host the error if mount fails
self._mount_error = ""
self._mount_warnings = []
self._mounted = False
# Many guestfs compilations don't support scrub
self._scrub_support = True
......@@ -357,6 +358,10 @@ class OSBase(object):
self.out.output()
@property
def ismounted(self):
return self._mounted
def mount(self, readonly=False, silent=False, fatal=True):
"""Returns a context manager for mounting an image"""
......@@ -374,17 +379,30 @@ class OSBase(object):
parent._mount_error = ""
del parent._mount_warnings[:]
if not parent._do_mount(readonly) and fatal:
try:
parent._mounted = parent._do_mount(readonly)
except:
parent.image.g.umount_all()
raise
if not parent.ismounted:
msg = "Unable to mount the media %s. Reason: %s" % \
(mount_type, parent._mount_error)
raise FatalError(msg)
if fatal:
raise FatalError(msg)
else:
warn(msg)
for warning in parent._mount_warnings:
warn(warning)
success('done')
if parent.ismounted:
success('done')
def __exit__(self, exc_type, exc_value, traceback):
output("Umounting the media ...", False)
parent.image.g.umount_all()
parent._mounted = False
success('done')
return Mount()
......
......@@ -525,16 +525,21 @@ class Windows(OSBase):
self.out.output("Reverting media boot preparations ...", False)
with self.mount(readonly=False, silent=True, fatal=False):
if disabled_uac:
self.registry.update_uac_remote_setting(0)
if not self.sysprepped:
# Reset the old password
admin = self.sysprep_params['admin'].value
self.registry.reset_passwd(admin, v_val)
if not self.ismounted:
self.out.warn("The boot changes cannot be reverted. "
"The snapshot may be in a corrupted state.")
else:
if disabled_uac:
self.registry.update_uac_remote_setting(0)
self.registry.update_firewalls(*firewall_states)
self.out.success("done")
if not self.sysprepped:
# Reset the old password
admin = self.sysprep_params['admin'].value
self.registry.reset_passwd(admin, v_val)
self.registry.update_firewalls(*firewall_states)
self.out.success("done")
def _exec_sysprep_tasks(self):
"""This function hosts the actual code for executing the enabled
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment