def raidlevelchangeCB(self, widget, sparesb): raidlevel = widget.get_model()[widget.get_active()][0] numparts = sparesb.get_data("numparts") maxspares = mdraidlib.get_raid_max_spares(raidlevel, numparts) if maxspares > 0 and not mdraidlib.isRaid(mdraidlib.RAID0, raidlevel): adj = sparesb.get_adjustment() value = adj.value if adj.value > maxspares: value = maxspares sparesb.set_sensitive(1) spareAdj = gtk.Adjustment(value = value, lower = 0, upper = maxspares, step_incr = 1) spareAdj.clamp_page(0, maxspares) sparesb.set_adjustment(spareAdj) sparesb.set_value(value) else: sparesb.set_value(0) sparesb.set_sensitive(0)
def raidlevelchangeCB(self, widget, sparesb): raidlevel = widget.get_model()[widget.get_active()][0] numparts = sparesb.get_data("numparts") maxspares = mdraidlib.get_raid_max_spares(raidlevel, numparts) if maxspares > 0 and not mdraidlib.isRaid(mdraidlib.RAID0, raidlevel): adj = sparesb.get_adjustment() value = adj.value if adj.value > maxspares: value = maxspares sparesb.set_sensitive(1) spareAdj = gtk.Adjustment(value=value, lower=0, upper=maxspares, step_incr=1) spareAdj.clamp_page(0, maxspares) sparesb.set_adjustment(spareAdj) sparesb.set_value(value) else: sparesb.set_value(0) sparesb.set_sensitive(0)
def run(self): if self.dialog is None: return [] while 1: self.allow_ok_button(self._total_selected_members()) rc = self.dialog.run() # user hit cancel, do nothing if rc in [2, gtk.RESPONSE_DELETE_EVENT]: self.destroy() return [] actions = [] luksdev = None raidmembers = [] migrate = None model = self.raidlist.get_model() iter = model.get_iter_first() format = None while iter: val = model.get_value(iter, 0) part = model.get_value(iter, 1) if val: dev = self.storage.devicetree.getDeviceByName(part) raidmembers.append(dev) iter = model.iter_next(iter) # The user has to select some devices to be part of the array. if not raidmembers: continue mountpoint = self.mountCombo.get_children()[0].get_text() (sensitive,) = self.mountCombo.get_properties('sensitive') if sensitive and mountpoint: msg = sanityCheckMountPoint(mountpoint) if msg: self.intf.messageWindow(_("Mount Point Error"), msg, custom_icon="error") self.dialog.present() continue used = False for (mp, dev) in self.storage.mountpoints.iteritems(): if mp == mountpoint and \ dev.id != self.origrequest.id and \ not (self.origrequest.format.type == "luks" and self.origrequest in dev.parents): used = True break if used: self.intf.messageWindow(_("Mount point in use"), _("The mount point \"%s\" is in " "use. Please pick another.") % (mountpoint,), custom_icon="error") self.dialog.present() continue if not self.origrequest.exists: # new device fmt_class = self.fstypeCombo.get_active_value() raidminor = int(self.minorCombo.get_active_value()) model = self.levelcombo.get_model() raidlevel = model[self.levelcombo.get_active()][0] if not mdraidlib.isRaid(mdraidlib.RAID0, raidlevel): self.sparesb.update() spares = self.sparesb.get_value_as_int() else: spares = 0 format = fmt_class(mountpoint=mountpoint) members = len(raidmembers) - spares try: request = self.storage.newMDArray(minor=raidminor, level=raidlevel, format=format, parents=raidmembers, totalDevices=len(raidmembers), memberDevices=members) except ValueError, e: self.intf.messageWindow(_("Error"), str(e), custom_icon="error") self.dialog.present() continue # we must destroy luks leaf before original raid request if self.origrequest.format.type == "luks": # => not self.isNew # destroy luks format and mapped device # XXX remove catching, it should always succeed try: luksdev = self.storage.devicetree.getChildren(self.origrequest)[0] except IndexError: pass else: actions.append(ActionDestroyFormat(luksdev)) actions.append(ActionDestroyDevice(luksdev)) luksdev = None if self.lukscb and self.lukscb.get_active(): luksdev = LUKSDevice("luks-%s" % request.name, format=format, parents=request) format = getFormat("luks", passphrase=self.storage.encryptionPassphrase) request.format = format elif self.lukscb and not self.lukscb.get_active() and \ self.origrequest.format.type == "luks": # XXXRV not needed as we destroy origrequest ? actions.append(ActionDestroyFormat(self.origrequest)) if not self.isNew: # This may be handled in devicetree.registerAction, # but not in case when we change minor and thus # device name/path (at least with current md) actions.append(ActionDestroyDevice(self.origrequest)) actions.append(ActionCreateDevice(request)) actions.append(ActionCreateFormat(request)) else: # existing device fmt_class = self.fsoptionsDict["fstypeCombo"].get_active_value() if self.fsoptionsDict.has_key("formatcb") and \ self.fsoptionsDict["formatcb"].get_active(): format = fmt_class(mountpoint=mountpoint) if self.fsoptionsDict.has_key("lukscb") and \ self.fsoptionsDict["lukscb"].get_active() and \ (self.origrequest.format.type != "luks" or (self.origrequest.format.exists and not self.origrequest.format.hasKey)): luksdev = LUKSDevice("luks-%s" % self.origrequest.name, format=format, parents=self.origrequest) format = getFormat("luks", device=self.origrequest.path, passphrase=self.storage.encryptionPassphrase) elif self.fsoptionsDict.has_key("lukscb") and \ not self.fsoptionsDict["lukscb"].get_active() and \ self.origrequest.format.type == "luks": # destroy luks format and mapped device try: luksdev = self.storage.devicetree.getChildren(self.origrequest)[0] except IndexError: pass else: actions.append(ActionDestroyFormat(luksdev)) actions.append(ActionDestroyDevice(luksdev)) luksdev = None actions.append(ActionDestroyFormat(self.origrequest)) elif self.fsoptionsDict.has_key("formatcb") and \ not self.fsoptionsDict["formatcb"].get_active(): # if the format checkbutton is inactive, cancel all # actions on this device that create or destroy formats devicetree = self.storage.devicetree request = self.origrequest cancel = [] if request.originalFormat.type == "luks": path = "/dev/mapper/luks-%s" % request.originalFormat.uuid cancel.extend(devicetree.findActions(path=path)) cancel.extend(devicetree.findActions(type="destroy", object="format", devid=request.id)) cancel.extend(devicetree.findActions(type="create", object="format", devid=request.id)) for action in cancel: devicetree.cancelAction(action) # even though we cancelled a bunch of actions, it's # pretty much impossible to be sure we cancelled them # in the correct order. make sure things are back to # their original state. request.format = request.originalFormat if request.format.type == "luks": try: usedev = devicetree.getChildren(request)[0] except IndexError: usedev = request else: usedev.format = usedev.originalFormat else: usedev = request if usedev.format.mountable: usedev.format.mountpoint = mountpoint if self.origrequest.format.mountable: self.origrequest.format.mountpoint = mountpoint if self.fsoptionsDict.has_key("migratecb") and \ self.fsoptionsDict["migratecb"].get_active(): if self.origrequest.format.type == "luks": try: usedev = self.storage.devicetree.getChildren(self.origrequest)[0] except IndexError: usedev = self.origrequest else: usedev = self.origrequest migrate = True if self.origrequest.format.exists and not format and \ self.storage.formatByDefault(self.origrequest): if not queryNoFormatPreExisting(self.intf): continue if format: actions.append(ActionCreateFormat(self.origrequest, format)) # everything ok, break out break
def run(self): if self.dialog is None: return [] while 1: rc = self.dialog.run() # user hit cancel, do nothing if rc in [2, gtk.RESPONSE_DELETE_EVENT]: self.destroy() return [] actions = [] luksdev = None raidmembers = [] migrate = None model = self.raidlist.get_model() iter = model.get_iter_first() format = None while iter: val = model.get_value(iter, 0) part = model.get_value(iter, 1) if val: dev = self.storage.devicetree.getDeviceByName(part) raidmembers.append(dev) iter = model.iter_next(iter) # The user has to select some devices to be part of the array. if not raidmembers: continue mountpoint = self.mountCombo.get_children()[0].get_text() if mountpoint == _("<Not Applicable>"): mountpoint = "" if mountpoint: used = False for (mp, dev) in self.storage.mountpoints.iteritems(): if mp == mountpoint and \ dev.id != self.origrequest.id and \ not (self.origrequest.format.type == "luks" and self.origrequest in dev.parents): used = True break if used: self.intf.messageWindow(_("Mount point in use"), _("The mount point \"%s\" is in " "use. Please pick another.") % (mountpoint,), custom_icon="error") continue if not self.origrequest.exists: # new device fmt_class = self.fstypeCombo.get_active_value() raidminor = int(self.minorCombo.get_active_value()) model = self.levelcombo.get_model() raidlevel = model[self.levelcombo.get_active()][0] if not mdraidlib.isRaid(mdraidlib.RAID0, raidlevel): self.sparesb.update() spares = self.sparesb.get_value_as_int() else: spares = 0 format = fmt_class(mountpoint=mountpoint) members = len(raidmembers) - spares try: request = self.storage.newMDArray(minor=raidminor, level=raidlevel, format=format, parents=raidmembers, totalDevices=len(raidmembers), memberDevices=members) except ValueError, e: self.intf.messageWindow(_("Error"), str(e), custom_icon="error") continue # we must destroy luks leaf before original raid request if self.origrequest.format.type == "luks": # => not self.isNew # destroy luks format and mapped device # XXX remove catching, it should always succeed try: luksdev = self.storage.devicetree.getChildren(self.origrequest)[0] except IndexError: pass else: actions.append(ActionDestroyFormat(luksdev)) actions.append(ActionDestroyDevice(luksdev)) luksdev = None if self.lukscb and self.lukscb.get_active(): luksdev = LUKSDevice("luks-%s" % request.name, format=format, parents=request) format = getFormat("luks", passphrase=self.storage.encryptionPassphrase) request.format = format elif self.lukscb and not self.lukscb.get_active() and \ self.origrequest.format.type == "luks": # XXXRV not needed as we destroy origrequest ? actions.append(ActionDestroyFormat(self.origrequest)) if not self.isNew: # This may be handled in devicetree.registerAction, # but not in case when we change minor and thus # device name/path (at least with current md) actions.append(ActionDestroyDevice(self.origrequest)) actions.append(ActionCreateDevice(request)) actions.append(ActionCreateFormat(request)) else: # existing device fmt_class = self.fsoptionsDict["fstypeCombo"].get_active_value() if self.fsoptionsDict.has_key("formatcb") and \ self.fsoptionsDict["formatcb"].get_active(): format = fmt_class(mountpoint=mountpoint) if self.fsoptionsDict.has_key("lukscb") and \ self.fsoptionsDict["lukscb"].get_active() and \ (self.origrequest.format.type != "luks" or (self.origrequest.format.exists and not self.origrequest.format.hasKey)): luksdev = LUKSDevice("luks-%s" % self.origrequest.name, format=format, parents=self.origrequest) format = getFormat("luks", device=self.origrequest.path, passphrase=self.storage.encryptionPassphrase) elif self.fsoptionsDict.has_key("lukscb") and \ not self.fsoptionsDict["lukscb"].get_active() and \ self.origrequest.format.type == "luks": # destroy luks format and mapped device try: luksdev = self.storage.devicetree.getChildren(self.origrequest)[0] except IndexError: pass else: actions.append(ActionDestroyFormat(luksdev)) actions.append(ActionDestroyDevice(luksdev)) luksdev = None actions.append(ActionDestroyFormat(self.origrequest)) elif self.fsoptionsDict.has_key("formatcb") and \ not self.fsoptionsDict["formatcb"].get_active(): # if the format checkbutton is inactive, cancel all # actions on this device that create or destroy formats devicetree = self.storage.devicetree request = self.origrequest cancel = [] if request.originalFormat.type == "luks": path = "/dev/mapper/luks-%s" % request.originalFormat.uuid cancel.extend(devicetree.findActions(path=path)) cancel.extend(devicetree.findActions(type="destroy", object="format", devid=request.id)) cancel.extend(devicetree.findActions(type="create", object="format", devid=request.id)) for action in cancel: devicetree.cancelAction(action) # even though we cancelled a bunch of actions, it's # pretty much impossible to be sure we cancelled them # in the correct order. make sure things are back to # their original state. request.format = request.originalFormat if request.format.type == "luks": try: usedev = devicetree.getChildren(request)[0] except IndexError: usedev = request else: usedev.format = usedev.originalFormat else: usedev = request if usedev.format.mountable: usedev.format.mountpoint = mountpoint if self.origrequest.format.mountable: self.origrequest.format.mountpoint = mountpoint if self.fsoptionsDict.has_key("migratecb") and \ self.fsoptionsDict["migratecb"].get_active(): if self.origrequest.format.type == "luks": try: usedev = self.storage.devicetree.getChildren(self.origrequest)[0] except IndexError: usedev = self.origrequest else: usedev = self.origrequest migrate = True if self.origrequest.format.exists and not format and \ self.storage.formatByDefault(self.origrequest): if not queryNoFormatPreExisting(self.intf): continue if format: actions.append(ActionCreateFormat(self.origrequest, format)) # everything ok, break out break