- # this is the actual data structure we return
- system_mods= {}
-
- # these are the lists that will be in system_mods
- network_mods= []
- scsi_mods= []
-
-
- # get all the system devices from lspci
- lspci_prog= popen2.Popen3( self.LSPCI_CMD, 1 )
- if lspci_prog is None:
- print( "Unable to run %s with popen2.Popen3" % self.LSPCI_CMD )
- return
-
- returncode= lspci_prog.wait()
- if returncode != 0:
- print( "Running %s failed" % self.LSPCI_CMD )
- return
- else:
- print( "Successfully ran %s" % self.LSPCI_CMD )
-
- for line in lspci_prog.fromchild:
- if string.strip(line) == "":
- continue
-
- parts= string.split(line)
-
- try:
- classid= self.remove_quotes(parts[2])
- vendorid= self.remove_quotes(parts[3])
- deviceid= self.remove_quotes(parts[4])
- except IndexError:
- print( "Skipping invalid line:", string.strip(line) )
- continue
-
- if classid not in (self.PCI_CLASS_NETWORK,
- self.PCI_CLASS_RAID,
- self.PCI_CLASS_RAID2):
- continue
-
- full_deviceid= "%s:%s" % (vendorid,deviceid)
-
- for module in all_modules.keys():
- if full_deviceid in all_modules[module]:
- if classid == self.PCI_CLASS_NETWORK:
- network_mods.append(module)
- elif classid in (self.PCI_CLASS_RAID,
- self.PCI_CLASS_RAID2):
- scsi_mods.append(module)
-
- system_mods[self.MODULE_CLASS_SCSI]= scsi_mods
- system_mods[self.MODULE_CLASS_NETWORK]= network_mods
+ print( "Using kernel version %s" % kernel_version )
+
+ # test to make sure the file we need is present
+ modules_pcimap_path = "%s/lib/modules/%s/modules.pcimap" % \
+ (SYSIMG_PATH,kernel_version)
+ if not os.access(modules_pcimap_path,os.R_OK):
+ print( "WARNING: Unable to read %s" % modules_pcimap_path )
+ return
+
+ pcimap = pypcimap.PCIMap(modules_pcimap_path)
+
+ # this is the actual data structure we return
+ system_mods= {}
+
+ # these are the lists that will be in system_mods
+ network_mods= []
+ scsi_mods= []
+
+ # XXX: this is really similar to what BootCD/conf_files/pl_hwinit does. merge?
+ pcidevs = get_devices()
+
+ devlist=pcidevs.keys()
+ devlist.sort()
+ for slot in devlist:
+ dev = pcidevs[slot]
+ base = (dev[4] & 0xff0000) >> 16
+ if base not in (PCI_BASE_CLASS_STORAGE,
+ PCI_BASE_CLASS_NETWORK):
+ continue
+
+ modules = pcimap.get(dev)
+ if len(modules) > 0:
+ if base == PCI_BASE_CLASS_NETWORK:
+ network_mods += modules
+ elif base == PCI_BASE_CLASS_STORAGE:
+ scsi_mods += modules
+
+ system_mods[MODULE_CLASS_SCSI]= scsi_mods
+ system_mods[MODULE_CLASS_NETWORK]= network_mods
+
+ return system_mods
+
+
+def getKernelVersion( vars = {} , log = sys.stderr):
+ # 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 = ''
+ try:
+ initrd= os.readlink( "%s/boot/initrd-boot%s" % (SYSIMG_PATH,option) )
+ kernel_version= initrd.replace("initrd-", "").replace(".img", "")
+ except OSError, e:
+ initrd = None
+ kernel_version = None