X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=source%2FRunlevelAgent.py;h=8dd3474e36459ec942d1ec03c7e2b57d10e43b61;hb=40778dc41a026857000551f5cc7a8e229e32d384;hp=012dba18c9d5259438f715fb0d2880ba9035d2cf;hpb=752736d288e356875e5a3198bf1ef1dd43ac9f34;p=bootmanager.git diff --git a/source/RunlevelAgent.py b/source/RunlevelAgent.py index 012dba1..8dd3474 100755 --- a/source/RunlevelAgent.py +++ b/source/RunlevelAgent.py @@ -7,6 +7,8 @@ # so that it is immediately visible at myplc (gui or api). # +from __future__ import print_function + import xml, xmlrpclib import logging import time @@ -14,6 +16,7 @@ import traceback import sys import os import string +import ssl CONFIG_FILE = "/tmp/source/configuration" SESSION_FILE = "/etc/planetlab/session" @@ -32,7 +35,7 @@ def read_config_file(filename): parts = string.split(line, "=") if len(parts) != 2: - print "Invalid line in vars file: {}".format(line) + print("Invalid line in vars file: {}".format(line)) validConfFile = False break @@ -42,7 +45,7 @@ def read_config_file(filename): vars_file.close() if not validConfFile: - print "Unable to read configuration vars." + print("Unable to read configuration vars.") return vars @@ -72,7 +75,13 @@ class PLC: def __init__(self, auth, url): self.auth = auth self.url = url - self.api = xmlrpclib.Server(self.url, verbose=False, allow_none=True) + # Using a self signed certificate + # https://www.python.org/dev/peps/pep-0476/ + if hasattr(ssl, '_create_unverified_context'): + self.api = xmlrpclib.Server(self.url, verbose=False, allow_none=True, + context=ssl._create_unverified_context()) + else : + self.api = xmlrpclib.Server(self.url, verbose=False, allow_none=True) def __getattr__(self, name): method = getattr(self.api, name) @@ -103,7 +112,7 @@ def save_pid(): f.write("{}\n".format(pid)) f.close() except: - print "Uuuhhh.... this should not occur." + print("Uuuhhh.... this should not occur.") sys.exit(1) def start_and_run(): @@ -122,8 +131,8 @@ def start_and_run(): api.AuthCheck() break except: - print "Retry in 30 seconds: ", os.popen("uptime").read().strip() - traceback.print_exc() + print("Retry in 30 seconds: ", os.popen("uptime").read().strip()) + traceback.print_exc(limit=5) time.sleep(30) try: @@ -168,7 +177,7 @@ def start_and_run(): api.ReportRunlevel({'run_level' : 'failboot'}) except: - print "reporting error: ", os.popen("uptime").read().strip() + print("reporting error: ", os.popen("uptime").read().strip()) traceback.print_exc() sys.stdout.flush()