# Copyright (c) 2004-2006 The Trustees of Princeton University
# All rights reserved.
+from __future__ import print_function
+
import sys, os
import traceback
import string
VARS_FILE = "configuration"
# the new contents of PATH when the boot manager is running
-BIN_PATH= ('/usr/local/bin',
- '/usr/local/sbin',
- '/usr/bin',
- '/usr/sbin',
- '/bin',
- '/sbin')
+BIN_PATH = ('/usr/local/bin',
+ '/usr/local/sbin',
+ '/usr/bin',
+ '/usr/sbin',
+ '/bin',
+ '/sbin')
def read_configuration_file(filename):
# read in and store all variables in VARS_FILE into each line
if line[:1] == "#" or string.strip(line) == "":
continue
- parts = string.split(line,"=")
+ parts = string.split(line, "=")
if len(parts) != 2:
validConfFile = False
raise Exception("Invalid line in vars file: {}".format(line))
except Exception, e:
self.LogEntry(str(e))
return
-
+
def LogEntry(self, str, inc_newline = 1, display_screen = 1):
now = time.strftime(log.format, time.localtime())
if self.OutputFile:
self.OutputFile.write(now + str)
if display_screen:
sys.stdout.write(now + str)
-
+
if inc_newline:
if display_screen:
sys.stdout.write("\n")
def write(self, str):
"""
- make log behave like a writable file object (for traceback
- prints)
+ make log behave like a writable file object
+ (for traceback prints)
"""
self.LogEntry(str, 0, 1)
-
+
def print_stack(self):
"""
dump current stack in log
self.OutputFile.flush()
self.LogEntry("Uploading logs to {}".format(self.VARS['UPLOAD_LOG_SCRIPT']))
-
+
self.OutputFile.close()
- self.OutputFile= None
+ self.OutputFile = None
hostname = self.VARS['INTERFACE_SETTINGS']['hostname'] + "." + \
self.VARS['INTERFACE_SETTINGS']['domainname']
GetVars = None, PostVars = None,
DoSSL = True, DoCertCheck = True,
FormData = ["log=@" + self.OutputFilePath,
- "hostname=" + hostname,
+ "hostname=" + hostname,
"type=bm.log"])
except:
# new pycurl
("hostname",hostname),
("type","bm.log")])
if extra_file is not None:
- # NOTE: for code-reuse, evoke the bash function 'upload_logs';
+ # NOTE: for code-reuse, evoke the bash function 'upload_logs';
# by adding --login, bash reads .bash_profile before execution.
# Also, never fail, since this is an optional feature.
utils.sysexec_noerr("""bash --login -c "upload_logs {}" """.format(extra_file), self)
'safeboot' : None,
'disabled' : None,
}
-
+
def __init__(self, log, forceState):
# override machine's current state from the command line
self.forceState = forceState
self.VARS = log.VARS
else:
return
-
+
# not sure what the current PATH is set to, replace it with what
# we know will work with all the boot cds
os.environ['PATH'] = string.join(BIN_PATH,":")
# then finally chain boots.
# starting the fallback/debug ssh daemon for safety:
- # if the node install somehow hangs, or if it simply takes ages,
+ # if the node install somehow hangs, or if it simply takes ages,
# we can still enter and investigate
try:
StartDebug.Run(self.VARS, self.LOG, last_resort = False)
except:
pass
- InstallInit.Run(self.VARS, self.LOG)
+ InstallInit.Run(self.VARS, self.LOG)
ret = ValidateNodeInstall.Run(self.VARS, self.LOG)
if ret == 1:
# Thierry - feb. 2013 turning off WriteModprobeConfig for now on lxc
def _reinstallRun(upgrade=False):
# starting the fallback/debug ssh daemon for safety:
- # if the node install somehow hangs, or if it simply takes ages,
+ # if the node install somehow hangs, or if it simply takes ages,
# we can still enter and investigate
try:
StartDebug.Run(self.VARS, self.LOG, last_resort = False)
# 'boot' state and chainboot into the production system
if not CheckHardwareRequirements.Run(self.VARS, self.LOG):
self.VARS['RUN_LEVEL'] = 'failboot'
- raise BootManagerException, "Hardware requirements not met."
+ raise BootManagerException("Hardware requirements not met.")
# runinstaller
- InstallInit.Run(self.VARS, self.LOG)
+ InstallInit.Run(self.VARS, self.LOG)
+ # do not erase disks in upgrade mode
if not upgrade:
- InstallPartitionDisks.Run(self.VARS, self.LOG)
- InstallBootstrapFS.Run(self.VARS, self.LOG)
+ InstallPartitionDisks.Run(self.VARS, self.LOG)
+ # pass upgrade boolean to this step so we can do extra cleanup
+ InstallBootstrapFS.Run(self.VARS, upgrade, self.LOG)
InstallWriteConfig.Run(self.VARS, self.LOG)
InstallUninitHardware.Run(self.VARS, self.LOG)
self.VARS['BOOT_STATE'] = 'boot'
AnsibleHook.Run(self.VARS, self.LOG)
UpdateBootStateWithPLC.Run(self.VARS, self.LOG)
_bootRun()
-
+
def _installRun():
# implements the new install logic, which will first check
# with the user whether it is ok to install on this
except KeyError as e:
self.LOG.write("\n\nKeyError while running: {}\n".format(e))
- self.LOG.print_stack ()
+ self.LOG.print_stack()
except BootManagerException as e:
self.LOG.write("\n\nException while running: {}\n".format(e))
- self.LOG.print_stack ()
+ self.LOG.print_stack()
except BootManagerAuthenticationException as e:
self.LOG.write("\n\nFailed to Authenticate Node: {}\n".format(e))
- self.LOG.print_stack ()
+ self.LOG.print_stack()
# sets /tmp/CANCEL_BOOT flag
StartDebug.Run(self.VARS, self.LOG)
# Return immediately b/c any other calls to API will fail
return success
except:
self.LOG.write("\n\nImplementation Error\n")
- self.LOG.print_stack ()
+ self.LOG.print_stack()
if not success:
try:
traceback.print_exc()
return success
-
-
+
def main(argv):
import utils
utils.prompt_for_breakpoint_mode()
-# utils.breakpoint ("Entering BootManager::main")
-
+# utils.breakpoint("Entering BootManager::main")
+
# 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
LOG = log(BM_NODE_LOG)
except:
traceback.print_exc(file=LOG.OutputFile)
traceback.print_exc()
-
+
if error:
LOG.LogEntry("BootManager finished at: {}"\
.format(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())))
return error
-
if __name__ == "__main__":
error = main(sys.argv)
sys.exit(error)