X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=source%2FBootAPI.py;h=c7d810570fe9b205b0b22ff80e3d2659df8843f2;hb=d4be39e78e9a1a0c1885958e74189280a281be1b;hp=bedf7275f6d9d179c8da6cd4c22d5f611c562dfe;hpb=79ea11f05210d17197030e6405e74345c7dcb690;p=bootmanager.git diff --git a/source/BootAPI.py b/source/BootAPI.py index bedf727..c7d8105 100644 --- a/source/BootAPI.py +++ b/source/BootAPI.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2 - +#!/usr/bin/python +# # Copyright (c) 2003 Intel Corporation # All rights reserved. # @@ -14,6 +14,7 @@ import string import sha import cPickle import utils +import os from Exceptions import * @@ -27,35 +28,63 @@ 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['NETWORK_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 = {} - if not vars.has_key('SESSION'): - session = vars['API_SERVER_INST'].GetSession(auth) + auth_session['AuthMethod'] = 'session' + + if not vars.has_key('NODE_SESSION'): + # Try to load /etc/planetlab/session if it exists. + sessionfile = open('/etc/planetlab/session', 'r') + session = sessionfile.read().strip() + auth_session['session'] = session - vars['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['SESSION'] - auth_session['AuthMethod'] = 'session' + auth_session['session'] = vars['NODE_SESSION'] + auth = auth_session - except Exception, e: - print e - pass + + except: + 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 + if not os.path.exists("/etc/planetlab"): + os.makedirs("/etc/planetlab") + 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: + # NOTE: BM has failed to authenticate utterly. + raise BootManagerAuthenticationException, "%s" % e + return auth