- f=open(SESSION_FILE,'r')
- session_str=f.read().strip()
- api = PLC(Auth(session=session_str), api_server_url)
- # NOTE: What should we do if this call fails?
- api.AuthCheck()
+ # Keep trying to authenticate session, waiting for NM to re-write the
+ # session file, or DNS to succeed, until AuthCheck succeeds.
+ while True:
+ try:
+ f=open(SESSION_FILE,'r')
+ session_str=f.read().strip()
+ api = PLC(Auth(session=session_str), api_server_url)
+ # NOTE: What should we do if this call fails?
+ # TODO: handle dns failure here.
+ api.AuthCheck()
+ break
+ except:
+ print "Retry in 30 seconds: ", os.popen("uptime").read().strip()
+ traceback.print_exc()
+ time.sleep(30)