# # backend.py: Interface for installation backends # # Paul Nasrat # Jeremy Katz # # Copyright (c) 2005 Red Hat, Inc. # # This software may be freely redistributed under the terms of the GNU # general public license. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # import shutil import iutil import os, sys import logging from syslogd import syslog from rhpl.translate import _ from flags import flags from fsset import devify log = logging.getLogger("anaconda") class AnacondaBackend: def __init__(self, method, instPath): """Abstract backend class all backends should inherit from this @param method: Object of InstallMethod type @param instPath: root path for the installation to occur""" self.method = method self.instPath = instPath self.instLog = None self.modeText = "" def doPreSelection(self, intf, id, instPath): pass def doPostSelection(self, anaconda): pass def doPreInstall(self, anaconda): pass def doPostInstall(self, anaconda): sys.stdout.flush() if flags.setupFilesystems: syslog.stop() # disable multipath boot features if system isn't using multipath if not flags.mpath: mpfile = self.instPath + "/etc/sysconfig/mkinitrd/multipath" leading = os.path.dirname(mpfile) if not os.path.isdir(leading): os.makedirs(leading, mode=0755) f = open(mpfile, "w") f.write("MULTIPATH=no\n") f.close() os.chmod(mpfile, 0755) # make sure /var/lib/multipath/bindings exists on final system bindings = '/var/lib/multipath/bindings' wwids = [] if flags.mpath and os.path.isfile(bindings): leading = self.instPath + os.path.dirname(bindings) if not os.path.isdir(leading): os.makedirs(leading, mode=0755) shutil.copy2(bindings, leading + '/bindings') # read in WWIDs per mpath device f = open(bindings, 'r') lines = map(lambda s: s[:-1], f.readlines()) f.close() for l in lines: if l.strip().startswith('mpath'): try: i = l.index(' ') wwid = l[i:].strip() wwids.append(wwid) except: pass # since all devices are blacklisted by default, add a # blacklist_exception block for the devices we want treated as # multipath devices --dcantrell (BZ #243527) mpconf = self.instPath + "/etc/multipath.conf" if flags.mpath: f = open(mpconf, "r") # remove newline from the end of each line mplines = map(lambda s: s[:-1], f.readlines()) f.close() f = open(mpconf, "w") blacklist = False depth = 0 for line in mplines: if line.strip().startswith('#'): f.write("%s\n" % (line,)) else: if blacklist: depth += line.count('{') depth -= line.count('}') f.write("#%s\n" % (line,)) if depth == 0: blacklist = False # write out the catch-all blacklist section to # blacklist all device types f.write('\nblacklist {\n') f.write(' devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"\n') f.write(' devnode "^hd[a-z]"\n') f.write(' wwid "*"\n') f.write('}\n') # write out the blacklist exceptions with # multipath WWIDs if wwids != []: f.write('\n# Make sure our multipath devices are enabled.\n') f.write('\nblacklist_exception {\n') for wwid in wwids: f.write(" wwid \"%s\"\n" % (wwid,)) f.write('}\n\n') else: if line.strip().startswith('blacklist'): depth += line.count('{') depth -= line.count('}') blacklist = True f.write("#%s\n" % (line,)) else: f.write("%s\n" % (line,)) # add mpath filters to /etc/lvm/lvm.conf (#243531) conf = self.instPath + '/etc/lvm/lvm.conf' if flags.mpath and os.path.isfile(conf): f = open(conf, 'w+') f.write('filter = [ "a|/dev/mpath|", "r|.*|" ]\n') f.close() def doInstall(self, anaconda): pass def initLog(self, id, instPath): upgrade = id.getUpgrade() if upgrade: logname = '/root/upgrade.log' else: logname = '/root/install.log' instLogName = instPath + logname try: shutil.rmtree (instLogName) except OSError: pass instLog = open(instLogName, "w+") if upgrade: logname = '/root/upgrade.log' else: logname = '/root/install.log' instLogName = instPath + logname try: shutil.rmtree (instLogName) except OSError: pass self.instLog = open(instLogName, "w+") # dont start syslogd if we arent creating filesystems if flags.setupFilesystems: syslogname = "%s%s.syslog" % (instPath, logname) try: shutil.rmtree (syslogname) except OSError: pass syslog.start (instPath, syslogname) else: syslogname = None if upgrade: self.modeText = _("Upgrading %s\n") else: self.modeText = _("Installing %s\n") def kernelVersionList(self): pass def doInitialSetup(self, anaconda): pass def doRepoSetup(self, anaconda): log.warning("doRepoSetup not implemented for backend!") pass def groupExists(self, group): log.warning("groupExists not implemented for backend!") pass def selectGroup(self, group, *args): log.warning("selectGroup not implemented for backend!") pass def deselectGroup(self, group, *args): log.warning("deselectGroup not implemented for backend!") pass def packageExists(self, pkg): log.warning("packageExists not implemented for backend!") pass def selectPackage(self, pkg, *args): log.warning("selectPackage not implemented for backend!") pass def deselectPackage(self, pkg, *args): log.warning("deselectPackage not implemented for backend!") pass def getDefaultGroups(self, anaconda): log.warning("getDefaultGroups not implemented for backend!") pass def writePackagesKS(self, f): log.warning("writePackagesKS not implemented for backend!") pass def writeConfiguration(self): log.warning("writeConfig not implemented for backend!") pass def doRepoSetup(anaconda): anaconda.backend.doInitialSetup(anaconda) anaconda.backend.doRepoSetup(anaconda) if anaconda.id.upgrade: anaconda.backend.checkSupportedUpgrade(anaconda) def doPostSelection(anaconda): return anaconda.backend.doPostSelection(anaconda) def doPreInstall(anaconda): anaconda.backend.doPreInstall(anaconda) def doPostInstall(anaconda): anaconda.backend.doPostInstall(anaconda) def doInstall(anaconda): anaconda.backend.doInstall(anaconda) # does this need to be per-backend? we'll just leave here until it does :) def doBasePackageSelect(anaconda): anaconda.id.instClass.setPackageSelection(anaconda) anaconda.id.instClass.setGroupSelection(anaconda) def writeConfiguration(anaconda): log.info("Writing main configuration") if not flags.test: anaconda.backend.writeConfiguration() anaconda.id.write(anaconda)