'/usr/local/planetlab/bin')
+# the set of valid node run states
+NodeRunStates = {}
class log:
VARS_FILE = "configuration"
- def __init__(self, log):
+ def __init__(self, log, forceState):
+ # override machine's current state from the command line
+ self.forceState = forceState
+
# this contains a set of information used and updated
# by each step
self.VARS= {}
UpdateBootStateWithPLC.Run( self.VARS, self.LOG )
StartDebug.Run( self.VARS, self.LOG )
+ global NodeRunStates
# setup state -> function hash table
- states = {'new':_newRun,
- 'inst':_newRun,
- 'rins':_rinsRun,
- 'boot':_bootRun,
- 'dbg':_debugRun}
+ NodeRunStates['new'] = _newRun
+ NodeRunStates['inst'] = _newRun
+ NodeRunStates['rins'] = _rinsRun
+ NodeRunStates['boot'] = _bootRun
+ NodeRunStates['dbg'] = _debugRun
+
try:
InitializeBootManager.Run( self.VARS, self.LOG )
ReadNodeConfiguration.Run( self.VARS, self.LOG )
AuthenticateWithPLC.Run( self.VARS, self.LOG )
GetAndUpdateNodeDetails.Run( self.VARS, self.LOG )
- stateRun = states.get(self.VARS['BOOT_STATE'],_badRun)
+ # override machine's current state from the command line
+ if self.forceState is not None:
+ self.VARS['BOOT_STATE']= self.forceState
+ UpdateBootStateWithPLC.Run( self.VARS, self.LOG )
+
+ stateRun = NodeRunStates.get(self.VARS['BOOT_STATE'],_badRun)
stateRun()
except KeyError, e:
SendHardwareConfigToPLC.Run( self.VARS, self.LOG )
-
-if __name__ == "__main__":
-
- # set to 0 if no error occurred
- error= 1
+def main(argv):
+ global NodeRunStates
+ NodeRunStates = {'new':None,
+ 'inst':None,
+ 'rins':None,
+ 'boot':None,
+ 'dbg':None}
+
+ # set to 1 if error occurred
+ error= 0
# all output goes through this class so we can save it and post
# the data back to PlanetLab central
strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()) )
try:
- bm= BootManager(LOG)
+ forceState = None
+ if len(argv) == 2:
+ fState = argv[1]
+ if NodeRunStates.has_key(fState):
+ forceState = fState
+ else:
+ LOG.LogEntry("FATAL: cannot force node run state to=%s" % fState)
+ error = 1
+ except:
+ traceback.print_exc(file=LOG.OutputFile)
+ traceback.print_exc()
+
+ if error:
+ LOG.LogEntry( "BootManager finished at: %s" % \
+ strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()) )
+ LOG.Upload()
+ return error
+
+ try:
+ bm= BootManager(LOG,forceState)
if bm.CAN_RUN == 0:
LOG.LogEntry( "Unable to initialize BootManager." )
else:
LOG.LogEntry( "\nDone!" );
else:
LOG.LogEntry( "\nError occurred!" );
-
+ error = 1
except:
traceback.print_exc(file=LOG.OutputFile)
traceback.print_exc()
LOG.LogEntry( "BootManager finished at: %s" % \
strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()) )
-
LOG.Upload()
+
+ return error
+
+if __name__ == "__main__":
+ error = main(sys.argv)
sys.exit(error)
import BootAPI
import notify_messages
-from GetAndUpdateNodeDetails import SMP_OPT
-
+import ModelOptions
def Run( vars, log ):
"""
# get the kernel version
option = ''
- if NODE_MODEL_OPTIONS & SMP_OPT:
+ if NODE_MODEL_OPTIONS & ModelOptions.SMP:
option = 'smp'
log.write( "Copying kernel and initrd for booting.\n" )
kargs = "root=/dev/mapper/planetlab-root ramdisk_size=8192"
+ if NODE_MODEL_OPTIONS & ModelOptions.SMP:
+ kargs = kargs + " " + "acpi=off"
try:
kargsfb = open("/kargs.txt","r")
moreargs = kargsfb.readline()
from Exceptions import *
import BootAPI
-
-MINHW_OPT = 0x001
-SMP_OPT = 0x002
-X86_64_OPT = 0x004
-INTEL_OPT = 0x008
-AMD_OPT = 0x010
-NUMA_OPT = 0x020
-LAST_OPT = 0x040
-
-modeloptions = {'smp':SMP_OPT,
- 'x64':X86_64_OPT,
- 'i64':X86_64_OPT|INTEL_OPT,
- 'a64':X86_64_OPT|AMD_OPT,
- 'i32':INTEL_OPT,
- 'a32':AMD_OPT,
- 'numa':NUMA_OPT,
- 'minhw':MINHW_OPT}
+import ModelOptions
def Run( vars, log ):
"""
# parse in the model options from the node_model string
model= vars['NODE_MODEL']
- modelinfo = string.split(model,'/')
- options= 0
- for mi in modelinfo:
- info = string.strip(mi)
- info = info.lower()
- options = options | modeloptions.get(info,0)
-
- print "node model options = %d" % options
+ options= ModelOptions.Get(model)
vars['NODE_MODEL_OPTIONS']=options
- # if the end of NODE_MODEL string contains the minhw string, skip hardware
- # requirement checks (overrides configuration)
- if options & MINHW_OPT:
+ # Check if we should skip hardware requirement check
+ if options & ModelOptions.MINHW:
vars['SKIP_HARDWARE_REQUIREMENT_CHECK']=1
log.write( "node model indicates override to hardware requirements.\n" )
file(SYSIMG_PATH + "/usr/boot/boot_server", "w").write(boot_server)
shutil.copy("/usr/bootme/pubring.gpg", SYSIMG_PATH + "/usr/boot/pubring.gpg")
+ # For backward compatibility
+ if os.path.exists("/usr/bootme"):
+ utils.makedirs(SYSIMG_PATH + "/mnt/cdrom")
+ shutil.copytree("/usr/bootme", SYSIMG_PATH + "/mnt/cdrom/bootme")
+
# Import the GPG key into the RPM database so that RPMS can be verified
utils.makedirs(SYSIMG_PATH + "/etc/pki/rpm-gpg")
utils.sysexec("gpg --homedir=/root --export --armor" \
import BootServerRequest
import compatibility
-
+import ModelOptions
def Run( vars, log ):
"""
if BOOT_CD_VERSION == "":
raise ValueError, "BOOT_CD_VERSION"
+ NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
+
except KeyError, var:
raise BootManagerException, "Missing variable in vars: %s\n" % var
except ValueError, var:
# make swap
utils.sysexec( "mkswap %s" % PARTITIONS["swap"], log )
- # make root file system
- utils.sysexec( "mkfs.ext2 -j %s" % PARTITIONS["root"], log )
-
- # make vservers file system
- utils.sysexec( "mkfs.ext2 -m 0 -j %s" % PARTITIONS["vservers"], log )
+ # check if badhd option has been set
+ option = ''
+ txt = ''
+ if NODE_MODEL_OPTIONS & ModelOptions.BADHD:
+ option = '-c'
+ txt = " with bad block search enabled, which may take a while"
+
+ # filesystems partitions names and their corresponding
+ # reserved-blocks-percentages
+ filesystems = {"root":5,"vservers":0}
+
+ # make the file systems
+ for fs in filesystems.keys():
+ # get the reserved blocks percentage
+ rbp = filesystems[fs]
+ devname = PARTITIONS[fs]
+ log.write("formatting %s partition (%s)%s.\n" % (fs,devname,txt))
+ utils.sysexec( "mkfs.ext2 -q %s -m %d -j %s" % (option,rbp,devname), log )
# save the list of block devices in the log
log.write( "Block devices used (in lvm):\n" )
import utils
from systeminfo import systeminfo
import BootAPI
-
-from GetAndUpdateNodeDetails import SMP_OPT
+import ModelOptions
def Run( vars, log ):
if BOOT_CD_VERSION == "":
raise ValueError, "BOOT_CD_VERSION"
- NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
-
except KeyError, var:
raise BootManagerException, "Missing variable in vars: %s\n" % var
except ValueError, var:
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()
- option = ''
- if NODE_MODEL_OPTIONS & SMP_OPT:
- option = 'smp'
- initrd= os.readlink( "%s/boot/initrd-boot%s" % (SYSIMG_PATH,option) )
- kernel_version= initrd.replace("initrd-", "").replace(".img", "")
+ 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" )
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
-
- # get the kernel version
- option = ''
- if NODE_MODEL_OPTIONS & SMP_OPT:
- option = 'smp'
- initrd= os.readlink( "%s/boot/initrd-boot%s" % (SYSIMG_PATH,option) )
- kernel_version= initrd.replace("initrd-", "").replace(".img", "")
-
+ initrd, kernel_version= getKernelVersion(vars,log)
sysinfo= systeminfo()
sysmods= sysinfo.get_system_modules(SYSIMG_PATH, kernel_version)
if sysmods is 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)
import utils
from systeminfo import systeminfo
import compatibility
-from GetAndUpdateNodeDetails import SMP_OPT
+import ModelOptions
def Run( vars, log ):
vars['ROOT_MOUNTED']= 1
- # get the kernel version
- option = ''
- if NODE_MODEL_OPTIONS & SMP_OPT:
- option = 'smp'
-
- files = ("kernel-boot%s" % option, "initrd-boot%s" % option)
- valid= 1
- for filepath in files:
- if not os.access("%s/boot/%s"%(SYSIMG_PATH,filepath),os.F_OK|os.R_OK):
- log.write( "Node not properly installed:\n")
- log.write( "\tmissing file /boot/%s\n" % filepath )
- valid= 0
-
- if not valid:
+ # check if the base kernel is installed
+ try:
+ os.stat("%s/boot/kernel-boot" % SYSIMG_PATH)
+ os.stat("%s/boot/initrd-boot" % SYSIMG_PATH)
+ except OSError, e:
+ log.write( "FATAL: Couldn't locate base kernel.\n")
return 0
+ # check if the model specified kernel is installed
+ 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")
+
# write out the node id to /etc/planetlab/node_id. if this fails, return
# 0, indicating the node isn't a valid install.
try:
node_id_file.write( str(NODE_ID) )
node_id_file.close()
node_id_file= None
- log.write( "Updated /etc/planetlab/node_id" )
+ log.write( "Updated /etc/planetlab/node_id\n" )
except IOError, e:
- log.write( "Unable to write out /etc/planetlab/node_id" )
+ log.write( "Unable to write out /etc/planetlab/node_id\n" )
return 0
log.write( "Everything appears to be ok\n" )