class Plugin(plugins.NodePlugin): _model = {} def __init__(self, app): super(Plugin, self).__init__(app) self.storage_discovery = StorageDiscovery(app.args.dry) self.storage_discovery.start() def name(self): return _("Data Device") def rank(self): return 30 def model(self): devices = self.storage_discovery.all_devices_for_ui_table() self.logger.debug("Available devices: %s" % devices) if devices: selected_boot_dev = \ self.application.plugins()["Boot Device"]\ .model().get("boot.device.current", "") self.logger.debug("Selected boot device: %s" % selected_boot_dev) first_dev = devices[0][0] if selected_boot_dev in [dev[0] for dev in devices]: first_dev = selected_boot_dev self.logger.debug("First installation device: %s" % first_dev) self._model["installation.device.details"] = first_dev self._model["installation.device.current"] = first_dev return self._model def validators(self): def has_selection(v): if (self.widgets["installation.device.current"].selection() or "installation.device.custom" in self._model): return True else: return "Please select at least one installation device." def multiple_block_devices(v): if all(valid.BlockDevice().validate(b) for b in v.split(",")): return True else: return "Please enter only valid block devices." return { "installation.device.current": has_selection, "installation.device.custom": multiple_block_devices } def ui_content(self): page_title = \ _("Please select the disk(s) to use for installation of %s") \ % self.application.product.PRODUCT_SHORT other_device = self._model.get("installation.device.custom", "") devices = self.storage_discovery.all_devices_for_ui_table() ws = [ui.Header("header[0]", page_title)] tbl_head = self.storage_discovery.tbl_tpl.format(bus="Location", name="Device Name", size="Size (GB)") if devices: ws += [ ui.Table("installation.device.current", "", tbl_head, devices, height=3, multi=True), ui.Button("button.other_device", "Other Device: %s" % other_device), ui.Divider("divider[0]"), DeviceDetails("installation.device.details", self, _("(No device)")) ] else: ws += [ ui.Label("installation.no_device", _("No Valid Install Devices Detected")) ] page = ui.Page("installation", ws) page.buttons = [ ui.QuitButton("button.quit", _("Quit")), ui.Button("button.back", _("Back")), ui.SaveButton("button.next", _("Continue")) ] self.widgets.add(page) # We are directly connecting to the table's on_change event # The tables on_change event is fired (in the multi-case) # when the highlighted entry is changed. table = self.widgets["installation.device.current"] table.on_change.connect(self.__update_details) return page def __update_details(self, target, change): details = self.widgets["installation.device.details"] highlighted_device = change[target.path] if highlighted_device is "other": details.text("") else: details.set_device(highlighted_device) def on_change(self, changes): self.logger.debug("Installation device changes: %s" % changes) if changes.contains_any(["installation.device.current"]): changed_device = changes["installation.device.current"] if changed_device: selected_devices = \ self.widgets["installation.device.current"].selection() self.logger.debug("selected devices: %s" % selected_devices) changes["installation.devices"] = selected_devices self._model.update(changes) if changes.contains_any(["installation.device.custom"]): if self.storage_discovery.devices.live_disk_name() == \ self.storage_discovery.devices.translate_device_name( changes["installation.device.custom"]): raise exceptions.InvalidData("Can't be the same as " + "the live device") else: self._model.update(changes) def on_merge(self, effective_changes): changes = self.pending_changes(False) self.logger.debug("All inst changes: %s" % changes) if "button.other_device" in changes: details = self.widgets["installation.device.details"] details.text("") description = (("Please enter one or more disks to use " + "for installing %s. Multiple devices can be " + "separated by comma.") % self.application.product.PRODUCT_SHORT) self._dialog = CustomDeviceDialog("installation.device.custom", "Installation devices.", description) self.widgets.add(self._dialog) return self._dialog elif changes.contains_any( ["installation.device.custom", "dialog.device.custom.save"]): self._dialog.close() return self.ui_content() if changes.contains_any(["button.back"]): self.application.ui.navigate.to_previous_plugin() elif changes.contains_any(["button.next"]): if "installation.device.custom" in self._model: cdev = self._model["installation.device.custom"] self._model["installation.devices"].append(cdev) self.application.ui.navigate.to_next_plugin()
class Plugin(plugins.NodePlugin): _model = {} def __init__(self, app): super(Plugin, self).__init__(app) self.storage_discovery = StorageDiscovery(app.args.dry) self.storage_discovery.start() self._header = "{bus!s:8.8} {name!s:48.48} {size!s:9.9}" def name(self): return "Confirm disk selections" def rank(self): return 45 def model(self): # Force rebuilding in case they go back and change a value self._build_model() return self._model def validators(self): return {} def ui_content(self): align = lambda l: l.ljust(16) if not self._model: self._build_model() ws = [ ui.Header("header[0]", _("Confirm disk selections")), ui.Notice("notice[0]", _("The data on these disks will " "be erased!")), ui.KeywordLabel("boot.header", _("Boot device")), DiskDetails("boot.device.current", self, self._model["boot.device.current"]) ] if self._storage_tagged(self._model["boot.device.current"]): ws.extend([ ui.Notice("boot.notice", _("Boot device may be part " "of a storage domain!")) ]) ws.extend([ui.KeywordLabel("install.header", "Install devices")]) for i in range(len(self._model["installation.devices"])): ws.extend([ DiskDetails("installation.device[%s]" % i, self, self._model["installation.devices"][i]) ]) if self._storage_tagged(self._model["installation.devices"][i]): ws.extend([ ui.Notice( "installation.notice[%s]" % i, _("This device may be part of a storage " "domain!")) ]) ws.extend([ ui.Divider("divider[0]"), ui.KeywordLabel("storage.volumes", _("Volume sizes")) ]) intuples = lambda lst, n: [lst[x:x + n] for x in range(0, len(lst), n)] for xs in intuples( sorted(k for k in self._model.keys() if k.startswith("storage.")), 2): chi = [] for x in xs: chi.append( ui.KeywordLabel( x, _( align( x.replace("_", " ").replace( "storage.", "").title() + ":")))) row = ui.Row("row[%s]" % xs, chi) ws.append(row) if int(self._model["storage.data_size"]) < (50 * 1024): ws.extend([ ui.Divider("divider.he"), ui.Notice( "notice.he", "The size of the data volume is " "not large enough to use the Engine " "Appliance, must be at least 50GB (51200MB)") ]) page = ui.Page("confirmation", ws) page.buttons = [ ui.QuitButton("button.quit", _("Quit")), ui.Button("button.back", _("Back")), ui.SaveButton("button.next", _("Confirm")) ] self.widgets.add(page) return page def on_change(self, changes): pass def on_merge(self, effective_changes): changes = self.pending_changes(False) if changes.contains_any(["button.back"]): self.application.ui.navigate.to_previous_plugin() elif changes.contains_any(["button.next"]): self.application.ui.navigate.to_next_plugin() def _build_model(self): _model = {} [ _model.update(plugin.model()) for plugin in self.application.plugins().values() if not plugin.name() == "Confirm disk selections" ] [ _model.update({k: "%s" % _model[k]}) for k in _model.keys() if re.match(r'storage.*?size$', k) and not _model[k].endswith(" MB") ] if "storage.fill_data" in _model: if _model["storage.fill_data"]: _model["storage.free_space"] = "0" del _model["storage.fill_data"] _model["installation.devices"].sort() self._model = _model def _storage_tagged(self, dev): found = False for vg in LVM().vgs(): if dev in vg.pv_names and "storage_domain" in \ " ".join(vg.tags): found = True return found
class Plugin(plugins.NodePlugin): _model = {} def __init__(self, app): super(Plugin, self).__init__(app) self.storage_discovery = StorageDiscovery(app.args.dry) self.storage_discovery.start() def name(self): return _("Data Device") def rank(self): return 30 def model(self): devices = self.storage_discovery.all_devices_for_ui_table() self.logger.debug("Available devices: %s" % devices) if devices: selected_boot_dev = \ self.application.plugins()["Boot Device"]\ .model().get("boot.device.current", "") self.logger.debug("Selected boot device: %s" % selected_boot_dev) first_dev = devices[0][0] if selected_boot_dev in [dev[0] for dev in devices]: first_dev = selected_boot_dev self.logger.debug("First installation device: %s" % first_dev) self._model["installation.device.details"] = first_dev self._model["installation.device.current"] = first_dev return self._model def validators(self): def has_selection(v): if (self.widgets["installation.device.current"].selection() or "installation.device.custom" in self._model): return True else: return "Please select at least one installation device." def multiple_block_devices(v): if all(valid.BlockDevice().validate(b) for b in v.split(",")): return True else: return "Please enter only valid block devices." return {"installation.device.current": has_selection, "installation.device.custom": multiple_block_devices} def ui_content(self): page_title = \ _("Please select the disk(s) to use for installation of %s") \ % self.application.product.PRODUCT_SHORT other_device = self._model.get("installation.device.custom", "") devices = self.storage_discovery.all_devices_for_ui_table() ws = [ui.Header("header[0]", page_title)] tbl_head = self.storage_discovery.tbl_tpl.format(bus="Location", name="Device Name", size="Size (GB)") if devices: ws += [ui.Table("installation.device.current", "", tbl_head, devices, height=3, multi=True), ui.Button("button.other_device", "Other Device: %s" % other_device), ui.Divider("divider[0]"), DeviceDetails("installation.device.details", self, _("(No device)")) ] else: ws += [ui.Label("installation.no_device", _("No Valid Install Devices Detected"))] page = ui.Page("installation", ws) page.buttons = [ui.QuitButton("button.quit", _("Quit")), ui.Button("button.back", _("Back")), ui.SaveButton("button.next", _("Continue"))] self.widgets.add(page) # We are directly connecting to the table's on_change event # The tables on_change event is fired (in the multi-case) # when the highlighted entry is changed. table = self.widgets["installation.device.current"] table.on_change.connect(self.__update_details) return page def __update_details(self, target, change): details = self.widgets["installation.device.details"] highlighted_device = change[target.path] if highlighted_device is "other": details.text("") else: details.set_device(highlighted_device) def on_change(self, changes): self.logger.debug("Installation device changes: %s" % changes) if changes.contains_any(["installation.device.current"]): changed_device = changes["installation.device.current"] if changed_device: selected_devices = \ self.widgets["installation.device.current"].selection() self.logger.debug("selected devices: %s" % selected_devices) changes["installation.devices"] = selected_devices self._model.update(changes) if changes.contains_any(["installation.device.custom"]): if self.storage_discovery.devices.live_disk_name() == \ self.storage_discovery.devices.translate_device_name( changes["installation.device.custom"]): raise exceptions.InvalidData("Can't be the same as " + "the live device") elif self.storage_discovery.devices.translate_device_name( changes["installation.device.custom"]) in \ self.widgets["installation.device.current"].selection(): raise exceptions.InvalidData("%s is already selected" % changes[ "installation.device.custom"]) else: self._model.update(changes) def on_merge(self, effective_changes): changes = self.pending_changes(False) self.logger.debug("All inst changes: %s" % changes) if "button.other_device" in changes: details = self.widgets["installation.device.details"] details.text("") description = (("Please enter one or more disks to use " + "for installing %s. Multiple devices can be " + "separated by comma.") % self.application.product.PRODUCT_SHORT) self._dialog = CustomDeviceDialog("installation.device.custom", "Installation devices.", description, self) self.widgets.add(self._dialog) return self._dialog if changes.contains_any(["installation.device.custom"]): # Check if any custom device was set cdevs = self._model.get("installation.device.custom", "").\ split(",") # Update the installlation devices accordingly self._model.setdefault("installation.devices", []).extend(cdevs) if changes.contains_any(["dialog.device.custom.save"]): # Custom device dialog: <Save> has been hit self._dialog.close() self.application.ui.navigate.to_next_plugin() elif changes.contains_any(["button.back"]): self.application.ui.navigate.to_previous_plugin() elif changes.contains_any(["button.next"]): self.application.ui.navigate.to_next_plugin()
class Plugin(plugins.NodePlugin): _model = {} def __init__(self, app): super(Plugin, self).__init__(app) self.storage_discovery = StorageDiscovery(app.args.dry) self.storage_discovery.start() def name(self): return "Data Device" def rank(self): return 30 def model(self): devices = self.storage_discovery.all_devices_for_ui_table() self.logger.debug("Available devices: %s" % devices) if devices: first_dev = devices[0][0] self._model["installation.device.details"] = first_dev self._model["installation.device.current"] = first_dev return self._model def validators(self): has_selection = lambda v: "At least one installation device" \ if not self.widgets["installation.device.current"].selection() \ else True return {"installation.device.current": has_selection} def ui_content(self): page_title = "Please select the disk(s) to use for installation " \ "of %s" % self.application.product.PRODUCT_SHORT other_device = self._model.get("installation.device.custom", "") devices = self.storage_discovery.all_devices_for_ui_table(other_device) ws = [ui.Header("header[0]", page_title)] if devices: ws += [ui.Table("installation.device.current", "", " %6s %11s %5s" % ("Location", "Device Name", "Size"), devices, multi=True), DeviceDetails("installation.device.details", self, "(No device)") ] else: ws += [ui.Label("installation.no_device", "No Valid Install Devices Detected")] page = ui.Page("installation", ws) page.buttons = [ui.QuitButton("button.quit", "Quit"), ui.Button("button.back", "Back"), ui.SaveButton("button.next", "Continue")] self.widgets.add(page) return page def on_change(self, changes): self.logger.debug("Installation device changes: %s" % changes) if changes.contains_any(["installation.device.current"]): highlighted_device = changes["installation.device.current"] details = self.widgets["installation.device.details"] if highlighted_device == "other": details.text("") self._dialog = CustomDeviceDialog("custom", "x", "y") return self._dialog elif highlighted_device: selected_devices = \ self.widgets["installation.device.current"].selection() self.logger.debug("selected devices: %s" % selected_devices) changes["installation.devices"] = selected_devices self._model.update(changes) details.set_device(highlighted_device) def on_merge(self, effective_changes): changes = self.pending_changes(False) self.logger.debug("All inst changes: %s" % changes) if changes.contains_any(["button.back"]): self.application.ui.navigate.to_previous_plugin() elif changes.contains_any(["button.next"]): self.application.ui.navigate.to_next_plugin() elif changes.contains_any(["installation.device.custom", "dialog.device.custom.save"]): self._dialog.close() return self.ui_content()
class Plugin(plugins.NodePlugin): _model = {} def __init__(self, app): super(Plugin, self).__init__(app) self.storage_discovery = StorageDiscovery(app.args.dry) self.storage_discovery.start() self._header = "{bus!s:8.8} {name!s:48.48} {size!s:9.9}" def name(self): return "Confirm disk selections" def rank(self): return 45 def model(self): # Force rebuilding in case they go back and change a value self._build_model() return self._model def validators(self): return {} def ui_content(self): align = lambda l: l.ljust(16) if not self._model: self._build_model() ws = [ui.Header("header[0]", _("Confirm disk selections")), ui.Notice("notice[0]", _("The data on these disks will " "be erased!")), ui.KeywordLabel("boot.header", _("Boot device")), DiskDetails("boot.device.current", self, self._model["boot.device.current"])] if self._storage_tagged(self._model["boot.device.current"]): ws.extend([ui.Notice("boot.notice", _("Boot device may be part " "of a storage domain!"))]) ws.extend([ui.KeywordLabel("install.header", "Install devices")]) for i in range(len(self._model["installation.devices"])): ws.extend([DiskDetails("installation.device[%s]" % i, self, self._model["installation.devices"][i])]) if self._storage_tagged(self._model["installation.devices"][i]): ws.extend([ui.Notice("installation.notice[%s]" % i, _("This device may be part of a storage " "domain!"))]) ws.extend([ui.Divider("divider[0]"), ui.KeywordLabel("storage.volumes", _("Volume sizes"))]) intuples = lambda lst, n: [lst[x:x+n] for x in range(0, len(lst), n)] for xs in intuples(sorted(k for k in self._model.keys() if k.startswith("storage.")), 2): chi = [] for x in xs: chi.append(ui.KeywordLabel(x, _(align( x.replace("_", " ").replace("storage.", "").title() + ":")) )) row = ui.Row("row[%s]" % xs, chi) ws.append(row) if int(self._model["storage.data_size"]) < (50*1024): ws.extend([ui.Divider("divider.he"), ui.Notice("notice.he", "The size of the data volume is " "not large enough to use the Engine " "Appliance, must be at least 50GB (51200MB)")]) page = ui.Page("confirmation", ws) page.buttons = [ui.QuitButton("button.quit", _("Quit")), ui.Button("button.back", _("Back")), ui.SaveButton("button.next", _("Confirm"))] self.widgets.add(page) return page def on_change(self, changes): pass def on_merge(self, effective_changes): changes = self.pending_changes(False) if changes.contains_any(["button.back"]): self.application.ui.navigate.to_previous_plugin() elif changes.contains_any(["button.next"]): self.application.ui.navigate.to_next_plugin() def _build_model(self): _model = {} [_model.update(plugin.model()) for plugin in self.application.plugins().values() if not plugin.name() == "Confirm disk selections"] [_model.update({k: "%s" % _model[k]}) for k in _model.keys() if re.match(r'storage.*?size$', k) and not _model[k].endswith(" MB")] if "storage.fill_data" in _model: del _model["storage.fill_data"] _model["installation.devices"].sort() self._model = _model self.logger.debug("SET %s" % _model) def _storage_tagged(self, dev): found = False for vg in LVM().vgs(): if dev in vg.pv_names and "storage_domain" in \ " ".join(vg.tags): found = True return found
class Plugin(plugins.NodePlugin): _model = {} def __init__(self, app): super(Plugin, self).__init__(app) self.storage_discovery = StorageDiscovery(app.args.dry) self.storage_discovery.start() def name(self): return _("Data Device") def rank(self): return 30 def model(self): devices = self.storage_discovery.all_devices_for_ui_table() self.logger.debug("Available devices: %s" % devices) if devices: first_dev = devices[0][0] self._model["installation.device.details"] = first_dev self._model["installation.device.current"] = first_dev return self._model def validators(self): def has_selection(v): if self.widgets["installation.device.current"].selection(): return True else: return "Please select at least one installation device." def multiple_block_devices(v): if all(valid.BlockDevice().validate(b) for b in v.split(",")): return True else: return "Please enter only valid block devices." return {"installation.device.current": has_selection, "installation.device.custom": multiple_block_devices} def ui_content(self): page_title = \ _("Please select the disk(s) to use for installation of %s") \ % self.application.product.PRODUCT_SHORT other_device = self._model.get("installation.device.custom", "") devices = self.storage_discovery.all_devices_for_ui_table() ws = [ui.Header("header[0]", page_title)] if devices: ws += [ui.Table("installation.device.current", "", " %6s %11s %5s" % (_("Location"), _("Device Name"), _("Size")), devices, height=3, multi=True), ui.Button("button.other_device", "Other Device: %s" % other_device), ui.Divider("divider[0]"), DeviceDetails("installation.device.details", self, _("(No device)")) ] else: ws += [ui.Label("installation.no_device", _("No Valid Install Devices Detected"))] page = ui.Page("installation", ws) page.buttons = [ui.QuitButton("button.quit", _("Quit")), ui.Button("button.back", _("Back")), ui.SaveButton("button.next", _("Continue"))] self.widgets.add(page) # We are directly connecting to the table's on_change event # The tables on_change event is fired (in the multi-case) # when the highlighted entry is changed. table = self.widgets["installation.device.current"] table.on_change.connect(self.__update_details) return page def __update_details(self, target, change): details = self.widgets["installation.device.details"] highlighted_device = change[target.path] if highlighted_device is "other": details.text("") else: details.set_device(highlighted_device) def on_change(self, changes): self.logger.debug("Installation device changes: %s" % changes) if changes.contains_any(["installation.device.current"]): changed_device = changes["installation.device.current"] if changed_device: selected_devices = \ self.widgets["installation.device.current"].selection() self.logger.debug("selected devices: %s" % selected_devices) changes["installation.devices"] = selected_devices self._model.update(changes) if changes.contains_any(["installation.device.custom"]): self._model.update(changes) def on_merge(self, effective_changes): changes = self.pending_changes(False) self.logger.debug("All inst changes: %s" % changes) if "button.other_device" in changes: details = self.widgets["installation.device.details"] details.text("") description = (("Please enter one or more disks to use " + "for installing %s. Multiple devices can be " + "separated by comma.") % self.application.product.PRODUCT_SHORT) self._dialog = CustomDeviceDialog("installation.device.custom", "Installation devices.", description) self.widgets.add(self._dialog) return self._dialog elif changes.contains_any(["installation.device.custom", "dialog.device.custom.save"]): self._dialog.close() return self.ui_content() if changes.contains_any(["button.back"]): self.application.ui.navigate.to_previous_plugin() elif changes.contains_any(["button.next"]): self.application.ui.navigate.to_next_plugin()
class Plugin(plugins.NodePlugin): _model = {} def __init__(self, app): super(Plugin, self).__init__(app) self.storage_discovery = StorageDiscovery(app.args.dry) self.storage_discovery.start() def name(self): return "Data Device" def rank(self): return 30 def model(self): devices = self.storage_discovery.all_devices_for_ui_table() self.logger.debug("Available devices: %s" % devices) if devices: first_dev = devices[0][0] self._model["installation.device.details"] = first_dev self._model["installation.device.current"] = first_dev return self._model def validators(self): has_selection = lambda v: "At least one installation device" \ if not self.widgets["installation.device.current"].selection() \ else True return {"installation.device.current": has_selection} def ui_content(self): page_title = "Please select the disk(s) to use for installation " \ "of %s" % self.application.product.PRODUCT_SHORT other_device = self._model.get("installation.device.custom", "") devices = self.storage_discovery.all_devices_for_ui_table(other_device) ws = [ui.Header("header[0]", page_title)] if devices: ws += [ ui.Table("installation.device.current", "", " %6s %11s %5s" % ("Location", "Device Name", "Size"), devices, multi=True), DeviceDetails("installation.device.details", self, "(No device)") ] else: ws += [ ui.Label("installation.no_device", "No Valid Install Devices Detected") ] page = ui.Page("installation", ws) page.buttons = [ ui.QuitButton("button.quit", "Quit"), ui.Button("button.back", "Back"), ui.SaveButton("button.next", "Continue") ] self.widgets.add(page) return page def on_change(self, changes): self.logger.debug("Installation device changes: %s" % changes) if changes.contains_any(["installation.device.current"]): highlighted_device = changes["installation.device.current"] details = self.widgets["installation.device.details"] if highlighted_device == "other": details.text("") self._dialog = CustomDeviceDialog("custom", "x", "y") return self._dialog elif highlighted_device: selected_devices = \ self.widgets["installation.device.current"].selection() self.logger.debug("selected devices: %s" % selected_devices) changes["installation.devices"] = selected_devices self._model.update(changes) details.set_device(highlighted_device) def on_merge(self, effective_changes): changes = self.pending_changes(False) self.logger.debug("All inst changes: %s" % changes) if changes.contains_any(["button.back"]): self.application.ui.navigate.to_previous_plugin() elif changes.contains_any(["button.next"]): self.application.ui.navigate.to_next_plugin() elif changes.contains_any( ["installation.device.custom", "dialog.device.custom.save"]): self._dialog.close() return self.ui_content()