def debug(request, response):
config = Config.instance()
if config.get_section_config("Server").getboolean("local", False) is False:
raise HTTPForbidden(text="You can only debug a local server")
debug_dir = os.path.join(config.config_dir, "debug")
try:
if os.path.exists(debug_dir):
shutil.rmtree(debug_dir)
os.makedirs(debug_dir)
with open(os.path.join(debug_dir, "controller.txt"), "w+") as f:
f.write(ServerHandler._getDebugData())
except Exception as e:
# If something is wrong we log the info to the log and we hope the log will be include correctly to the debug export
log.error("Could not export debug informations {}".format(e), exc_info=1)
try:
if Controller.instance().gns3vm.engine == "vmware":
vmx_path = Controller.instance().gns3vm.current_engine().vmx_path
if vmx_path:
shutil.copy(vmx_path, os.path.join(debug_dir, os.path.basename(vmx_path)))
except OSError as e:
# If something is wrong we log the info to the log and we hope the log will be include correctly to the debug export
log.error("Could not copy VMware VMX file {}".format(e), exc_info=1)
for compute in list(Controller.instance().computes.values()):
try:
r = yield from compute.get("/debug", raw=True)
data = r.body.decode("utf-8")
except Exception as e:
data = str(e)
with open(os.path.join(debug_dir, "compute_{}.txt".format(compute.name)), "w+") as f:
f.write("Compute ID: {}\n".format(compute.id))
f.write(data)
response.set_status(201)
评论列表
文章目录