def _get_device_path(self): """Get a device path of the block device.""" log.debug("Resolving %s.", self._image_path) device_tree = STORAGE.get_proxy(DEVICE_TREE) # Get the device name. device_name = device_tree.ResolveDevice(self._image_path) if not device_name: raise SourceSetupError("Failed to resolve the Live OS image.") # Get the device path. device_data = DeviceData.from_structure( device_tree.GetDeviceData(device_name) ) device_path = device_data.path if not stat.S_ISBLK(os.stat(device_path)[stat.ST_MODE]): raise SourceSetupError("{} is not a valid block device.".format(device_path)) return device_path
def _get_request_description(self, request): """Get description of the given mount info.""" # Get the device data. device_name = self._device_tree.ResolveDevice(request.device_spec) device_data = DeviceData.from_structure( self._device_tree.GetDeviceData(device_name)) # Generate the description. description = "{} ({})".format(request.device_spec, Size(device_data.size)) if request.format_type: description += "\n {}".format(request.format_type) if request.reformat: description += "*" if request.mount_point: description += ", {}".format(request.mount_point) return description
def _choose_installation_device(self, device_tree, devices_candidates): device_name = "" for dev_name in devices_candidates: try: device_data = DeviceData.from_structure( device_tree.GetDeviceData(dev_name)) mount(device_data.path, self._target_mount, "iso9660", "ro") except OSError as e: log.debug("Failed to mount %s: %s", dev_name, str(e)) continue if is_valid_install_disk(self._target_mount): device_name = dev_name log.info("using CD-ROM device %s mounted at %s", dev_name, self._target_mount) break else: unmount(self._target_mount) return device_name
def _update_action_buttons(self): # Update buttons for the selected row. itr = self._selection.get_selected()[1] if not itr: return row = self._disk_store[itr] obj = PartStoreRow(*row) self._preserve_button.set_sensitive(obj.editable) self._shrink_button.set_sensitive(obj.editable) self._delete_button.set_sensitive(obj.editable) self._resize_slider.set_visible(False) if not obj.editable: return device_name = obj.name device_data = DeviceData.from_structure( self._device_tree.GetDeviceData(device_name)) # If the selected filesystem does not support shrinking, make that # button insensitive. is_shrinkable = self._device_tree.IsDeviceShrinkable(device_name) self._shrink_button.set_sensitive(is_shrinkable) if is_shrinkable: min_size = self._device_tree.GetDeviceSizeLimits(device_name)[0] self._setup_slider(min_size, device_data.size, Size(obj.target)) # Then, disable the button for whatever action is currently selected. # It doesn't make a lot of sense to allow clicking that. if obj.action == _(PRESERVE): self._preserve_button.set_sensitive(False) elif obj.action == _(SHRINK): self._shrink_button.set_sensitive(False) self._resize_slider.set_visible(True) elif obj.action == _(DELETE): self._delete_button.set_sensitive(False)
def run(self): """Run CD-ROM installation source setup.""" log.debug("Trying to detect CD-ROM automatically") device_tree = STORAGE.get_proxy(DEVICE_TREE) for dev_name in device_tree.FindOpticalMedia(): try: device_data = DeviceData.from_structure(device_tree.GetDeviceData(dev_name)) mount(device_data.path, self._target_mount, "iso9660", "ro") except PayloadSetupError: continue if is_valid_install_disk(self._target_mount): self._device_name = dev_name log.info("using CD-ROM device %s mounted at %s", dev_name, self._target_mount) break else: unmount(self._target_mount) if not self._device_name: raise SourceSetupError("Found no CD-ROM")
def _format_disk_info(self, disk): """ Some specialized disks are difficult to identify in the storage spoke, so add and return extra identifying information about them. Since this is going to be ugly to do within the confines of the CheckboxWidget, pre-format the display string right here. """ data = DeviceData.from_structure(self._device_tree.GetDeviceData(disk)) # show this info for all disks format_str = "{}: {} ({})".format(data.attrs.get("model", "DISK"), Size(data.size), data.name) # now append all additional attributes to our string disk_attrs = filter( None, map(data.attrs.get, ("wwn", "bus-id", "fcp-lun", "wwpn", "hba-id"))) for attr in disk_attrs: format_str += ", %s" % attr return format_str
def on_delete_all_clicked(self, button, *args): if button.get_label() == C_("GUI|Reclaim Dialog", "Delete _all"): action = DELETE button.set_label(C_("GUI|Reclaim Dialog", "Preserve _all")) else: action = PRESERVE button.set_label(C_("GUI|Reclaim Dialog", "Delete _all")) itr = self._disk_store.get_iter_first() while itr: obj = PartStoreRow(*self._disk_store[itr]) if not obj.editable: itr = self._disk_store.iter_next(itr) continue device_name = obj.name device_data = DeviceData.from_structure( self._device_tree.GetDeviceData(device_name)) if device_data.is_disk: self._on_action_changed(itr, action) itr = self._disk_store.iter_next(itr)
def _sum_reclaimable_space(self, model, path, itr, *args): obj = PartStoreRow(*model[itr]) if not obj.name: return False device_name = obj.name is_partitioned = self._device_tree.IsDevicePartitioned(device_name) if is_partitioned: return False device_data = DeviceData.from_structure( self._device_tree.GetDeviceData(device_name)) if obj.action == _(PRESERVE): return False elif obj.action == _(SHRINK): self._selected_reclaimable_space += Size(device_data.size) - Size( obj.target) elif obj.action == _(DELETE): self._selected_reclaimable_space += Size(device_data.size) return False
def exitHandler(rebootData): # Clear the list of watched PIDs. from pyanaconda.core.process_watchers import WatchProcesses WatchProcesses.unwatch_all_processes() if flags.usevnc: vnc.shutdownServer() if "nokill" in kernel_arguments: util.vtActivate(1) print("anaconda halting due to nokill flag.") print("The system will be rebooted when you press Ctrl-Alt-Delete.") while True: time.sleep(10000) if anaconda.dbus_inhibit_id: from pyanaconda.screensaver import uninhibit_screensaver uninhibit_screensaver(anaconda.dbus_session_connection, anaconda.dbus_inhibit_id) anaconda.dbus_inhibit_id = None # Unsetup the payload, which most usefully unmounts live images if anaconda.payload: anaconda.payload.unsetup() # Collect all optical media. from pyanaconda.modules.common.constants.objects import DEVICE_TREE from pyanaconda.modules.common.structures.storage import DeviceData device_tree = STORAGE.get_proxy(DEVICE_TREE) optical_media = [] for device_name in device_tree.FindOpticalMedia(): device_data = DeviceData.from_structure( device_tree.GetDeviceData(device_name) ) optical_media.append(device_data.path) # Tear down the storage module. storage_proxy = STORAGE.get_proxy() for task_path in storage_proxy.TeardownWithTasks(): task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) # Stop the DBus session. anaconda.dbus_launcher.stop() # Clean up the PID file if pidfile: pidfile.close() # Reboot the system. if conf.system.can_reboot: from pykickstart.constants import KS_SHUTDOWN, KS_WAIT if flags.eject or rebootData.eject: for device_path in optical_media: if util.get_mount_paths(device_path): util.dracut_eject(device_path) if flags.kexec: util.execWithRedirect("systemctl", ["--no-wall", "kexec"]) while True: time.sleep(10000) elif rebootData.action == KS_SHUTDOWN: util.execWithRedirect("systemctl", ["--no-wall", "poweroff"]) elif rebootData.action == KS_WAIT: util.execWithRedirect("systemctl", ["--no-wall", "halt"]) else: # reboot action is KS_REBOOT or None util.execWithRedirect("systemctl", ["--no-wall", "reboot"])
def post_install(self): super().post_install() data = self._get_source_configuration() gi.require_version("OSTree", "1.0") from gi.repository import OSTree cancellable = None # Following up on the "remote delete" above, we removed the # remote from /ostree/repo/config. But we want it in /etc, so # re-add it to /etc/ostree/remotes.d, using the sysroot path. # # However, we ignore the case where the remote already exists, # which occurs when the content itself provides the remote # config file. # Note here we use the deployment as sysroot, because it's # that version of /etc that we want. sysroot_file = Gio.File.new_for_path(conf.target.system_root) sysroot = OSTree.Sysroot.new(sysroot_file) sysroot.load(cancellable) repo = sysroot.get_repo(None)[1] repo.remote_change(sysroot_file, OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS, data.remote, data.url, Variant('a{sv}', self._remoteOptions), cancellable) boot = conf.target.system_root + '/boot' # If we're using GRUB2, move its config file, also with a # compatibility symlink. boot_grub2_cfg = boot + '/grub2/grub.cfg' if os.path.isfile(boot_grub2_cfg): boot_loader = boot + '/loader' target_grub_cfg = boot_loader + '/grub.cfg' log.info("Moving %s -> %s", boot_grub2_cfg, target_grub_cfg) os.rename(boot_grub2_cfg, target_grub_cfg) os.symlink('../loader/grub.cfg', boot_grub2_cfg) # Skip kernel args setup for dirinstall, there is no bootloader or rootDevice setup. if not conf.target.is_directory: # OSTree owns the bootloader configuration, so here we give it # the argument list we computed from storage, architecture and # such. bootloader = STORAGE.get_proxy(BOOTLOADER) device_tree = STORAGE.get_proxy(DEVICE_TREE) root_name = device_tree.GetRootDevice() root_data = DeviceData.from_structure( device_tree.GetDeviceData(root_name)) set_kargs_args = ["admin", "instutil", "set-kargs"] set_kargs_args.extend(bootloader.GetArguments()) set_kargs_args.append("root=" + device_tree.GetFstabSpec(root_name)) if root_data.type == "btrfs subvolume": set_kargs_args.append("rootflags=subvol=" + root_name) self._safe_exec_with_redirect("ostree", set_kargs_args, root=conf.target.system_root)
def get_dasd_info(self, disk_name): """Returns a string with description of a DASD.""" data = DeviceData.from_structure( self._device_tree.GetDeviceData(disk_name)) return "{} ({})".format(data.path, data.attrs.get("bus-id"))