Merge remote-tracking branch 'origin/2.0' into 2.0

Conflicts:
	gns3server/web/web_server.py
This commit is contained in:
grossmj committed 2016-06-16 11:19:03 -06:00
commit da58a65075
12 files changed
+69 -31

No files matched your search

+16 -13
View File
@@ -279,7 +279,7 @@ class DockerVM(BaseNode):
"Binds": self._mount_binds(image_infos)
},
"Volumes": {},
"Env": [],
"Env": ["container=docker"], # Systemd compliant: https://github.com/GNS3/gns3-server/issues/573
"Cmd": [],
"Entrypoint": image_infos.get("Config", {"Entrypoint": []})["Entrypoint"]
}
@@ -306,6 +306,7 @@ class DockerVM(BaseNode):
if self._console_type == "vnc":
yield from self._start_vnc()
params["Env"].append("QT_GRAPHICSSYSTEM=native") # To fix a Qt issue: https://github.com/GNS3/gns3-server/issues/556
params["Env"].append("DISPLAY=:{}".format(self._display))
params["HostConfig"]["Binds"].append("/tmp/.X11-unix/:/tmp/.X11-unix/")
@@ -384,7 +385,7 @@ class DockerVM(BaseNode):
# We can not use the API because docker doesn't expose a websocket api for exec
# https://github.com/GNS3/gns3-gui/issues/1039
process = yield from asyncio.subprocess.create_subprocess_exec(
"docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "script", "-qfc", "/gns3/bin/busybox sh", "/dev/null",
"docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "script", "-qfc", "while true; do /gns3/bin/busybox sh; done", "/dev/null",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
stdin=asyncio.subprocess.PIPE)
@@ -493,7 +494,9 @@ class DockerVM(BaseNode):
out.feed_eof()
ws.close()
break
yield from self.stop()
@asyncio.coroutine
def is_running(self):
"""Checks if the container is running.
@@ -535,21 +538,21 @@ class DockerVM(BaseNode):
if state == "paused":
yield from self.unpause()
yield from self._fix_permissions()
# t=5 number of seconds to wait before killing the container
try:
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})
log.info("Docker container '{name}' [{image}] stopped".format(name=self._name, image=self._image))
except DockerHttp304Error:
# Container is already stopped
pass
finally:
self.status = "stopped"
if state != "stopped":
yield from self._fix_permissions()
# t=5 number of seconds to wait before killing the container
try:
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})
log.info("Docker container '{name}' [{image}] stopped".format(
name=self._name, image=self._image))
except DockerHttp304Error:
# Container is already stopped
pass
# Ignore runtime error because when closing the server
except RuntimeError as e:
log.debug("Docker runtime error when closing: {}".format(str(e)))
return
self.status = "stopped"
@asyncio.coroutine
def pause(self):
+2 -1
View File
@@ -217,9 +217,10 @@ class Controller:
topo_data.pop("revision")
topo_data.pop("type")
project = yield from self.add_project(path=os.path.dirname(path), status="closed", **topo_data)
project = yield from self.add_project(path=os.path.dirname(path), status="closed", filename=os.path.basename(path), **topo_data)
if load:
yield from project.open()
return project
@property
def projects(self):
+10 -9
View File
@@ -43,7 +43,7 @@ class Project:
:param status: Status of the project (opened / closed)
"""
def __init__(self, name=None, project_id=None, path=None, controller=None, status="opened"):
def __init__(self, name=None, project_id=None, path=None, controller=None, status="opened", filename=None):
self._controller = controller
self._name = name
@@ -60,6 +60,13 @@ class Project:
if path is None:
path = os.path.join(get_default_project_directory(), self._id)
self.path = path
if filename is None and name is None:
self._filename = "project.gns3"
elif filename is not None:
self._filename = filename
else:
self._filename = self.name + ".gns3"
self.reset()
def reset(self):
@@ -322,14 +329,8 @@ class Project:
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
return path
def _filename(self):
if self.name is None:
return "untitled.gns3"
else:
return self.name + ".gns3"
def _topology_file(self):
return os.path.join(self.path, self._filename())
return os.path.join(self.path, self._filename)
@asyncio.coroutine
def open(self):
@@ -373,6 +374,6 @@ class Project:
"name": self._name,
"project_id": self._id,
"path": self._path,
"filename": self._filename(),
"filename": self._filename,
"status": self._status
}
@@ -49,7 +49,7 @@ class ServerHandler:
# close all the projects first
controller = Controller.instance()
projects = controller.projects
projects = controller.projects.values()
tasks = []
for project in projects:
+3
View File
@@ -102,6 +102,7 @@ def parse_arguments(argv):
parser.add_argument("--log", help="send output to logfile instead of console")
parser.add_argument("--daemon", action="store_true", help="start as a daemon")
parser.add_argument("--pid", help="store process pid")
parser.add_argument("--udpdiscovery", action="store_true", help="allow the server to be discover on the network")
args = parser.parse_args(argv)
if args.config:
@@ -121,6 +122,7 @@ def parse_arguments(argv):
"quiet": config.getboolean("quiet", False),
"debug": config.getboolean("debug", False),
"logfile": config.getboolean("logfile", ""),
"udp_discovery": config.getboolean("udp_discovery", False),
}
parser.set_defaults(**defaults)
@@ -142,6 +144,7 @@ def set_config(args):
server_config["record"] = args.record
server_config["debug"] = str(args.debug)
server_config["shell"] = str(args.shell)
server_config["udp_discovery"] = str(args.udpdiscovery)
config.set_section_config("Server", server_config)
+2 -1
View File
@@ -59,6 +59,7 @@ class WebServer:
self._handler = None
self._start_time = time.time()
self._port_manager = PortManager(host)
self._running = False
@staticmethod
def instance(host=None, port=None):
@@ -298,7 +299,7 @@ class WebServer:
if server_config.getboolean("shell"):
asyncio.async(self.start_shell())
if sys.platform.startswith("linux"):
if sys.platform.startswith("linux") and server_config.getboolean("udp_discovery"):
# UDP discovery is only supported on Linux
udp_server_discovery = threading.Thread(target=self._udp_server_discovery, daemon=True)
udp_server_discovery.start()