From 8acad258abfff20c890f6cc60aeee0049502a769 Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Sat, 14 Feb 2009 02:05:08 +0000 Subject: [PATCH] preserve the 'session' variable across BootManager runs. This also makes the file accessible to the RunlevelAgent. --- source/BootAPI.py | 65 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/source/BootAPI.py b/source/BootAPI.py index 7d5a5cb..b3bbffb 100644 --- a/source/BootAPI.py +++ b/source/BootAPI.py @@ -27,35 +27,62 @@ def create_auth_structure( vars, call_params ): API call. Return None if unable to (typically due to missing keys in vars, such as node_id or node_key) """ - + auth= {} - auth['AuthMethod']= 'hmac' - try: - auth['node_id'] = vars['NODE_ID'] - auth['node_ip'] = vars['INTERFACE_SETTINGS']['ip'] - except KeyError, e: - return None - - #params= serialize_params(call_params) - #params.sort() - #msg= "[" + "".join(params) + "]" - #node_hmac= hmac.new(vars['NODE_KEY'], msg.encode('utf-8'), sha).hexdigest() - node_hmac= hmac.new(vars['NODE_KEY'], "[]".encode('utf-8'), sha).hexdigest() - auth['value']= node_hmac try: auth_session = {} + auth_session['AuthMethod'] = 'session' + if not vars.has_key('NODE_SESSION'): - session = vars['API_SERVER_INST'].GetSession(auth) + # Try to load /etc/planetlab/session if it exists. + sessionfile = open('/etc/planetlab/session', 'r') + session = sessionfile.read().strip() + auth_session['session'] = session + # Test session. Faults if it's no good. + vars['API_SERVER_INST'].AuthCheck(auth_session) vars['NODE_SESSION'] = session + + sessionfile.close() else: auth_session['session'] = vars['NODE_SESSION'] - auth_session['AuthMethod'] = 'session' + auth = auth_session - except Exception, e: - print e - pass + + except: + import traceback; traceback.print_exc() + auth['AuthMethod']= 'hmac' + + try: + auth['node_id'] = vars['NODE_ID'] + auth['node_ip'] = vars['INTERFACE_SETTINGS']['ip'] + except KeyError, e: + return None + + node_hmac= hmac.new(vars['NODE_KEY'], "[]".encode('utf-8'), sha).hexdigest() + auth['value']= node_hmac + try: + auth_session = {} + if not vars.has_key('NODE_SESSION'): + session = vars['API_SERVER_INST'].GetSession(auth) + auth_session['session'] = session + vars['NODE_SESSION'] = session + # NOTE: save session value to /etc/planetlab/session for + # RunlevelAgent and future BootManager runs + sessionfile = open('/etc/planetlab/session', 'w') + sessionfile.write( vars['NODE_SESSION'] ) + sessionfile.close() + else: + auth_session['session'] = vars['NODE_SESSION'] + + auth_session['AuthMethod'] = 'session' + auth = auth_session + + except Exception, e: + print e + pass + return auth -- 2.43.0