mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 16:28:11 +00:00
Fix small errors like unhandled exceptions etc.
This commit is contained in:
parent
0aa9ab53d1
commit
17d657c919
@ -163,7 +163,7 @@ class Cloud(BaseNode):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
output = yield from gns3server.utils.asyncio.subprocess_check_output("networksetup", "-listallhardwareports")
|
output = yield from gns3server.utils.asyncio.subprocess_check_output("networksetup", "-listallhardwareports")
|
||||||
except (FileNotFoundError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
log.warn("Could not execute networksetup: {}".format(e))
|
log.warn("Could not execute networksetup: {}".format(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -526,8 +526,8 @@ class DockerVM(BaseNode):
|
|||||||
x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display))
|
x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display))
|
||||||
yield from wait_for_file_creation(x11_socket)
|
yield from wait_for_file_creation(x11_socket)
|
||||||
|
|
||||||
monitor_process(self._xvfb_process, self._xvfb_callback)
|
#monitor_process(self._xvfb_process, self._xvfb_callback)
|
||||||
monitor_process(self._x11vnc_process, self._x11vnc_callback)
|
#monitor_process(self._x11vnc_process, self._x11vnc_callback)
|
||||||
|
|
||||||
def _xvfb_callback(self, returncode):
|
def _xvfb_callback(self, returncode):
|
||||||
"""
|
"""
|
||||||
|
@ -368,7 +368,7 @@ class IOUVM(BaseNode):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
output = yield from gns3server.utils.asyncio.subprocess_check_output("ldd", self._path)
|
output = yield from gns3server.utils.asyncio.subprocess_check_output("ldd", self._path)
|
||||||
except (FileNotFoundError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
log.warn("Could not determine the shared library dependencies for {}: {}".format(self._path, e))
|
log.warn("Could not determine the shared library dependencies for {}: {}".format(self._path, e))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ class IOUVM(BaseNode):
|
|||||||
hostid = (yield from gns3server.utils.asyncio.subprocess_check_output("hostid")).strip()
|
hostid = (yield from gns3server.utils.asyncio.subprocess_check_output("hostid")).strip()
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
raise IOUError("Could not find hostid: {}".format(e))
|
raise IOUError("Could not find hostid: {}".format(e))
|
||||||
except subprocess.SubprocessError as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise IOUError("Could not execute hostid: {}".format(e))
|
raise IOUError("Could not execute hostid: {}".format(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -193,7 +193,7 @@ class Qemu(BaseManager):
|
|||||||
return version
|
return version
|
||||||
else:
|
else:
|
||||||
raise QemuError("Could not determine the Qemu version for {}".format(qemu_path))
|
raise QemuError("Could not determine the Qemu version for {}".format(qemu_path))
|
||||||
except subprocess.SubprocessError as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise QemuError("Error while looking for the Qemu version: {}".format(e))
|
raise QemuError("Error while looking for the Qemu version: {}".format(e))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -213,7 +213,7 @@ class Qemu(BaseManager):
|
|||||||
return version
|
return version
|
||||||
else:
|
else:
|
||||||
raise QemuError("Could not determine the Qemu-img version for {}".format(qemu_img_path))
|
raise QemuError("Could not determine the Qemu-img version for {}".format(qemu_img_path))
|
||||||
except subprocess.SubprocessError as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise QemuError("Error while looking for the Qemu-img version: {}".format(e))
|
raise QemuError("Error while looking for the Qemu-img version: {}".format(e))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -217,6 +217,8 @@ class VirtualBoxVM(BaseNode):
|
|||||||
except ET.ParseError:
|
except ET.ParseError:
|
||||||
raise VirtualBoxError("Cannot modify VirtualBox linked nodes file. "
|
raise VirtualBoxError("Cannot modify VirtualBox linked nodes file. "
|
||||||
"File {} is corrupted.".format(self._linked_vbox_file()))
|
"File {} is corrupted.".format(self._linked_vbox_file()))
|
||||||
|
except OSError as e:
|
||||||
|
raise VirtualBoxError("Cannot modify VirtualBox linked nodes file '{}': {}".format(self._linked_vbox_file(), e))
|
||||||
|
|
||||||
machine = tree.getroot().find("{http://www.virtualbox.org/}Machine")
|
machine = tree.getroot().find("{http://www.virtualbox.org/}Machine")
|
||||||
if machine is not None and machine.get("uuid") != "{" + self.id + "}":
|
if machine is not None and machine.get("uuid") != "{" + self.id + "}":
|
||||||
@ -245,6 +247,7 @@ class VirtualBoxVM(BaseNode):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@locking
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def start(self):
|
def start(self):
|
||||||
"""
|
"""
|
||||||
|
@ -66,9 +66,7 @@ class Controller:
|
|||||||
|
|
||||||
def load_appliances(self):
|
def load_appliances(self):
|
||||||
self._appliance_templates = {}
|
self._appliance_templates = {}
|
||||||
for directory, builtin in (
|
for directory, builtin in ((get_resource('appliances'), True,), (self.appliances_path(), False,)):
|
||||||
(get_resource('appliances'), True,), (self.appliances_path(), False,)
|
|
||||||
):
|
|
||||||
if directory and os.path.isdir(directory):
|
if directory and os.path.isdir(directory):
|
||||||
for file in os.listdir(directory):
|
for file in os.listdir(directory):
|
||||||
if not file.endswith('.gns3a') and not file.endswith('.gns3appliance'):
|
if not file.endswith('.gns3a') and not file.endswith('.gns3appliance'):
|
||||||
@ -200,7 +198,7 @@ class Controller:
|
|||||||
for c in computes:
|
for c in computes:
|
||||||
try:
|
try:
|
||||||
yield from self.add_compute(**c)
|
yield from self.add_compute(**c)
|
||||||
except (aiohttp.web.HTTPConflict, KeyError):
|
except (aiohttp.web.HTTPError, KeyError):
|
||||||
pass # Skip not available servers at loading
|
pass # Skip not available servers at loading
|
||||||
yield from self.load_projects()
|
yield from self.load_projects()
|
||||||
try:
|
try:
|
||||||
|
@ -175,7 +175,7 @@ class Node:
|
|||||||
if not os.path.isabs(path):
|
if not os.path.isabs(path):
|
||||||
path = os.path.join(self.project.controller.configs_path(), path)
|
path = os.path.join(self.project.controller.configs_path(), path)
|
||||||
try:
|
try:
|
||||||
with open(path) as f:
|
with open(path, encoding="utf-8") as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
except OSError:
|
except OSError:
|
||||||
return None
|
return None
|
||||||
|
@ -843,7 +843,7 @@ class Project:
|
|||||||
link = yield from self.add_link(link_id=link_data["link_id"])
|
link = yield from self.add_link(link_id=link_data["link_id"])
|
||||||
if "filters" in link_data:
|
if "filters" in link_data:
|
||||||
yield from link.update_filters(link_data["filters"])
|
yield from link.update_filters(link_data["filters"])
|
||||||
for node_link in link_data["nodes"]:
|
for node_link in link_data.get("nodes", []):
|
||||||
node = self.get_node(node_link["node_id"])
|
node = self.get_node(node_link["node_id"])
|
||||||
port = node.get_port(node_link["adapter_number"], node_link["port_number"])
|
port = node.get_port(node_link["adapter_number"], node_link["port_number"])
|
||||||
if port is None:
|
if port is None:
|
||||||
|
@ -22,6 +22,9 @@ from ..utils.get_resource import get_resource
|
|||||||
from ..utils.picture import get_size
|
from ..utils.picture import get_size
|
||||||
from ..config import Config
|
from ..config import Config
|
||||||
|
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Symbols:
|
class Symbols:
|
||||||
"""
|
"""
|
||||||
@ -72,19 +75,25 @@ class Symbols:
|
|||||||
def symbols_path(self):
|
def symbols_path(self):
|
||||||
directory = os.path.expanduser(Config.instance().get_section_config("Server").get("symbols_path", "~/GNS3/symbols"))
|
directory = os.path.expanduser(Config.instance().get_section_config("Server").get("symbols_path", "~/GNS3/symbols"))
|
||||||
if directory:
|
if directory:
|
||||||
os.makedirs(directory, exist_ok=True)
|
try:
|
||||||
|
os.makedirs(directory, exist_ok=True)
|
||||||
|
except OSError as e:
|
||||||
|
log.error("Could not create symbol directory '{}': {}".format(directory, e))
|
||||||
|
return None
|
||||||
return directory
|
return directory
|
||||||
|
|
||||||
def get_path(self, symbol_id):
|
def get_path(self, symbol_id):
|
||||||
try:
|
try:
|
||||||
return self._symbols_path[symbol_id]
|
return self._symbols_path[symbol_id]
|
||||||
# Symbol not found refresh cache
|
# Symbol not found, let's refresh the cache
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.list()
|
|
||||||
try:
|
try:
|
||||||
|
self.list()
|
||||||
return self._symbols_path[symbol_id]
|
return self._symbols_path[symbol_id]
|
||||||
except KeyError:
|
except (OSError, KeyError):
|
||||||
return self._symbols_path[":/symbols/computer.svg"]
|
log.warning("Could not retrieve symbol '{}'".format(symbol_id))
|
||||||
|
symbols_path = self._symbols_path
|
||||||
|
return symbols_path[":/symbols/computer.svg"]
|
||||||
|
|
||||||
def get_size(self, symbol_id):
|
def get_size(self, symbol_id):
|
||||||
try:
|
try:
|
||||||
|
@ -409,7 +409,7 @@ def _convert_1_3_later(topo, topo_path):
|
|||||||
symbol = old_node.get("symbol", ":/symbols/computer.svg")
|
symbol = old_node.get("symbol", ":/symbols/computer.svg")
|
||||||
old_node["ports"] = _create_cloud(node, old_node, symbol)
|
old_node["ports"] = _create_cloud(node, old_node, symbol)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Conversion of {} is not supported".format(old_node["type"]))
|
raise aiohttp.web.HTTPConflict(text="Conversion of {} is not supported".format(old_node["type"]))
|
||||||
|
|
||||||
for prop in old_node.get("properties", {}):
|
for prop in old_node.get("properties", {}):
|
||||||
if prop not in ["console", "name", "console_type", "console_host", "use_ubridge"]:
|
if prop not in ["console", "name", "console_type", "console_host", "use_ubridge"]:
|
||||||
@ -608,13 +608,13 @@ def _create_cloud(node, old_node, icon):
|
|||||||
elif old_port["name"].startswith("nio_nat"):
|
elif old_port["name"].startswith("nio_nat"):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("The conversion of cloud with {} is not supported".format(old_port["name"]))
|
raise aiohttp.web.HTTPConflict(text="The conversion of cloud with {} is not supported".format(old_port["name"]))
|
||||||
|
|
||||||
if port_type == "udp":
|
if port_type == "udp":
|
||||||
try:
|
try:
|
||||||
_, lport, rhost, rport = old_port["name"].split(":")
|
_, lport, rhost, rport = old_port["name"].split(":")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise NotImplementedError("UDP tunnel using IPV6 is not supported in cloud")
|
raise aiohttp.web.HTTPConflict(text="UDP tunnel using IPV6 is not supported in cloud")
|
||||||
port = {
|
port = {
|
||||||
"name": "UDP tunnel {}".format(len(ports) + 1),
|
"name": "UDP tunnel {}".format(len(ports) + 1),
|
||||||
"port_number": len(ports) + 1,
|
"port_number": len(ports) + 1,
|
||||||
@ -645,7 +645,7 @@ def _convert_snapshots(topo_dir):
|
|||||||
old_snapshots_dir = os.path.join(topo_dir, "project-files", "snapshots")
|
old_snapshots_dir = os.path.join(topo_dir, "project-files", "snapshots")
|
||||||
if os.path.exists(old_snapshots_dir):
|
if os.path.exists(old_snapshots_dir):
|
||||||
new_snapshots_dir = os.path.join(topo_dir, "snapshots")
|
new_snapshots_dir = os.path.join(topo_dir, "snapshots")
|
||||||
os.makedirs(new_snapshots_dir)
|
os.makedirs(new_snapshots_dir, exist_ok=True)
|
||||||
|
|
||||||
for snapshot in os.listdir(old_snapshots_dir):
|
for snapshot in os.listdir(old_snapshots_dir):
|
||||||
snapshot_dir = os.path.join(old_snapshots_dir, snapshot)
|
snapshot_dir = os.path.join(old_snapshots_dir, snapshot)
|
||||||
|
@ -52,7 +52,8 @@ class SymbolHandler:
|
|||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
try:
|
try:
|
||||||
yield from response.file(controller.symbols.get_path(request.match_info["symbol_id"]))
|
yield from response.file(controller.symbols.get_path(request.match_info["symbol_id"]))
|
||||||
except (KeyError, FileNotFoundError, PermissionError):
|
except (KeyError, OSError) as e:
|
||||||
|
log.warning("Could not get symbol file: {}".format(e))
|
||||||
response.set_status(404)
|
response.set_status(404)
|
||||||
|
|
||||||
@Route.post(
|
@Route.post(
|
||||||
@ -66,7 +67,7 @@ class SymbolHandler:
|
|||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
path = os.path.join(controller.symbols.symbols_path(), os.path.basename(request.match_info["symbol_id"]))
|
path = os.path.join(controller.symbols.symbols_path(), os.path.basename(request.match_info["symbol_id"]))
|
||||||
try:
|
try:
|
||||||
with open(path, 'wb') as f:
|
with open(path, "wb") as f:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
chunk = yield from request.content.read(1024)
|
chunk = yield from request.content.read(1024)
|
||||||
@ -75,7 +76,7 @@ class SymbolHandler:
|
|||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
except OSError as e:
|
except (UnicodeEncodeError, OSError) as e:
|
||||||
raise aiohttp.web.HTTPConflict(text="Could not write symbol file '{}': {}".format(path, e))
|
raise aiohttp.web.HTTPConflict(text="Could not write symbol file '{}': {}".format(path, e))
|
||||||
# Reset the symbol list
|
# Reset the symbol list
|
||||||
controller.symbols.list()
|
controller.symbols.list()
|
||||||
|
@ -178,7 +178,7 @@ class Hypervisor(UBridgeHypervisor):
|
|||||||
env=env)
|
env=env)
|
||||||
|
|
||||||
log.info("ubridge started PID={}".format(self._process.pid))
|
log.info("ubridge started PID={}".format(self._process.pid))
|
||||||
except (OSError, PermissionError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
ubridge_stdout = self.read_stdout()
|
ubridge_stdout = self.read_stdout()
|
||||||
log.error("Could not start ubridge: {}\n{}".format(e, ubridge_stdout))
|
log.error("Could not start ubridge: {}\n{}".format(e, ubridge_stdout))
|
||||||
raise UbridgeError("Could not start ubridge: {}\n{}".format(e, ubridge_stdout))
|
raise UbridgeError("Could not start ubridge: {}\n{}".format(e, ubridge_stdout))
|
||||||
|
Loading…
Reference in New Issue
Block a user