def create_volume(devices, label=None, data=None, metadata=None, progress=None): """ For now, data and metadata must be strings mkfs.btrfs understands. """ if not devices: raise ValueError("no devices specified") elif any([not os.path.exists(d) for d in devices]): raise ValueError("one or more specified devices not present") args = [] if data: args.append("--data=%s" % data) if metadata: args.append("--metadata=%s" % metadata) if label: args.append("--label=%s" % label) args.extend(devices) ret = iutil.execWithPulseProgress("mkfs.btrfs", args, stdout="/dev/tty5", stderr="/dev/tty5", progress=progress) if ret.rc: raise BTRFSError(ret.stderr) return ret
def lvm(args, progress=None): ret = iutil.execWithPulseProgress("lvm", args, stdout = "/dev/tty5", stderr = "/dev/tty5", progress=progress) if ret.rc: raise LVMError(ret.stderr)
def mdadm(args, progress=None): ret = iutil.execWithPulseProgress("mdadm", args, stdout = "/dev/tty5", stderr = "/dev/tty5", progress=progress) if ret.rc: raise MDRaidError(ret.stderr)
def dm_setup(args, progress=None): ret = iutil.execWithPulseProgress("dmsetup", args, stdout = "/dev/tty5", stderr = "/dev/tty5", progress=progress) if ret.rc: raise DMError(ret.stderr)
def lvm(args, progress=None): ret = iutil.execWithPulseProgress("lvm", args, stdout="/dev/tty5", stderr="/dev/tty5", progress=progress) if ret.rc: raise LVMError(ret.stderr)
def doCheck(self, intf=None): if not self.exists: raise FSError("filesystem has not been created") if not self.fsckProg: return if not os.path.exists(self.device): raise FSError("device does not exist") w = None if intf: w = intf.progressWindow(_("Checking"), _("Checking filesystem on %s") % (self.device), 100, pulse=True) try: ret = iutil.execWithPulseProgress(self.fsckProg, self._getCheckArgs(), stdout="/dev/tty5", stderr="/dev/tty5", progress=w) except Exception as e: raise FSError("filesystem check failed: %s" % e) finally: if w: w.pop() if self._fsckFailed(ret.rc): hdr = _("%(type)s filesystem check failure on %(device)s: ") % \ {"type": self.type, "device": self.device} msg = self._fsckErrorMessage(ret.rc) if intf: help = _("Errors like this usually mean there is a problem " "with the filesystem that will require user " "interaction to repair. Before restarting " "installation, reboot to rescue mode or another " "system that allows you to repair the filesystem " "interactively. Restart installation after you " "have corrected the problems on the filesystem.") intf.messageWindow(_("Unrecoverable Error"), hdr + "\n\n" + msg + "\n\n" + help, custom_icon='error') sys.exit(0) else: raise FSError(hdr + msg)
def doCheck(self, intf=None): if not self.exists: raise FSError("filesystem has not been created") if not self.fsckProg: return if not os.path.exists(self.device): raise FSError("device does not exist") w = None if intf: w = intf.progressWindow(_("Checking"), _("Checking filesystem on %s") % (self.device), 100, pulse = True) try: ret = iutil.execWithPulseProgress(self.fsckProg, self._getCheckArgs(), stdout="/dev/tty5", stderr="/dev/tty5", progress = w) except Exception as e: raise FSError("filesystem check failed: %s" % e) finally: if w: w.pop() if self._fsckFailed(ret.rc): hdr = _("%(type)s filesystem check failure on %(device)s: ") % \ {"type": self.type, "device": self.device} msg = self._fsckErrorMessage(ret.rc) if intf: help = _("Errors like this usually mean there is a problem " "with the filesystem that will require user " "interaction to repair. Before restarting " "installation, reboot to rescue mode or another " "system that allows you to repair the filesystem " "interactively. Restart installation after you " "have corrected the problems on the filesystem.") intf.messageWindow(_("Unrecoverable Error"), hdr + "\n\n" + msg + "\n\n" + help, custom_icon='error') sys.exit(0) else: raise FSError(hdr + msg)
def mkswap(device, label='', progress=None): # We use -f to force since mkswap tends to refuse creation on lvs with # a message about erasing bootbits sectors on whole disks. Bah. argv = ["-f"] if label: argv.extend(["-L", label]) argv.append(device) ret = iutil.execWithPulseProgress("mkswap", argv, stderr = "/dev/tty5", stdout = "/dev/tty5", progress=progress) if ret.rc: raise SwapError("mkswap failed for '%s'" % device)
def mkswap(device, label='', progress=None): # We use -f to force since mkswap tends to refuse creation on lvs with # a message about erasing bootbits sectors on whole disks. Bah. argv = ["-f"] if label: argv.extend(["-L", label]) argv.append(device) ret = iutil.execWithPulseProgress("mkswap", argv, stderr="/dev/tty5", stdout="/dev/tty5", progress=progress) if ret.rc: raise SwapError("mkswap failed for '%s'" % device)
def startup(self, intf, exclusiveDisks, zeroMbr): """ Look for any unformatted DASDs in the system and offer the user the option for format them with dasdfmt or exit the installer. """ if self.started: return self.started = True out = "/dev/tty5" err = "/dev/tty5" if not iutil.isS390(): return log.info("Checking for unformatted DASD devices:") for device in os.listdir("/sys/block"): if not device.startswith("dasd"): continue statusfile = "/sys/block/%s/device/status" % (device,) if not os.path.isfile(statusfile): continue f = open(statusfile, "r") status = f.read().strip() f.close() if status in ["unformatted"] and device not in exclusiveDisks: bypath = deviceNameToDiskByPath(device) if not bypath: bypath = "/dev/" + device log.info(" %s (%s) status is %s, needs dasdfmt" % (device, bypath, status,)) self._dasdlist.append((device, bypath)) if not len(self._dasdlist): log.info(" no unformatted DASD devices found") return askUser = True if zeroMbr: askUser = False elif not intf and not zeroMbr: log.info(" non-interactive kickstart install without zerombr " "command, unable to run dasdfmt, exiting installer") sys.exit(0) c = len(self._dasdlist) if intf and askUser: devs = '' for dasd, bypath in self._dasdlist: devs += "%s\n" % (bypath,) rc = intf.questionInitializeDASD(c, devs) if rc == 1: log.info(" not running dasdfmt, continuing installation") return # gather total cylinder count argv = ["-t", "-v"] + self.commonArgv for dasd, bypath in self._dasdlist: buf = iutil.execWithCapture(self.dasdfmt, argv + ["/dev/" + dasd], stderr=err) for line in buf.splitlines(): if line.startswith("Drive Geometry: "): # line will look like this: # Drive Geometry: 3339 Cylinders * 15 Heads = 50085 Tracks cyls = long(filter(lambda s: s, line.split(' '))[2]) self.totalCylinders += cyls break # format DASDs argv = ["-P"] + self.commonArgv update = self._updateProgressWindow title = P_("Formatting DASD Device", "Formatting DASD Devices", c) msg = P_("Preparing %d DASD device for use with Linux..." % c, "Preparing %d DASD devices for use with Linux..." % c, c) if intf: if self.totalCylinders: pw = intf.progressWindow(title, msg, 1.0) else: pw = intf.progressWindow(title, msg, 100, pulse=True) for dasd, bypath in self._dasdlist: log.info("Running dasdfmt on %s" % (bypath,)) arglist = argv + ["/dev/" + dasd] try: if intf and self.totalCylinders: ret = iutil.execWithCallback(self.dasdfmt, arglist, stdout=out, stderr=err, callback=update, callback_data=pw, echo=False) rc = ret.rc elif intf: ret = iutil.execWithPulseProgress(self.dasdfmt, arglist, stdout=out, stderr=err, progress=pw) rc = ret.rc else: rc = iutil.execWithRedirect(self.dasdfmt, arglist, stdout=out, stderr=err) except Exception as e: raise DasdFormatError(e, bypath) if rc: raise DasdFormatError("dasdfmt failed: %s" % rc, bypath) if intf: pw.pop()
def doResize(self, *args, **kwargs): """ Resize this filesystem to new size @newsize. Arguments: None Keyword Arguments: intf -- InstallInterface instance """ intf = kwargs.get("intf") if not self.exists: raise FSResizeError("filesystem does not exist", self.device) if not self.resizable: raise FSResizeError("filesystem not resizable", self.device) if self.targetSize == self.currentSize: return if not self.resizefsProg: return if not os.path.exists(self.device): raise FSResizeError("device does not exist", self.device) self.doCheck(intf=intf) # The first minimum size can be incorrect if the fs was not # properly unmounted. After doCheck the minimum size will be correct # so run the check one last time and bump up the size if it was too # small. self._minInstanceSize = None if self.targetSize < self.minSize: self.targetSize = self.minSize log.info("Minimum size changed, setting targetSize on %s to %s" \ % (self.device, self.targetSize)) w = None if intf: w = intf.progressWindow(_("Resizing"), _("Resizing filesystem on %s") % (self.device, ), 100, pulse=True) try: ret = iutil.execWithPulseProgress(self.resizefsProg, self.resizeArgs, stdout="/dev/tty5", stderr="/dev/tty5", progress=w) except Exception as e: raise FSResizeError(e, self.device) finally: if w: w.pop() if ret.rc: raise FSResizeError("resize failed: %s" % ret.rc, self.device) self.doCheck(intf=intf) # XXX must be a smarter way to do this self._size = self.targetSize self.notifyKernel()
def doFormat(self, *args, **kwargs): """ Create the filesystem. Arguments: None Keyword Arguments: intf -- InstallInterface instance options -- list of options to pass to mkfs """ log_method_call(self, type=self.mountType, device=self.device, mountpoint=self.mountpoint) intf = kwargs.get("intf") options = kwargs.get("options") if self.exists: raise FormatCreateError("filesystem already exists", self.device) if not self.formattable: return if not self.mkfsProg: return if self.exists: return if not os.path.exists(self.device): raise FormatCreateError("device does not exist", self.device) argv = self._getFormatOptions(options=options) w = None if intf: w = intf.progressWindow( _("Formatting"), _("Creating %(type)s filesystem on %(device)s") % { "type": self.type, "device": self.device }, 100, pulse=True) try: ret = iutil.execWithPulseProgress(self.mkfsProg, argv, stdout="/dev/tty5", stderr="/dev/tty5", progress=w) except Exception as e: raise FormatCreateError(e, self.device) finally: if w: w.pop() if ret.rc: raise FormatCreateError("format failed: %s" % ret.rc, self.device) self.exists = True self.notifyKernel() if self.label: self.writeLabel(self.label)
def doResize(self, *args, **kwargs): """ Resize this filesystem to new size @newsize. Arguments: None Keyword Arguments: intf -- InstallInterface instance """ intf = kwargs.get("intf") if not self.exists: raise FSResizeError("filesystem does not exist", self.device) if not self.resizable: raise FSResizeError("filesystem not resizable", self.device) if self.targetSize == self.currentSize: return if not self.resizefsProg: return if not os.path.exists(self.device): raise FSResizeError("device does not exist", self.device) self.doCheck(intf=intf) # The first minimum size can be incorrect if the fs was not # properly unmounted. After doCheck the minimum size will be correct # so run the check one last time and bump up the size if it was too # small. self._minInstanceSize = None if self.targetSize < self.minSize: self.targetSize = self.minSize log.info("Minimum size changed, setting targetSize on %s to %s" \ % (self.device, self.targetSize)) w = None if intf: w = intf.progressWindow(_("Resizing"), _("Resizing filesystem on %s") % (self.device,), 100, pulse = True) try: ret = iutil.execWithPulseProgress(self.resizefsProg, self.resizeArgs, stdout="/dev/tty5", stderr="/dev/tty5", progress=w) except Exception as e: raise FSResizeError(e, self.device) finally: if w: w.pop() if ret.rc: raise FSResizeError("resize failed: %s" % ret.rc, self.device) self.doCheck(intf=intf) # XXX must be a smarter way to do this self._size = self.targetSize self.notifyKernel()
def doFormat(self, *args, **kwargs): """ Create the filesystem. Arguments: None Keyword Arguments: intf -- InstallInterface instance options -- list of options to pass to mkfs """ log_method_call(self, type=self.mountType, device=self.device, mountpoint=self.mountpoint) intf = kwargs.get("intf") options = kwargs.get("options") if self.exists: raise FormatCreateError("filesystem already exists", self.device) if not self.formattable: return if not self.mkfsProg: return if self.exists: return if not os.path.exists(self.device): raise FormatCreateError("device does not exist", self.device) argv = self._getFormatOptions(options=options) w = None if intf: w = intf.progressWindow(_("Formatting"), _("Creating %(type)s filesystem on %(device)s") % {"type": self.type, "device": self.device}, 100, pulse = True) try: ret = iutil.execWithPulseProgress(self.mkfsProg, argv, stdout="/dev/tty5", stderr="/dev/tty5", progress=w) except Exception as e: raise FormatCreateError(e, self.device) finally: if w: w.pop() if ret.rc: raise FormatCreateError("format failed: %s" % ret.rc, self.device) self.exists = True self.notifyKernel() if self.label: self.writeLabel(self.label)
def startup(self, intf, exclusiveDisks, zeroMbr): """ Look for any unformatted DASDs in the system and offer the user the option for format them with dasdfmt or exit the installer. """ if self.started: return self.started = True out = "/dev/tty5" err = "/dev/tty5" if not iutil.isS390(): return log.info("Checking for unformatted DASD devices:") for device in os.listdir("/sys/block"): if not device.startswith("dasd"): continue statusfile = "/sys/block/%s/device/status" % (device, ) if not os.path.isfile(statusfile): continue f = open(statusfile, "r") status = f.read().strip() f.close() if status in ["unformatted"] and device not in exclusiveDisks: bypath = deviceNameToDiskByPath(device) if not bypath: bypath = "/dev/" + device log.info(" %s (%s) status is %s, needs dasdfmt" % ( device, bypath, status, )) self._dasdlist.append((device, bypath)) if not len(self._dasdlist): log.info(" no unformatted DASD devices found") return askUser = True if zeroMbr: askUser = False elif not intf and not zeroMbr: log.info(" non-interactive kickstart install without zerombr " "command, unable to run dasdfmt, exiting installer") sys.exit(0) c = len(self._dasdlist) if intf and askUser: devs = '' for dasd, bypath in self._dasdlist: devs += "%s\n" % (bypath, ) rc = intf.questionInitializeDASD(c, devs) if rc == 1: log.info(" not running dasdfmt, continuing installation") return # gather total cylinder count argv = ["-t", "-v"] + self.commonArgv for dasd, bypath in self._dasdlist: buf = iutil.execWithCapture(self.dasdfmt, argv + ["/dev/" + dasd], stderr=err) for line in buf.splitlines(): if line.startswith("Drive Geometry: "): # line will look like this: # Drive Geometry: 3339 Cylinders * 15 Heads = 50085 Tracks cyls = long(filter(lambda s: s, line.split(' '))[2]) self.totalCylinders += cyls break # format DASDs argv = ["-P"] + self.commonArgv update = self._updateProgressWindow title = P_("Formatting DASD Device", "Formatting DASD Devices", c) msg = P_("Preparing %d DASD device for use with Linux..." % c, "Preparing %d DASD devices for use with Linux..." % c, c) if intf: if self.totalCylinders: pw = intf.progressWindow(title, msg, 1.0) else: pw = intf.progressWindow(title, msg, 100, pulse=True) for dasd, bypath in self._dasdlist: log.info("Running dasdfmt on %s" % (bypath, )) arglist = argv + ["/dev/" + dasd] try: if intf and self.totalCylinders: ret = iutil.execWithCallback(self.dasdfmt, arglist, stdout=out, stderr=err, callback=update, callback_data=pw, echo=False) rc = ret.rc elif intf: ret = iutil.execWithPulseProgress(self.dasdfmt, arglist, stdout=out, stderr=err, progress=pw) rc = ret.rc else: rc = iutil.execWithRedirect(self.dasdfmt, arglist, stdout=out, stderr=err) except Exception as e: raise DasdFormatError(e, bypath) if rc: raise DasdFormatError("dasdfmt failed: %s" % rc, bypath) if intf: pw.pop()