From 25a9fff76ec48c528db75eaf48e10118c5b4e0ca Mon Sep 17 00:00:00 2001 From: Aaron Klingaman Date: Wed, 21 Sep 2005 20:29:52 +0000 Subject: [PATCH] rather than code in the name of the boot server into the boot manager configuration, pull it off of the boot cd. this change requires that an api server be running on the boot server. --- source/BootManager.py | 20 ++++-- source/configuration | 4 -- source/steps/InitializeBootManager.py | 99 ++++++++++++++++++++++++--- 3 files changed, 104 insertions(+), 19 deletions(-) diff --git a/source/BootManager.py b/source/BootManager.py index 6d9d394..517fb43 100755 --- a/source/BootManager.py +++ b/source/BootManager.py @@ -62,7 +62,7 @@ import notify_messages # all output is written to this file LOG_FILE= "/tmp/bm.log" CURL_PATH= "curl" -UPLOAD_LOG_URL = "http://boot.planet-lab.org/alpina-logs/upload.php" + # the new contents of PATH when the boot manager is running BIN_PATH= ('/usr/local/bin', @@ -78,6 +78,9 @@ BIN_PATH= ('/usr/local/bin', class log: def __init__( self, OutputFilePath= None ): + + self.UPLOAD_LOG_URL= None + if OutputFilePath: try: self.OutputFilePath= OutputFilePath @@ -103,7 +106,6 @@ class log: self.OutputFile.flush() - def write( self, str ): """ make log behave like a writable file object (for traceback @@ -112,21 +114,27 @@ class log: self.LogEntry( str, 0, 1 ) + def SetUploadServer( self, server ): + """ + set the url we should use to upload the logs to + """ + self.UPLOAD_LOG_URL = "http://%s/alpina-logs/upload.php" % server + def Upload( self ): """ upload the contents of the log to the server """ - if self.OutputFile is not None: - self.LogEntry( "Uploading logs to %s" % UPLOAD_LOG_URL ) + if self.OutputFile is not None and self.UPLOAD_LOG_URL is not None: + self.LogEntry( "Uploading logs to %s" % self.UPLOAD_LOG_URL ) self.OutputFile.close() self.OutputFile= None curl_cmd= "%s -s --connect-timeout 60 --max-time 600 " \ "--form log=@%s %s" % \ - (CURL_PATH, self.OutputFilePath, UPLOAD_LOG_URL) + (CURL_PATH, self.OutputFilePath, self.UPLOAD_LOG_URL) os.system( curl_cmd ) @@ -164,7 +172,7 @@ class BootManager: # 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,":") - + self.CAN_RUN= 1 diff --git a/source/configuration b/source/configuration index ac0ea8e..fece501 100644 --- a/source/configuration +++ b/source/configuration @@ -7,10 +7,6 @@ VERSION=3.1.8 -# full url to which api server to contact -BOOT_API_SERVER=https://www.planet-lab.org:443/PLCAPI/ - - # path to store temporary files during the install, # do not include trailing slashes TEMP_PATH=/mnt/tmp diff --git a/source/steps/InitializeBootManager.py b/source/steps/InitializeBootManager.py index c129d63..076a637 100644 --- a/source/steps/InitializeBootManager.py +++ b/source/steps/InitializeBootManager.py @@ -11,6 +11,14 @@ import utils BOOT_VERSION_2X_FILE='/usr/bootme/ID' BOOT_VERSION_3X_FILE='/pl_version' +# locations of boot server name/certificate files +V2X_BOOTCD_SERVER_FILE = "/usr/bootme/BOOTSERVER" +V2X_BOOTCD_SERVER_CACERT_DIR = "/usr/bootme/cacert" +V2X_CACERT_NAME = "cacert.pem" + +V3X_BOOTCD_SERVER_FILE = "/usr/boot/boot_server" +V3X_BOOTCD_SERVER_CACERT = "/usr/boot/cacert.pem" + # minimium version of the boot os we need to run, as a (major,minor) tuple MINIMUM_BOOT_VERSION= (2,0) @@ -25,19 +33,14 @@ def Run( vars, log ): Sets the following variables: BOOT_CD_VERSION A two number tuple of the boot cd version + MA_BOOT_SERVER The boot server we contacted, identified from + files on the boot cd. + MA_BOOT_SERVER_CACERT The SSL certificate for the above server + """ log.write( "\n\nStep: Initializing the BootManager.\n" ) - - log.write( "Opening connection to API server\n" ) - try: - api_inst= xmlrpclib.Server( vars['BOOT_API_SERVER'], verbose=0 ) - except KeyError, e: - raise BootManagerException, \ - "configuration file does not specify API server URL" - - vars['API_SERVER_INST']= api_inst if not __check_boot_version( vars, log ): raise BootManagerException, \ @@ -47,6 +50,84 @@ def Run( vars, log ): str(vars['BOOT_CD_VERSION']) ) BOOT_CD_VERSION= vars['BOOT_CD_VERSION'] + + + log.write( "Identifying boot server and setting up /etc/planetlab entries" ) + + # need to pull the server name we contacted. 2.x cds will have the + # info in /usr/bootme; 3.x cds in /usr/boot + if BOOT_CD_VERSION[0] == 2: + try: + boot_server= file(V2X_BOOTCD_SERVER_FILE).read().strip() + except IOError: + raise BootManagerException, \ + "It appears we are running on a v2.x boot cd, but could " \ + "not load contacted boot server from %s" % V2X_BOOTCD_SERVER_FILE + + if boot_server == "": + raise BootManagerException, \ + "It appears we are running on a v2.x boot cd, but %s " \ + "appears to be blank." % V2X_BOOTCD_SERVER_FILE + + cacert_file= "%s/%s/%s" % (V2X_BOOTCD_SERVER_CACERT_DIR, + boot_server, V2X_CACERT_NAME) + + elif BOOT_CD_VERSION[0] == 3: + try: + boot_server= file(V3X_BOOTCD_SERVER_FILE).read().strip() + except IOError: + raise BootManagerException, \ + "It appears we are running on a v3.x boot cd, but could " \ + "not load contacted boot server from %s" % V3X_BOOTCD_SERVER_FILE + + if boot_server == "": + raise BootManagerException, \ + "It appears we are running on a v3.x boot cd, but %s " \ + "appears to be blank." % V3X_BOOTCD_SERVER_FILE + + cacert_file= V3X_BOOTCD_SERVER_CACERT + + else: + raise BootManagerException, "Unknown boot cd version." + + if not os.access(cacert_file, os.R_OK): + raise BootManagerException, \ + "Could not find the certificate for the " \ + "specified boot server (at %s)" % cacert_file + + # tell the log instance about the boot server so it knows + # where to upload the logs + try: + log.SetUploadServer( self.VARS['MA_BOOT_SERVER'] ) + except KeyError, e: + log.LogEntry( "configuration does not contain boot server name." ) + return + + + # now that we have the boot server name and the location of its certificate, + # write out /etc/planetlab/primary_ma with this info. + try: + primary_ma_file= file("/etc/planetlab/primary_ma","w") + primary_ma_file.write( "MA_NAME=\"Unknown\"\n" ) + primary_ma_file.write( "MA_BOOT_SERVER=\"%s\"\n" % boot_server ) + primary_ma_file.write( "MA_BOOT_SERVER_CACERT=\"%s\"\n" % cacert_file ) + primary_ma_file.close() + primary_ma_file= None + except IOError: + raise BootManagerException, "Unable to write out /etc/planetlab/primary_ma" + + vars['MA_BOOT_SERVER']= boot_server + vars['MA_BOOT_SERVER_CACRET']= cacert_file + + self.Message( "Using boot server %s with certificate" % + (boot_server,cacert_file) ) + + + log.write( "Opening connection to API server\n" ) + api_server_url= "https://%s/PLCAPI/" % vars['MA_BOOT_SERVER'] + api_inst= xmlrpclib.Server( api_server_url, verbose=0 ) + vars['API_SERVER_INST']= api_inst + # old cds need extra modules loaded for compaq smart array if BOOT_CD_VERSION[0] == 2: -- 2.43.0