+
+ except:
+ auth['AuthMethod'] = 'hmac'
+
+ try:
+ auth['node_id'] = vars['NODE_ID']
+ auth['node_ip'] = vars['INTERFACE_SETTINGS']['ip']
+ except KeyError as 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")
+ with open('/etc/planetlab/session', 'w') as sessionfile:
+ sessionfile.write(vars['NODE_SESSION'])
+
+ else:
+ auth_session['session'] = vars['NODE_SESSION']
+
+ auth_session['AuthMethod'] = 'session'
+ auth = auth_session
+
+ except Exception as e:
+ # NOTE: BM has failed to authenticate utterly.
+ import traceback
+ traceback.print_exc()
+ raise BootManagerAuthenticationException("{}".format(e))
+