def find_and_mount_iso_image(source_path, mount_path): """Find ISO image and mount it. :param str source_path: path to where to look for the iso; it could point to iso directly :param str mount_path: where to mount the ISO image :return: name of the ISO image file or empty string if ISO can't be used """ iso_name = find_first_iso_image(source_path) if iso_name: path_to_iso = _create_iso_path(source_path, iso_name) if mount_iso_image(path_to_iso, mount_path): return iso_name return ""
def run(self): """Run Hard drive installation source setup. Always sets up two mount points: First for the device, and second for the ISO image or a bind for unpacked ISO. These depend on each other, and must be destroyed in the correct order again. :raise: SourceSetupError :return: named tuple with path to the install tree and name of ISO if set or empty string :rtype: SetupHardDriveResult instance """ log.debug("Setting up Hard drive source") for mount_point in [self._device_mount, self._iso_mount]: if os.path.ismount(mount_point): raise SourceSetupError( "The mount point {} is already in use.".format( mount_point)) if not find_and_mount_device(self._partition, self._device_mount): raise SourceSetupError( "Could not mount device specified as {}".format( self._partition)) full_path_on_mounted_device = os.path.normpath("{}/{}".format( self._device_mount, self._directory)) iso_name = find_first_iso_image(full_path_on_mounted_device) if iso_name: full_path_to_iso = self._create_iso_path( full_path_on_mounted_device, iso_name) if mount_iso_image(full_path_to_iso, self._iso_mount): log.debug("Using the ISO '%s' mounted at '%s'.", iso_name, self._iso_mount) return SetupHardDriveResult(self._iso_mount, iso_name) if verify_valid_installtree(full_path_on_mounted_device): log.debug("Using the directory at '%s'.", full_path_on_mounted_device) return SetupHardDriveResult(full_path_on_mounted_device, "") raise SourceSetupError( "Nothing useful found for Hard drive ISO source at partition={} directory={}" .format(self._partition, self._directory))
def _find_and_mount_iso(self, device, device_mount_dir, iso_path, iso_mount_dir): """Find and mount installation source from ISO on device. Return changed path to the iso to save looking for iso in the future call. """ self._setup_device(device, mountpoint=device_mount_dir) # check for ISO images in the newly mounted dir path = device_mount_dir if iso_path: path = os.path.normpath("%s/%s" % (path, iso_path)) # XXX it would be nice to streamline this when we're just setting # things back up after storage activation instead of having to # pretend we don't already know which ISO image we're going to # use image = find_first_iso_image(path) if not image: payload_utils.teardown_device(device) raise PayloadSetupError("failed to find valid iso image") if path.endswith(".iso"): path = os.path.dirname(path) # this could already be set up the first time through if not os.path.ismount(iso_mount_dir): # mount the ISO on a loop image = os.path.normpath("%s/%s" % (path, image)) payload_utils.mount(image, iso_mount_dir, fstype='iso9660', options="ro") if not iso_path.endswith(".iso"): result_path = os.path.normpath("%s/%s" % (iso_path, os.path.basename(image))) while result_path.startswith("/"): # ridiculous result_path = result_path[1:] return result_path return iso_path
def find_and_mount_iso_image(image_location, mount_point): """Find a ISO image in a location and mount it. :param str image_location: where the image ISO file is :param str mount_point: where to mount the image :return: success or not :rtype: bool """ image_filename = find_first_iso_image(image_location) if not image_filename: return False full_image_path = join_paths(image_location, image_filename) try: mount(full_image_path, mount_point, fstype='iso9660', options="ro") return True except OSError as e: log.error("Mount of ISO file failed: %s", e) return False