X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=source%2Fsteps%2FInstallWriteConfig.py;h=a0dfac526259943dfa74adc46ad6999576b70873;hb=f79098df1d4acd219916038b8c9fcf2ec8f3bf01;hp=d7fddcc6df594d8672b525a956bdf4ae53639a52;hpb=7ab7e9dd797333a9fdc8604554e16e192a32144d;p=bootmanager.git diff --git a/source/steps/InstallWriteConfig.py b/source/steps/InstallWriteConfig.py index d7fddcc..a0dfac5 100644 --- a/source/steps/InstallWriteConfig.py +++ b/source/steps/InstallWriteConfig.py @@ -46,7 +46,7 @@ from Exceptions import * import utils from systeminfo import systeminfo import BootAPI - +import ModelOptions def Run( vars, log ): @@ -153,38 +153,8 @@ def Run( vars, log ): # if the network modules are activated in a different order that the # boot cd. log.write( "Writing /etc/modprobe.conf\n" ) - - sysinfo= systeminfo() - sysmods= sysinfo.get_system_modules(SYSIMG_PATH) - if sysmods is None: - raise BootManagerException, "Unable to get list of system modules." - - eth_count= 0 - scsi_count= 0 - - modulesconf_file= file("%s/etc/modprobe.conf" % SYSIMG_PATH, "w" ) - - for type in sysmods: - if type == sysinfo.MODULE_CLASS_SCSI: - for a_mod in sysmods[type]: - if scsi_count == 0: - modulesconf_file.write( "alias scsi_hostadapter %s\n" % - a_mod ) - else: - modulesconf_file.write( "alias scsi_hostadapter%d %s\n" % - (scsi_count,a_mod) ) - scsi_count= scsi_count + 1 - - elif type == sysinfo.MODULE_CLASS_NETWORK: - for a_mod in sysmods[type]: - modulesconf_file.write( "alias eth%d %s\n" % - (eth_count,a_mod) ) - eth_count= eth_count + 1 - - modulesconf_file.close() - modulesconf_file= None - - + write_modprobeconf_file( vars, log ) + # dump the modprobe.conf file to the log (not to screen) log.write( "Contents of new modprobe.conf file:\n" ) modulesconf_file= file("%s/etc/modprobe.conf" % SYSIMG_PATH, "r" ) @@ -205,7 +175,8 @@ def Run( vars, log ): fstab.write( "none /proc proc defaults 0 0\n" ) fstab.write( "none /dev/shm tmpfs defaults 0 0\n" ) fstab.write( "none /dev/pts devpts defaults 0 0\n" ) - fstab.write( "none /rcfs rcfs defaults 0 0\n" ) + # no longer needed + # fstab.write( "none /rcfs rcfs defaults 0 0\n" ) fstab.close() @@ -249,20 +220,19 @@ def Run( vars, log ): log.write( "Making initrd\n" ) # trick mkinitrd in case the current environment does not have device mapper - fake_root_lvm= 0 + fake_root_lvm= False if not os.path.exists( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) ): - fake_root_lvm= 1 + fake_root_lvm= True utils.makedirs( "%s/dev/mapper" % SYSIMG_PATH ) rootdev= file( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]), "w" ) rootdev.close() - utils.sysexec( "chroot %s sh -c '" \ - "kernelversion=`ls /lib/modules | tail -1` && " \ - "rm -f /boot/initrd-$kernelversion.img && " \ - "mkinitrd /boot/initrd-$kernelversion.img $kernelversion'" % \ - SYSIMG_PATH, log ) + initrd, kernel_version= getKernelVersion(vars,log) + utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) ) + utils.sysexec( "chroot %s mkinitrd /boot/initrd-%s.img %s" % \ + (SYSIMG_PATH, kernel_version, kernel_version), log ) - if fake_root_lvm == 1: + if fake_root_lvm == True: utils.removefile( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) ) log.write( "Writing node install version\n" ) @@ -356,6 +326,7 @@ def write_network_configuration( vars, log ): network= network_settings['network'] netmask= network_settings['netmask'] dns1= network_settings['dns1'] + mac= network_settings['mac'] except KeyError, e: raise BootManagerException, "Missing value %s in network settings." % str(e) @@ -387,6 +358,8 @@ def write_network_configuration( vars, log ): else: eth0_file.write( "BOOTPROTO=dhcp\n" ) eth0_file.write( "DHCP_HOSTNAME=%s\n" % hostname ) + if mac != "": + eth0_file.write( "HWADDR=%s\n" % mac ) eth0_file.write( "ONBOOT=yes\n" ) eth0_file.write( "USERCTL=no\n" ) eth0_file.close() @@ -412,3 +385,90 @@ def write_network_configuration( vars, log ): network_file.close() network_file= None + + +def write_modprobeconf_file( vars, log, filename = "/etc/modprobe.conf"): + """ + write out the system file /etc/modprobe.conf with the current + set of modules. + + returns a tuple of the number of network driver lines and storage + driver lines written as (networkcount,storagecount) + """ + + # make sure we have this class loaded + from systeminfo import systeminfo + + try: + SYSIMG_PATH= vars["SYSIMG_PATH"] + if SYSIMG_PATH == "": + raise ValueError, "SYSIMG_PATH" + + except KeyError, var: + raise BootManagerException, "Missing variable in vars: %s\n" % var + except ValueError, var: + raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var + + initrd, kernel_version= getKernelVersion(vars,log) + sysinfo= systeminfo() + sysmods= sysinfo.get_system_modules(SYSIMG_PATH, kernel_version) + if sysmods is None: + raise BootManagerException, "Unable to get list of system modules." + + eth_count= 0 + scsi_count= 0 + + modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "w" ) + + for type in sysmods: + if type == sysinfo.MODULE_CLASS_SCSI: + for a_mod in sysmods[type]: + if scsi_count == 0: + modulesconf_file.write( "alias scsi_hostadapter %s\n" % + a_mod ) + else: + modulesconf_file.write( "alias scsi_hostadapter%d %s\n" % + (scsi_count,a_mod) ) + scsi_count= scsi_count + 1 + + elif type == sysinfo.MODULE_CLASS_NETWORK: + for a_mod in sysmods[type]: + modulesconf_file.write( "alias eth%d %s\n" % + (eth_count,a_mod) ) + eth_count= eth_count + 1 + + modulesconf_file.close() + modulesconf_file= None + + return (eth_count,scsi_count) + +def getKernelVersion( vars, log): + # make sure we have the variables we need + try: + SYSIMG_PATH= vars["SYSIMG_PATH"] + if SYSIMG_PATH == "": + raise ValueError, "SYSIMG_PATH" + + NODE_MODEL_OPTIONS=vars["NODE_MODEL_OPTIONS"] + except KeyError, var: + raise BootManagerException, "Missing variable in vars: %s\n" % var + except ValueError, var: + raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var + + option = '' + if NODE_MODEL_OPTIONS & ModelOptions.SMP: + option = 'smp' + try: + os.stat("%s/boot/kernel-boot%s" % (SYSIMG_PATH,option)) + os.stat("%s/boot/initrd-boot%s" % (SYSIMG_PATH,option)) + except OSError, e: + # smp kernel is not there; remove option from modeloptions + # such that the rest of the code base thinks we are just + # using the base kernel. + NODE_MODEL_OPTIONS = NODE_MODEL_OPTIONS & ~ModelOptions.SMP + vars["NODE_MODEL_OPTIONS"] = NODE_MODEL_OPTIONS + log.write( "WARNING: Couldn't locate smp kernel.\n") + option = '' + initrd= os.readlink( "%s/boot/initrd-boot%s" % (SYSIMG_PATH,option) ) + kernel_version= initrd.replace("initrd-", "").replace(".img", "") + return (initrd, kernel_version)