def write(self): args = [] if not selinux_states.has_key(self.selinux): log.error("unknown selinux state: %s" %(self.selinux,)) return args = args + [ "--selinux=%s" %(selinux_states[self.selinux],) ] try: iutil.execWithRedirect("/usr/sbin/lokkit", args, root=ROOT_PATH, stdout="/dev/null", stderr="/dev/null") except (RuntimeError, OSError) as msg: log.error ("lokkit run failed: %s" %(msg,)) args = ["--update", "--nostart"] + shlex.split(self.auth) if self._addFingerprint(): args += ["--enablefingerprint"] try: iutil.execWithRedirect("/usr/sbin/authconfig", args, stdout = "/dev/tty5", stderr = "/dev/tty5", root=ROOT_PATH) except RuntimeError as msg: log.error("Error running %s: %s", args, msg)
def set_hostname(hn): if flags.imageInstall: log.info("image install -- not setting hostname") return log.info("setting installation environment hostname to %s" % hn) iutil.execWithRedirect("hostname", [hn])
def _startLldpad(self): if self.lldpadStarted: return iutil.execWithRedirect("lldpad", [ "-d" ], stdout = "/dev/tty5", stderr="/dev/tty5") self.lldpadStarted = True
def udev_get_block_devices(): # Wait for scsi adapters to be done with scanning their busses (#583143) iutil.execWithRedirect("modprobe", ["scsi_wait_scan"], stdout="/dev/tty5", stderr="/dev/tty5") iutil.execWithRedirect("rmmod", ["scsi_wait_scan"], stdout="/dev/tty5", stderr="/dev/tty5") udev_settle() entries = [] for path in udev_enumerate_block_devices(): entry = udev_get_block_device(path) if entry: if entry["name"].startswith("md"): # mdraid is really braindead, when a device is stopped # it is no longer usefull in anyway (and we should not # probe it) yet it still sticks around, see bug rh523387 state = None state_file = "/sys/%s/md/array_state" % entry["sysfs_path"] if os.access(state_file, os.R_OK): state = open(state_file).read().strip() if state == "clear": continue entries.append(entry) return entries
def restoreTime(anaconda): """Load time setup for upgrade install. We need to find out the timezone and the UTC parameter of the old system and set the system time accordingly, so timestamps are set correctly for the files the upgrade procedure will create. This is pretty much what packages.setupTimezone() does in reverse. """ if anaconda.dir == DISPATCH_BACK: return if os.environ.has_key("TZ"): del os.environ["TZ"] copyFromSysimage(anaconda.rootPath, '/etc/localtime') copyFromSysimage(anaconda.rootPath, '/etc/adjtime') if iutil.isS390(): return args = ["--hctosys"] try: iutil.execWithRedirect("/sbin/hwclock", args, stdout="/dev/tty5", stderr="/dev/tty5") except RuntimeError: log.error("Failed to set the clock.")
def turnOnFilesystems(anaconda): if anaconda.dir == DISPATCH_BACK: if not anaconda.id.upgrade: log.info("unmounting filesystems") anaconda.id.storage.umountFilesystems() return DISPATCH_NOOP if not anaconda.id.upgrade: if not anaconda.id.storage.fsset.active: # turn off any swaps that we didn't turn on # needed for live installs iutil.execWithRedirect("swapoff", ["-a"], stdout="/dev/tty5", stderr="/dev/tty5") anaconda.id.storage.devicetree.teardownAll() upgrade_migrate = False if anaconda.id.upgrade: for d in anaconda.id.storage.migratableDevices: if d.format.migrate: upgrade_migrate = True title = None message = None details = None try: anaconda.id.storage.doIt() except DeviceResizeError as (msg, device): # XXX does this make any sense? do we support resize of # devices other than partitions? title = _("Device Resize Failed") message = _("An error was encountered while " "resizing device %s.") % (device, ) details = msg
def vgactivate(volgroup=None): """Activate volume groups by running vgchange -ay. volgroup - optional single volume group to activate """ global lvmDevicePresent if flags.test or lvmDevicePresent == 0: return args = ["lvm", "vgchange", "-ay"] if volgroup: args.append(volgroup) rc = iutil.execWithRedirect(args[0], args, stdout=output, stderr=output, searchPath=1) if rc: log("running vgchange failed: %s. disabling lvm" % (rc, )) lvmDevicePresent = 0 # now make the device nodes args = ["lvm", "vgmknodes"] if volgroup: args.append(volgroup) rc = iutil.execWithRedirect(args[0], args, stdout=output, stderr=output, searchPath=1) if rc: log("running vgmknodes failed: %s. disabling lvm" % (rc, )) lvmDevicePresent = 0
def pvremove(pvname): # Check that device is PV args = ["pvdisplay", pvname] log.info(string.join(args, ' ')) rc = iutil.execWithRedirect("lvm", args, stdout=output, stderr=output, searchPath=1) if rc: # No LVM metadata found on partition return args = ["pvremove", "-ff", "-y", "-v", pvname] log.info(string.join(args, ' ')) rc = iutil.execWithRedirect("lvm", args, stdout=output, stderr=output, searchPath=1) if rc: raise SystemError, "pvremove failed for %s" % (pvname, )
def _startFcoemon(self): if self.fcoemonStarted: return iutil.execWithRedirect("fcoemon", [ ], stdout = "/dev/tty5", stderr="/dev/tty5") self.fcoemonStarted = True
def setupTimezone(anaconda): # we don't need this on an upgrade or going backwards if anaconda.id.upgrade or anaconda.dir == DISPATCH_BACK: return os.environ["TZ"] = anaconda.id.timezone.tz tzfile = "/usr/share/zoneinfo/" + anaconda.id.timezone.tz tzlocalfile = "/etc/localtime" if not os.access(tzfile, os.R_OK): log.error("unable to set timezone") else: try: os.remove(tzlocalfile) except OSError: pass try: shutil.copyfile(tzfile, tzlocalfile) except OSError as e: log.error("Error copying timezone (from %s): %s" % (tzfile, e.strerror)) if iutil.isS390(): return args = ["--hctosys"] if anaconda.id.timezone.utc: args.append("-u") try: iutil.execWithRedirect("/usr/sbin/hwclock", args, stdin=None, stdout="/dev/tty5", stderr="/dev/tty5") except RuntimeError: log.error("Failed to set clock")
def write(self): self.writeXdriver() self.instLanguage.write(self.rootPath) self.timezone.write(self.rootPath) self.network.write() self.network.copyConfigToPath(instPath=self.rootPath) self.network.disableNMForStorageDevices(self, instPath=self.rootPath) self.desktop.write(self.rootPath) self.users.write(self.rootPath) self.security.write(self.rootPath) self.firewall.write(self.rootPath) services = list(self.storage.services) if self.ksdata: for svc in self.ksdata.services.disabled: iutil.execWithRedirect("/sbin/chkconfig", [svc, "off"], stdout="/dev/tty5", stderr="/dev/tty5", root=self.rootPath) services.extend(self.ksdata.services.enabled) for svc in services: iutil.execWithRedirect("/sbin/chkconfig", [svc, "on"], stdout="/dev/tty5", stderr="/dev/tty5", root=self.rootPath)
def vgactivate(volgroup = None): """Activate volume groups by running vgchange -ay. volgroup - optional single volume group to activate """ global lvmDevicePresent if flags.test or lvmDevicePresent == 0: return args = ["vgchange", "-ay"] if volgroup: args.append(volgroup) rc = iutil.execWithRedirect("lvm", args, stdout = output, stderr = output, searchPath = 1) if rc: log.error("running vgchange failed: %s" %(rc,)) # lvmDevicePresent = 0 # now make the device nodes args = ["vgmknodes"] if volgroup: args.append(volgroup) rc = iutil.execWithRedirect("lvm", args, stdout = output, stderr = output, searchPath = 1) if rc: log.error("running vgmknodes failed: %s" %(rc,))
def write(self): self.writeXdriver() self.instLanguage.write() self.timezone.write() if not self.ksdata: self.instClass.setNetworkOnbootDefault(self.network) self.network.write() self.network.copyConfigToPath() self.network.disableNMForStorageDevices(self) self.network.autostartFCoEDevices(self) self.desktop.write() self.users.write() self.security.write() self.firewall.write() services = list(self.storage.services) if self.ksdata: for svc in self.ksdata.services.disabled: iutil.execWithRedirect("/sbin/chkconfig", [svc, "off"], stdout="/dev/tty5", stderr="/dev/tty5", root=ROOT_PATH) services.extend(self.ksdata.services.enabled) for svc in services: iutil.execWithRedirect("/sbin/chkconfig", [svc, "on"], stdout="/dev/tty5", stderr="/dev/tty5", root=ROOT_PATH)
def setupTimezone(anaconda): # we don't need this on an upgrade or going backwards if anaconda.upgrade or anaconda.dir == DISPATCH_BACK: return os.environ["TZ"] = anaconda.timezone.tz tzfile = "/usr/share/zoneinfo/" + anaconda.timezone.tz tzlocalfile = "/etc/localtime" if not os.access(tzfile, os.R_OK): log.error("unable to set timezone") else: try: os.remove(tzlocalfile) except OSError: pass try: shutil.copyfile(tzfile, tzlocalfile) except OSError as e: log.error("Error copying timezone (from %s): %s" %(tzfile, e.strerror)) if iutil.isS390(): return args = [ "--hctosys" ] if anaconda.timezone.utc: args.append("-u") try: iutil.execWithRedirect("/sbin/hwclock", args, stdin = None, stdout = "/dev/tty5", stderr = "/dev/tty5") except RuntimeError: log.error("Failed to set clock")
def udev_settle(): # wait maximal 300 seconds for udev to be done running blkid, lvm, # mdadm etc. This large timeout is needed when running on machines with # lots of disks, or with slow disks argv = ["settle", "--timeout=300"] iutil.execWithRedirect("udevadm", argv, stderr="/dev/null")
def turnOnFilesystems(anaconda): if anaconda.dir == DISPATCH_BACK: if not anaconda.id.upgrade: log.info("unmounting filesystems") anaconda.id.storage.umountFilesystems() return DISPATCH_NOOP if not anaconda.id.upgrade: if not anaconda.id.storage.fsset.active: # turn off any swaps that we didn't turn on # needed for live installs iutil.execWithRedirect("swapoff", ["-a"], stdout = "/dev/tty5", stderr="/dev/tty5") anaconda.id.storage.devicetree.teardownAll() upgrade_migrate = False if anaconda.id.upgrade: for d in anaconda.id.storage.migratableDevices: if d.format.migrate: upgrade_migrate = True title = None message = None details = None try: anaconda.id.storage.doIt() except DeviceResizeError as (msg, device): # XXX does this make any sense? do we support resize of # devices other than partitions? title = _("Device Resize Failed") message = _("An error was encountered while " "resizing device %s.") % (device,) details = msg
def vgremove(vgname): """Removes a volume group. Deactivates the volume group first vgname - name of volume group. """ global lvmDevicePresent if flags.test or lvmDevicePresent == 0: return # find the Physical Volumes which make up this Volume Group, so we # can prune and recreate them. pvs = [] for pv in pvlist(): if pv[1] == vgname: pvs.append(pv[0]) # we'll try to deactivate... if it fails, we'll probably fail on # the removal too... but it's worth a shot try: vgdeactivate(vgname) except: pass args = ["vgreduce", "-v", "--removemissing", "--force", vgname] log.info(string.join(args, ' ')) rc = iutil.execWithRedirect("lvm", args, stdout = output, stderr = output, searchPath = 1) if rc: raise SystemError, "vgreduce failed" args = ["vgremove", "-v", vgname] log.info(string.join(args, ' ')) rc = iutil.execWithRedirect("lvm", args, stdout = output, stderr = output, searchPath = 1) if rc: raise SystemError, "vgremove failed" # now iterate all the PVs we've just freed up, so we reclaim the metadata # space. This is an LVM bug, AFAICS. for pvname in pvs: args = ["pvremove", "-ff", "-y", "-v", pvname] log.info(string.join(args, ' ')) rc = iutil.execWithRedirect("lvm", args, stdout = output, stderr = output, searchPath = 1) if rc: raise SystemError, "pvremove failed" args = ["pvcreate", "-ff", "-y", "-v", pvname] log.info(string.join(args, ' ')) rc = iutil.execWithRedirect("lvm", args, stdout = output, stderr = output, searchPath = 1) if rc: raise SystemError, "pvcreate failed for %s" % (pvname,)
def has_fcoe(): global _fcoe_module_loaded if not _fcoe_module_loaded: iutil.execWithRedirect("modprobe", [ "fcoe" ], stdout = "/dev/tty5", stderr="/dev/tty5") _fcoe_module_loaded = True return os.access("/sys/module/fcoe", os.X_OK)
def updateSysClock(self): args = ["--hctosys"] if self.c.selected(): args.append("--utc") iutil.execWithRedirect("hwclock", args) self.g.setTimer(500) self.updateClock()
def udev_trigger(subsystem=None, action="add", name=None): argv = ["trigger", "--action=%s" % action] if subsystem: argv.append("--subsystem-match=%s" % subsystem) if name: argv.append("--sysname-match=%s" % name) iutil.execWithRedirect("udevadm", argv, stderr="/dev/null")
def _startFcoemon(self): if self.fcoemonStarted: return iutil.execWithRedirect("fcoemon", [], stdout="/dev/tty5", stderr="/dev/tty5") self.fcoemonStarted = True
def recreateInitrd(kernelTag, instRoot): log.info("recreating initrd for %s" % (kernelTag, )) iutil.execWithRedirect( "/sbin/new-kernel-pkg", ["--mkinitrd", "--dracut", "--depmod", "--update", kernelTag], stdout="/dev/null", stderr="/dev/null", root=instRoot)
def recreateInitrd(kernelTag, instRoot): log.info("recreating initrd for %s" % (kernelTag, )) iutil.execWithRedirect("/sbin/new-kernel-pkg", ["--mkinitrd", "--depmod", "--install", kernelTag], stdout=None, stderr=None, searchPath=1, root=instRoot)
def setHostname(self, hn): self.hostname = hn if flags.imageInstall: log.info("image install -- not setting hostname") return log.info("setting installation environment hostname to %s" % hn) iutil.execWithRedirect("hostname", ["-v", hn ], stdout="/dev/tty5", stderr="/dev/tty5")
def recreateInitrd(kernelTag, instRoot): log.info("recreating initrd for %s" % (kernelTag,)) iutil.execWithRedirect( "/sbin/new-kernel-pkg", ["--mkinitrd", "--dracut", "--depmod", "--install", kernelTag], stdout="/dev/null", stderr="/dev/null", root=instRoot, )
def copyExceptionToFloppy(anaconda): # in test mode have save to floppy option just copy to new name if not flags.setupFilesystems: try: shutil.copyfile("/tmp/anacdump.txt", "/tmp/test-anacdump.txt") except: log.error("Failed to copy anacdump.txt to /tmp/test-anacdump.txt") pass anaconda.intf.__del__() return 2 while 1: # Bail if they hit the cancel button. rc = anaconda.intf.dumpWindow() if rc: return 1 device = anaconda.id.floppyDevice file = "/tmp/floppy" try: isys.makeDevInode(device, file) except SystemError: pass try: fd = os.open(file, os.O_RDONLY) except: continue os.close(fd) if rhpl.getArch() != "ia64": cmd = "/usr/sbin/mkdosfs" if os.access("/sbin/mkdosfs", os.X_OK): cmd = "/sbin/mkdosfs" iutil.execWithRedirect(cmd, ["/tmp/floppy"], stdout='/dev/tty5', stderr='/dev/tty5') try: isys.mount(device, "/tmp/crash", fstype="vfat") except SystemError: continue # copy trace dump we wrote to local storage to floppy try: shutil.copyfile("/tmp/anacdump.txt", "/tmp/crash/anacdump.txt") except: log.error("Failed to copy anacdump.txt to floppy") return 2 isys.umount("/tmp/crash") return 0
def setPassword(instPath, account, password, useMD5, alreadyCrypted = 0): if not alreadyCrypted: password = cryptPassword(password, useMD5) devnull = os.open("/dev/null", os.O_RDWR) argv = [ "/usr/sbin/usermod", "-p", password, account ] iutil.execWithRedirect(argv[0], argv, root = instPath, stdout = '/dev/null', stderr = None) os.close(devnull)
def copyExceptionToFloppy (anaconda): # in test mode have save to floppy option just copy to new name if not flags.setupFilesystems: try: shutil.copyfile("/tmp/anacdump.txt", "/tmp/test-anacdump.txt") except: log.error("Failed to copy anacdump.txt to /tmp/test-anacdump.txt") pass anaconda.intf.__del__ () return 2 while 1: # Bail if they hit the cancel button. rc = anaconda.intf.dumpWindow() if rc: return 1 device = anaconda.id.floppyDevice file = "/tmp/floppy" try: isys.makeDevInode(device, file) except SystemError: pass try: fd = os.open(file, os.O_RDONLY) except: continue os.close(fd) if rhpl.getArch() != "ia64": cmd = "/usr/sbin/mkdosfs" if os.access("/sbin/mkdosfs", os.X_OK): cmd = "/sbin/mkdosfs" iutil.execWithRedirect (cmd, ["/tmp/floppy"], stdout = '/dev/tty5', stderr = '/dev/tty5') try: isys.mount(device, "/tmp/crash", fstype = "vfat") except SystemError: continue # copy trace dump we wrote to local storage to floppy try: shutil.copyfile("/tmp/anacdump.txt", "/tmp/crash/anacdump.txt") except: log.error("Failed to copy anacdump.txt to floppy") return 2 isys.umount("/tmp/crash") return 0
def write (self, instPath): args = [ "--quiet", "--nostart", "-f" ] + self.getArgList() try: if not flags.test: iutil.execWithRedirect("/usr/sbin/lokkit", args, root=instPath, stdout=None, stderr=None) else: log.error("would have run %s", args) except RuntimeError, msg: log.error ("lokkit run failed: %s", msg)
def delete_interfaces(self): if not self.ifaces: return None for iscsi_iface_name in self.ifaces: #iscsiadm -m iface -I iface0 --op=delete iutil.execWithRedirect( "iscsiadm", ["-m", "iface", "-I", iscsi_iface_name, "--op=delete"], stdout="/dev/tty5", stderr="/dev/tty5") self.ifaces = {}
def _stabilize(self, intf = None): if intf: w = intf.waitWindow(_("Connecting to FCoE SAN"), _("Connecting to FCoE SAN")) # I have no clue how long we need to wait, this ought to do the trick time.sleep(10) iutil.execWithRedirect("udevadm", [ "settle" ], stdout = "/dev/tty5", stderr="/dev/tty5") if intf: w.pop()
def delete_interfaces(self): if not self.ifaces: return None for iscsi_iface_name in self.ifaces: #iscsiadm -m iface -I iface0 --op=delete iutil.execWithRedirect("iscsiadm", ["-m", "iface", "-I", iscsi_iface_name, "--op=delete"], stdout="/dev/tty5", stderr="/dev/tty5") self.ifaces = {}
def buildLocale(self): import iutil c = langComponents(self._instLang) locale_p = c["language"] if c["territory"]: locale_p += "_" + c["territory"] if c["modifier"]: locale_p += "@" + c["modifier"] iutil.execWithRedirect("localedef", ["-i", locale_p, "-f", c["codeset"] or "UTF-8", self._instLang])
def has_fcoe(): global _fcoe_module_loaded if not _fcoe_module_loaded: iutil.execWithRedirect("modprobe", [ "fcoe" ], stdout = "/dev/tty5", stderr="/dev/tty5") _fcoe_module_loaded = True if "bnx2x" in iutil.lsmod(): log.info("fcoe: loading bnx2fc") iutil.execWithRedirect("modprobe", [ "bnx2fc" ], stdout = "/dev/tty5", stderr="/dev/tty5") return os.access("/sys/module/fcoe", os.X_OK)
def write (self, instPath): args = [ "--quiet", "--nostart", "-f" ] + self.getArgList() try: if not os.path.exists("%s/etc/sysconfig/iptables" %(instPath,)): iutil.execWithRedirect("/usr/sbin/lokkit", args, root=instPath, stdout="/dev/null", stderr="/dev/null") else: log.error("would have run %s", args) except RuntimeError, msg: log.error ("lokkit run failed: %s", msg)
def updateSysClock(self): if os.access("/sbin/hwclock", os.X_OK): args = ["/sbin/hwclock"] else: args = ["/usr/sbin/hwclock"] args.append("--hctosys") if self.c.selected(): args.append("--utc") iutil.execWithRedirect(args[0], args) self.g.setTimer(500) self.updateClock()
def addSan(self, nic, dcb=False, intf=None): if not has_fcoe(): raise IOError, _("FCoE not available") log.info("Activating FCoE SAN attached to %s, dcb: %s" % (nic, dcb)) iutil.execWithRedirect("ip", [ "link", "set", nic, "up" ], stdout = "/dev/tty5", stderr="/dev/tty5") if dcb: self._startLldpad() iutil.execWithRedirect("dcbtool", [ "sc", nic, "dcb", "on" ], stdout = "/dev/tty5", stderr="/dev/tty5") iutil.execWithRedirect("dcbtool", [ "sc", nic, "app:fcoe", "e:1", "a:1", "w:1" ], stdout = "/dev/tty5", stderr="/dev/tty5") iutil.execWithRedirect("fipvlan", [ nic, "-c", "-s" ], stdout = "/dev/tty5", stderr="/dev/tty5") else: f = open("/sys/module/fcoe/parameters/create", "w") f.write(nic) f.close() self._stabilize(intf) self.nics.append((nic, dcb))
def write (self, instPath): args = [ "/usr/sbin/authconfig", "--kickstart", "--nostart" ] args = args + self.getArgList() try: if flags.setupFilesystems: iutil.execWithRedirect(args[0], args, stdout = None, stderr = None, searchPath = 1, root = instPath) else: log("Would have run %s", args) except RuntimeError, msg: log ("Error running %s: %s", args, msg)
def __call__(self, screen, diskset, partrequests, intf): choices = [] drives = diskset.disks.keys() drives.sort() for drive in drives: choices.append("%s" %(drive)) # close all references we had to the diskset diskset.closeDevices() button = None while button != "done" and button != "back": (button, choice) = \ ListboxChoiceWindow(screen, _("Disk Setup"), _("Choose a disk to run fdisk on"), choices, [ (_("OK"), "done"), (_("Edit"), "edit"), TEXT_BACK_BUTTON ], width = 50, help = "fdisk") if button != "done" and button != TEXT_BACK_CHECK: device = choices[choice] if os.access("/sbin/fdisk", os.X_OK): path = "/sbin/fdisk" else: path = "/usr/sbin/fdisk" try: isys.makeDevInode(device, '/tmp/' + device) except: pass screen.suspend() iutil.execWithRedirect (path, [ path, "/tmp/" + device ], ignoreTermSigs = 1) screen.resume() try: os.remove('/tmp/' + device) except: pass diskset.refreshDevices(intf) diskset.checkNoDisks(intf) partrequests.setFromDisk(diskset) if button == TEXT_BACK_CHECK: return INSTALL_BACK return INSTALL_OK
def write(self, instPath): args = ["--quiet", "--nostart", "-f"] + self.getArgList() try: if not flags.test: iutil.execWithRedirect("/usr/sbin/lokkit", args, root=instPath, stdout=None, stderr=None) else: log.error("would have run %s", args) except RuntimeError, msg: log.error("lokkit run failed: %s", msg)
def abiquo_upgrade_post(anaconda): schema_path = anaconda.rootPath + "/usr/share/doc/abiquo-server/database/kinton-latest-delta.sql" work_path = anaconda.rootPath + "/opt/abiquo/tomcat/work" temp_path = anaconda.rootPath + "/opt/abiquo/tomcat/temp" lvm_path = anaconda.rootPath + "/opt/abiquo/lvmiscsi" log.info("ABIQUO: Post install steps") # Clean tomcat if os.path.exists(work_path): log.info("ABIQUO: Cleaning work folder...") shutil.rmtree(work_path) if os.path.exists(temp_path): log.info("ABIQUO: Cleaning temp folder...") shutil.rmtree(temp_path) # Upgrade database if this is a server install if os.path.exists(schema_path): schema = open(schema_path) log.info("ABIQUO: Updating Abiquo database ...") iutil.execWithRedirect("/sbin/ifconfig", ['lo', 'up'], stdout="/mnt/sysimage/var/log/abiquo-postinst.log", stderr="/mnt/sysimage/var/log/abiquo-postinst.log", root=anaconda.rootPath) iutil.execWithRedirect("/etc/init.d/mysqld", ['start'], stdout="/mnt/sysimage/var/log/abiquo-postinst.log", stderr="//mnt/sysimage/var/log/abiquo-postinst.log", root=anaconda.rootPath) iutil.execWithRedirect("/usr/bin/mysql", ['kinton'], stdin=schema, stdout="/mnt/sysimage/var/log/abiquo-postinst.log", stderr="//mnt/sysimage/var/log/abiquo-postinst.log", root=anaconda.rootPath) schema.close() if os.path.exists(lvm_path): log.info("ABIQUO: Fixing lvmiscsi service...") iutil.execWithRedirect("/sbin/chkconfig", ['--add','abiquo-lvmiscsi'], stdout="/mnt/sysimage/var/log/abiquo-postinst.log", stderr="/mnt/sysimage/var/log/abiquo-postinst.log", root=anaconda.rootPath) iutil.execWithRedirect("/sbin/chkconfig", ['abiquo-lvmiscsi','on'], stdout="/mnt/sysimage/var/log/abiquo-postinst.log", stderr="/mnt/sysimage/var/log/abiquo-postinst.log", root=anaconda.rootPath) # restore fstab backup_dir = anaconda.rootPath + '/opt/abiquo/backup/2.2.0' if os.path.exists('%s/fstab.anaconda' % backup_dir): shutil.copyfile("%s/fstab.anaconda" % backup_dir, '%s/etc/fstab' % anaconda.rootPath)
def write(self, instPath): args = [] if not selinux_states.has_key(self.selinux): log.error("unknown selinux state: %s" %(self.selinux,)) return args = args + [ "--selinux=%s" %(selinux_states[self.selinux],) ] try: iutil.execWithRedirect("/usr/sbin/lokkit", args, root = instPath, stdout = "/dev/null", stderr = "/dev/null") except RuntimeError, msg: log.error ("lokkit run failed: %s" %(msg,))
def loadModule(self): """Load whatever kernel module is required to support this filesystem.""" global kernel_filesystems if not self._modules or self.mountType in kernel_filesystems: return for module in self._modules: try: rc = iutil.execWithRedirect("modprobe", [module], stdout="/dev/tty5", stderr="/dev/tty5") except Exception as e: log.error("Could not load kernel module %s: %s" % (module, e)) self._supported = False return if rc: log.error("Could not load kernel module %s" % module) self._supported = False return # If we successfully loaded a kernel module, for this filesystem, we # also need to update the list of supported filesystems. kernel_filesystems = get_kernel_filesystems()
def update_initrd(kernel_version,machine,uuid): hostinfo = kernel_version+machine flag = create_driver_src(hostinfo) if not flag: return False tmp_path,initrd_path = create_initrd_src(kernel_version,uuid) os.chdir(tmp_path) create_initrd_env(initrd_path) flag,newmods = cp_drivers(hostinfo) if flag and newmods: update_init_script(newmods) rc = iutil.execWithRedirect("/sbin/depmod", [ "-a"], stdout = "/dev/null", stderr = "/dev/null", root = tmp_path) if rc: print 'depmod failed' return os.chdir(tmp_path) create_initrd_dst(initrd_path,uuid)
def doMigrate(self, intf=None): if not self.exists: raise FSError("filesystem has not been created") if not self.migratable or not self.migrate: return if not os.path.exists(self.device): raise FSError("device does not exist") # if journal already exists skip if isys.ext2HasJournal(self.device): log.info("Skipping migration of %s, has a journal already." % self.device) return argv = self._defaultMigrateOptions[:] argv.append(self.device) try: rc = iutil.execWithRedirect(self.migratefsProg, argv, stdout="/dev/tty5", stderr="/dev/tty5") except Exception as e: raise FSMigrateError("filesystem migration failed: %s" % e, self.device) if rc: raise FSMigrateError("filesystem migration failed: %s" % rc, self.device) # the other option is to actually replace this instance with an # instance of the new filesystem type. self._type = self.migrationTarget
def swapoff(device): rc = iutil.execWithRedirect("swapoff", [device], stderr = "/dev/tty5", stdout = "/dev/tty5") if rc: raise SwapError("swapoff failed for '%s'" % device)
def doMigrate(self, intf=None): if not self.exists: raise FSError("filesystem has not been created") if not self.migratable or not self.migrate: return if not os.path.exists(self.device): raise FSError("device does not exist") # if journal already exists skip if isys.ext2HasJournal(self.device): log.info("Skipping migration of %s, has a journal already." % self.device) return argv = self._defaultMigrateOptions[:] argv.append(self.device) try: rc = iutil.execWithRedirect(self.migratefsProg, argv, stdout = "/dev/tty5", stderr = "/dev/tty5") except Exception as e: raise FSMigrateError("filesystem migration failed: %s" % e, self.device) if rc: raise FSMigrateError("filesystem migration failed: %s" % rc, self.device) # the other option is to actually replace this instance with an # instance of the new filesystem type. self._type = self.migrationTarget self._mountType = self.migrationTarget
def luks_add_key(device, new_passphrase=None, new_key_file=None, passphrase=None, key_file=None): params = ["-q"] p = os.pipe() if passphrase: os.write(p[1], "%s\n" % passphrase) elif key_file and os.path.isfile(key_file): params.extend(["--key-file", key_file]) else: raise CryptoError("luks_add_key requires either a passphrase or a key file") params.extend(["luksAddKey", device]) if new_passphrase: os.write(p[1], "%s\n" % new_passphrase) elif new_key_file and os.path.isfile(new_key_file): params.append("%s" % new_key_file) else: raise CryptoError("luks_add_key requires either a passphrase or a key file to add") os.close(p[1]) rc = iutil.execWithRedirect("cryptsetup", params, stdin = p[0], stdout = "/dev/tty5", stderr = "/dev/tty5") os.close(p[0]) if rc: raise CryptoError("luks add key failed with errcode %d" % (rc,))
def swapoff(device): rc = iutil.execWithRedirect("swapoff", [device], stderr="/dev/tty5", stdout="/dev/tty5") if rc: raise SwapError("swapoff failed for '%s'" % device)