mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Merge remote-tracking branch 'origin/2.1' into 2.1
This commit is contained in:
commit
4e712280b3
458 files changed
+11443
-10751
No files matched your search
@@ -27,9 +27,9 @@ from operator import itemgetter
|
||||
|
||||
from ..utils import parse_version
|
||||
from ..utils.images import list_images
|
||||
from ..utils.asyncio import locked_coroutine
|
||||
from ..utils.asyncio import locking, asyncio_ensure_future
|
||||
from ..controller.controller_error import ControllerError
|
||||
from ..version import __version__
|
||||
from ..version import __version__, __version_info__
|
||||
|
||||
|
||||
import logging
|
||||
@@ -95,6 +95,7 @@ class Compute:
|
||||
self._set_auth(user, password)
|
||||
self._cpu_usage_percent = None
|
||||
self._memory_usage_percent = None
|
||||
self._last_error = None
|
||||
self._capabilities = {
|
||||
"version": None,
|
||||
"node_types": []
|
||||
@@ -301,7 +302,8 @@ class Compute:
|
||||
"connected": self._connected,
|
||||
"cpu_usage_percent": self._cpu_usage_percent,
|
||||
"memory_usage_percent": self._memory_usage_percent,
|
||||
"capabilities": self._capabilities
|
||||
"capabilities": self._capabilities,
|
||||
"last_error": self._last_error
|
||||
}
|
||||
|
||||
@asyncio.coroutine
|
||||
@@ -398,13 +400,14 @@ class Compute:
|
||||
except aiohttp.web.HTTPConflict:
|
||||
pass
|
||||
|
||||
@locked_coroutine
|
||||
@locking
|
||||
@asyncio.coroutine
|
||||
def connect(self):
|
||||
"""
|
||||
Check if remote server is accessible
|
||||
"""
|
||||
|
||||
if not self._connected and not self._closed:
|
||||
if not self._connected and not self._closed and self.host:
|
||||
try:
|
||||
log.info("Connecting to compute '{}'".format(self._id))
|
||||
response = yield from self._run_http_query("GET", "/capabilities")
|
||||
@@ -416,7 +419,7 @@ class Compute:
|
||||
if self._connection_failure == 5:
|
||||
log.warning("Cannot connect to compute '{}': {}".format(self._id, e))
|
||||
yield from self._controller.close_compute_projects(self)
|
||||
asyncio.get_event_loop().call_later(2, lambda: asyncio.async(self._try_reconnect()))
|
||||
asyncio.get_event_loop().call_later(2, lambda: asyncio_ensure_future(self._try_reconnect()))
|
||||
return
|
||||
except aiohttp.web.HTTPNotFound:
|
||||
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server or it's a 1.X server".format(self._id))
|
||||
@@ -428,16 +431,36 @@ class Compute:
|
||||
raise aiohttp.web.HTTPConflict(text="Invalid server url for server {}".format(self._id))
|
||||
|
||||
if "version" not in response.json:
|
||||
msg = "The server {} is not a GNS3 server".format(self._id)
|
||||
log.error(msg)
|
||||
self._http_session.close()
|
||||
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
|
||||
raise aiohttp.web.HTTPConflict(text=msg)
|
||||
self._capabilities = response.json
|
||||
if parse_version(__version__)[:2] != parse_version(response.json["version"])[:2]:
|
||||
self._http_session.close()
|
||||
raise aiohttp.web.HTTPConflict(text="The server {} versions are not compatible {} != {}".format(self._id, __version__, response.json["version"]))
|
||||
|
||||
if response.json["version"].split("-")[0] != __version__.split("-")[0]:
|
||||
msg = "GNS3 controller version {} is not the same as compute server {} version {}".format(__version__,
|
||||
self._name,
|
||||
response.json["version"])
|
||||
if __version_info__[3] == 0:
|
||||
# Stable release
|
||||
log.error(msg)
|
||||
self._http_session.close()
|
||||
self._last_error = msg
|
||||
raise aiohttp.web.HTTPConflict(text=msg)
|
||||
elif parse_version(__version__)[:2] != parse_version(response.json["version"])[:2]:
|
||||
# We don't allow different major version to interact even with dev build
|
||||
log.error(msg)
|
||||
self._http_session.close()
|
||||
self._last_error = msg
|
||||
raise aiohttp.web.HTTPConflict(text=msg)
|
||||
else:
|
||||
msg = "{}\nUsing different versions may result in unexpected problems. Please use at your own risk.".format(msg)
|
||||
self._controller.notification.emit("log.warning", {"message": msg})
|
||||
|
||||
self._notifications = asyncio.gather(self._connect_notification())
|
||||
self._connected = True
|
||||
self._connection_failure = 0
|
||||
self._last_error = None
|
||||
self._controller.notification.emit("compute.updated", self.__json__())
|
||||
|
||||
@asyncio.coroutine
|
||||
@@ -472,7 +495,7 @@ class Compute:
|
||||
|
||||
# Try to reconnect after 1 seconds if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
|
||||
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
|
||||
asyncio.get_event_loop().call_later(1, lambda: asyncio.async(self.connect()))
|
||||
asyncio.get_event_loop().call_later(1, lambda: asyncio_ensure_future(self.connect()))
|
||||
self._ws = None
|
||||
self._cpu_usage_percent = None
|
||||
self._memory_usage_percent = None
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import asyncio
|
||||
import aiohttp
|
||||
@@ -23,6 +24,7 @@ import zipfile
|
||||
import tempfile
|
||||
import zipstream
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -77,6 +79,7 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id
|
||||
# ignore the .gns3 file
|
||||
if file.endswith(".gns3"):
|
||||
continue
|
||||
_patch_mtime(path)
|
||||
zstream.write(path, os.path.relpath(path, project._path), compress_type=zipfile.ZIP_DEFLATED)
|
||||
|
||||
# Export files from remote computes
|
||||
@@ -99,12 +102,29 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id
|
||||
f.write(data)
|
||||
response.close()
|
||||
f.close()
|
||||
_patch_mtime(temp_path)
|
||||
zstream.write(temp_path, arcname=compute_file["path"], compress_type=zipfile.ZIP_DEFLATED)
|
||||
downloaded_files.add(compute_file['path'])
|
||||
|
||||
return zstream
|
||||
|
||||
|
||||
def _patch_mtime(path):
|
||||
"""
|
||||
Patch the file mtime because ZIP does not support timestamps before 1980
|
||||
|
||||
:param path: file path
|
||||
"""
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
# only UNIX type platforms
|
||||
return
|
||||
st = os.stat(path)
|
||||
file_date = datetime.fromtimestamp(st.st_mtime)
|
||||
if file_date.year < 1980:
|
||||
new_mtime = file_date.replace(year=1980).timestamp()
|
||||
os.utime(path, (st.st_atime, new_mtime))
|
||||
|
||||
def _is_exportable(path):
|
||||
"""
|
||||
:returns: True if file should not be included in the final archive
|
||||
@@ -228,6 +248,7 @@ def _export_local_image(image, zstream):
|
||||
|
||||
if os.path.exists(path):
|
||||
arcname = os.path.join("images", directory, os.path.basename(image))
|
||||
_patch_mtime(path)
|
||||
zstream.write(path, arcname)
|
||||
return
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import asyncio
|
||||
import aiohttp
|
||||
import ipaddress
|
||||
|
||||
from ...utils.asyncio import locked_coroutine
|
||||
from ...utils.asyncio import locking, asyncio_ensure_future
|
||||
from .vmware_gns3_vm import VMwareGNS3VM
|
||||
from .virtualbox_gns3_vm import VirtualBoxGNS3VM
|
||||
from .remote_gns3_vm import RemoteGNS3VM
|
||||
@@ -265,7 +265,8 @@ class GNS3VM:
|
||||
except GNS3VMError as e:
|
||||
log.warn(str(e))
|
||||
|
||||
@locked_coroutine
|
||||
@locking
|
||||
@asyncio.coroutine
|
||||
def start(self):
|
||||
"""
|
||||
Start the GNS3 VM
|
||||
@@ -302,7 +303,7 @@ class GNS3VM:
|
||||
|
||||
# check if the VM is in the same subnet as the local server, start 10 seconds later to give
|
||||
# some time for the compute in the VM to be ready for requests
|
||||
asyncio.get_event_loop().call_later(10, lambda: asyncio.async(self._check_network(compute)))
|
||||
asyncio.get_event_loop().call_later(10, lambda: asyncio_ensure_future(self._check_network(compute)))
|
||||
|
||||
@asyncio.coroutine
|
||||
def _check_network(self, compute):
|
||||
@@ -336,8 +337,11 @@ class GNS3VM:
|
||||
self._controller.notification.emit("log.warning", {"message": msg})
|
||||
except ComputeError as e:
|
||||
log.warning("Could not check the VM is in the same subnet as the local server: {}".format(e))
|
||||
except aiohttp.web.HTTPConflict as e:
|
||||
log.warning("Could not check the VM is in the same subnet as the local server: {}".format(e.text))
|
||||
|
||||
@locked_coroutine
|
||||
@locking
|
||||
@asyncio.coroutine
|
||||
def _suspend(self):
|
||||
"""
|
||||
Suspend the GNS3 VM
|
||||
@@ -349,7 +353,8 @@ class GNS3VM:
|
||||
log.info("Suspend the GNS3 VM")
|
||||
yield from engine.suspend()
|
||||
|
||||
@locked_coroutine
|
||||
@locking
|
||||
@asyncio.coroutine
|
||||
def _stop(self):
|
||||
"""
|
||||
Stop the GNS3 VM
|
||||
|
||||
@@ -22,6 +22,8 @@ import html
|
||||
import asyncio
|
||||
import aiohttp
|
||||
|
||||
from gns3server.utils.asyncio import asyncio_ensure_future
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -296,7 +298,7 @@ class Link:
|
||||
|
||||
self._capturing = True
|
||||
self._capture_file_name = capture_file_name
|
||||
self._streaming_pcap = asyncio.async(self._start_streaming_pcap())
|
||||
self._streaming_pcap = asyncio_ensure_future(self._start_streaming_pcap())
|
||||
self._project.controller.notification.emit("link.updated", self.__json__())
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
@@ -33,8 +33,8 @@ class ATMPort(SerialPort):
|
||||
"""
|
||||
return "ATM"
|
||||
|
||||
@property
|
||||
def short_name_type(self):
|
||||
@staticmethod
|
||||
def short_name_type():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
@@ -42,10 +42,6 @@ class ATMPort(SerialPort):
|
||||
"""
|
||||
return "a"
|
||||
|
||||
@property
|
||||
def short_name(self):
|
||||
return "{}".format(self._port_number)
|
||||
|
||||
@property
|
||||
def data_link_types(self):
|
||||
"""
|
||||
|
||||
@@ -39,8 +39,8 @@ class EthernetPort(Port):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
@property
|
||||
def short_name_type(self):
|
||||
@staticmethod
|
||||
def short_name_type():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ class FastEthernetPort(Port):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
@property
|
||||
def short_name_type(self):
|
||||
@staticmethod
|
||||
def short_name_type():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
|
||||
@@ -34,10 +34,6 @@ class FrameRelayPort(SerialPort):
|
||||
|
||||
return "FrameRelay"
|
||||
|
||||
@property
|
||||
def short_name(self):
|
||||
return "{}".format(self._port_number)
|
||||
|
||||
@property
|
||||
def data_link_types(self):
|
||||
"""
|
||||
|
||||
@@ -34,8 +34,8 @@ class GigabitEthernetPort(Port):
|
||||
|
||||
return "GigabitEthernet"
|
||||
|
||||
@property
|
||||
def short_name_type(self):
|
||||
@staticmethod
|
||||
def short_name_type():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
|
||||
@@ -63,12 +63,14 @@ class Port:
|
||||
|
||||
@property
|
||||
def short_name(self):
|
||||
# If port name format has change we use the port name as the short name (1.X behavior)
|
||||
# If port name format has changed we use the port name as the short name (1.X behavior)
|
||||
if self._short_name:
|
||||
return self._short_name
|
||||
elif not self._name.startswith("{}{}".format(self.long_name_type(), self._interface_number)):
|
||||
return self._name
|
||||
return self.short_name_type + "{}/{}".format(self._interface_number, self._port_number)
|
||||
elif '/' in self._name:
|
||||
return self._name.replace(self.long_name_type(), self.short_name_type())
|
||||
elif self._name.startswith("{}{}".format(self.long_name_type(), self._interface_number)):
|
||||
return self.short_name_type() + "{}".format(self._interface_number)
|
||||
return self._name
|
||||
|
||||
@short_name.setter
|
||||
def short_name(self, val):
|
||||
|
||||
@@ -64,7 +64,7 @@ class StandardPortFactory:
|
||||
for port_number in range(0, port_by_adapter):
|
||||
if first_port_name and adapter_number == 0:
|
||||
port_name = first_port_name
|
||||
port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet")
|
||||
port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet", short_name=first_port_name)
|
||||
else:
|
||||
try:
|
||||
port_name = port_name_format.format(
|
||||
@@ -190,7 +190,9 @@ class DynamipsPortFactory:
|
||||
if port_class:
|
||||
for port_number in range(0, cls.ADAPTER_MATRIX[properties[name]]["nb_ports"]):
|
||||
name = "{}{}/{}".format(port_class.long_name_type(), adapter_number, port_number)
|
||||
ports.append(port_class(name, adapter_number, adapter_number, port_number))
|
||||
port = port_class(name, adapter_number, adapter_number, port_number)
|
||||
port.short_name = "{}{}/{}".format(port_class.short_name_type(), adapter_number, port_number)
|
||||
ports.append(port)
|
||||
adapter_number += 1
|
||||
elif name.startswith("wic") and properties[name]:
|
||||
port_class = cls.WIC_MATRIX[properties[name]]["port"]
|
||||
@@ -198,7 +200,7 @@ class DynamipsPortFactory:
|
||||
for port_number in range(0, cls.WIC_MATRIX[properties[name]]["nb_ports"]):
|
||||
name = "{}{}/{}".format(port_class.long_name_type(), 0, display_wic_port_number)
|
||||
port = port_class(name, 0, 0, wic_port_number)
|
||||
port.short_name = "{}{}/{}".format(port.short_name_type, 0, display_wic_port_number)
|
||||
port.short_name = "{}{}/{}".format(port_class.short_name_type(), 0, display_wic_port_number)
|
||||
ports.append(port)
|
||||
display_wic_port_number += 1
|
||||
wic_port_number += 1
|
||||
|
||||
@@ -33,8 +33,8 @@ class POSPort(SerialPort):
|
||||
"""
|
||||
return "POS"
|
||||
|
||||
@property
|
||||
def short_name_type(self):
|
||||
@staticmethod
|
||||
def short_name_type():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ class SerialPort(Port):
|
||||
|
||||
return "Serial"
|
||||
|
||||
@property
|
||||
def short_name_type(self):
|
||||
@staticmethod
|
||||
def short_name_type():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
|
||||
@@ -36,8 +36,9 @@ from .udp_link import UDPLink
|
||||
from ..config import Config
|
||||
from ..utils.path import check_path_allowed, get_default_project_directory
|
||||
from ..utils.asyncio.pool import Pool
|
||||
from ..utils.asyncio import locked_coroutine
|
||||
from ..utils.asyncio import locking
|
||||
from ..utils.asyncio import wait_run_in_executor
|
||||
from ..utils.asyncio import asyncio_ensure_future
|
||||
from .export_project import export_project
|
||||
from .import_project import import_project
|
||||
|
||||
@@ -500,18 +501,21 @@ class Project:
|
||||
if compute not in self._project_created_on_compute:
|
||||
# For a local server we send the project path
|
||||
if compute.id == "local":
|
||||
yield from compute.post("/projects", data={
|
||||
data = {
|
||||
"name": self._name,
|
||||
"project_id": self._id,
|
||||
"path": self._path,
|
||||
"variables": self._variables
|
||||
})
|
||||
"path": self._path
|
||||
}
|
||||
else:
|
||||
yield from compute.post("/projects", data={
|
||||
data = {
|
||||
"name": self._name,
|
||||
"project_id": self._id,
|
||||
"variables": self._variables
|
||||
})
|
||||
"project_id": self._id
|
||||
}
|
||||
|
||||
if self._variables:
|
||||
data["variables"] = self._variables
|
||||
|
||||
yield from compute.post("/projects", data=data)
|
||||
|
||||
self._project_created_on_compute.add(compute)
|
||||
yield from node.create()
|
||||
@@ -521,7 +525,8 @@ class Project:
|
||||
self.dump()
|
||||
return node
|
||||
|
||||
@locked_coroutine
|
||||
@locking
|
||||
@asyncio.coroutine
|
||||
def __delete_node_links(self, node):
|
||||
"""
|
||||
Delete all link connected to this node.
|
||||
@@ -779,7 +784,8 @@ class Project:
|
||||
def _topology_file(self):
|
||||
return os.path.join(self.path, self._filename)
|
||||
|
||||
@locked_coroutine
|
||||
@locking
|
||||
@asyncio.coroutine
|
||||
def open(self):
|
||||
"""
|
||||
Load topology elements
|
||||
@@ -884,7 +890,7 @@ class Project:
|
||||
# Start all in the background without waiting for completion
|
||||
# we ignore errors because we want to let the user open
|
||||
# their project and fix it
|
||||
asyncio.async(self.start_all())
|
||||
asyncio_ensure_future(self.start_all())
|
||||
|
||||
@asyncio.coroutine
|
||||
def wait_loaded(self):
|
||||
@@ -928,7 +934,7 @@ class Project:
|
||||
yield from wait_run_in_executor(self._create_duplicate_project_file, project_path, zipstream)
|
||||
with open(project_path, "rb") as f:
|
||||
project = yield from import_project(self._controller, str(uuid.uuid4()), f, location=location, name=name, keep_compute_id=True)
|
||||
except (OSError, UnicodeEncodeError) as e:
|
||||
except (ValueError, OSError, UnicodeEncodeError) as e:
|
||||
raise aiohttp.web.HTTPConflict(text="Can not duplicate project: {}".format(str(e)))
|
||||
|
||||
if previous_status == "closed":
|
||||
|
||||
@@ -101,7 +101,7 @@ class Snapshot:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
zipstream = yield from export_project(self._project, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
||||
yield from wait_run_in_executor(self._create_snapshot_file, zipstream)
|
||||
except OSError as e:
|
||||
except (ValueError, OSError, RuntimeError) as e:
|
||||
raise aiohttp.web.HTTPConflict(text="Could not create snapshot file '{}': {}".format(self.path, e))
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
@@ -54,7 +54,7 @@ class UDPLink(Link):
|
||||
try:
|
||||
(node1_host, node2_host) = yield from node1.compute.get_ip_on_same_subnet(node2.compute)
|
||||
except ValueError as e:
|
||||
raise aiohttp.web.HTTPConflict(text=str(e))
|
||||
raise aiohttp.web.HTTPConflict(text="Cannot get an IP address on same subnet: {}".format(e))
|
||||
|
||||
# Reserve a UDP port on both side
|
||||
response = yield from node1.compute.post("/projects/{}/ports/udp".format(self._project.id))
|
||||
|
||||
Reference in new issue
Block a user