mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge remote-tracking branch 'origin/2.0' into 2.0
Conflicts: gns3server/controller/project.py tests/compute/test_project.py tests/controller/test_project.py
This commit is contained in:
commit
483431438a
17 files changed
+208
-53
No files matched your search
@@ -91,14 +91,35 @@ class Controller:
|
||||
"""
|
||||
Add a server to the dictionnary of computes controlled by GNS3
|
||||
|
||||
:param compute_id: Id of the compute node
|
||||
:param kwargs: See the documentation of Compute
|
||||
"""
|
||||
|
||||
# We dissallow to create from the outside the
|
||||
if compute_id == 'local':
|
||||
return self._createLocalCompute()
|
||||
|
||||
if compute_id not in self._computes:
|
||||
compute = Compute(compute_id=compute_id, controller=self, **kwargs)
|
||||
self._computes[compute_id] = compute
|
||||
self.save()
|
||||
return self._computes[compute_id]
|
||||
|
||||
def _createLocalCompute(self):
|
||||
"""
|
||||
Create the local compute node. It's the controller itself
|
||||
"""
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
self._computes["local"] = Compute(
|
||||
compute_id="local",
|
||||
controller=self,
|
||||
protocol=server_config.get("protocol", "http"),
|
||||
host=server_config.get("host", "localhost"),
|
||||
port=server_config.getint("port", 3080),
|
||||
user=server_config.get("user", ""),
|
||||
password=server_config.get("password", ""))
|
||||
return self._computes["local"]
|
||||
|
||||
@property
|
||||
def computes(self):
|
||||
"""
|
||||
@@ -113,6 +134,8 @@ class Controller:
|
||||
try:
|
||||
return self._computes[compute_id]
|
||||
except KeyError:
|
||||
if compute_id == "local":
|
||||
return self._createLocalCompute()
|
||||
raise aiohttp.web.HTTPNotFound(text="Compute ID {} doesn't exist".format(compute_id))
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
@@ -51,6 +51,7 @@ class Compute:
|
||||
self._controller = controller
|
||||
self._setAuth(user, password)
|
||||
self._session = aiohttp.ClientSession()
|
||||
self._version = None
|
||||
|
||||
# If the compute is local but the compute id is local
|
||||
# it's a configuration issue
|
||||
@@ -71,6 +72,20 @@ class Compute:
|
||||
else:
|
||||
self._auth = None
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
"""
|
||||
:returns: Version of compute node (string or None if not connected)
|
||||
"""
|
||||
return self._version
|
||||
|
||||
@property
|
||||
def connected(self):
|
||||
"""
|
||||
:returns: True if compute node is connected
|
||||
"""
|
||||
return self._connected
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
@@ -160,6 +175,7 @@ class Compute:
|
||||
|
||||
if "version" not in response.json:
|
||||
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
|
||||
self._version = response.json["version"]
|
||||
if parse_version(__version__)[:2] != parse_version(response.json["version"])[:2]:
|
||||
raise aiohttp.web.HTTPConflict(text="The server {} versions are not compatible {} != {}".format(self._id, __version__, response.json["version"]))
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ from .node import Node
|
||||
from .udp_link import UDPLink
|
||||
from ..notification_queue import NotificationQueue
|
||||
from ..config import Config
|
||||
from ..utils.path import check_path_allowed, get_default_project_directory
|
||||
|
||||
|
||||
class Project:
|
||||
@@ -50,10 +51,8 @@ class Project:
|
||||
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(project_id))
|
||||
self._id = project_id
|
||||
|
||||
#TODO: Security check if not locale
|
||||
if path is None:
|
||||
location = self._config().get("project_directory", self._get_default_project_directory())
|
||||
path = os.path.join(location, self._id)
|
||||
path = os.path.join(get_default_project_directory(), self._id)
|
||||
self.path = path
|
||||
|
||||
self._temporary = temporary
|
||||
@@ -62,6 +61,9 @@ class Project:
|
||||
self._links = {}
|
||||
self._listeners = set()
|
||||
|
||||
# Create the project on demand on the compute node
|
||||
self._project_created_on_compute = set()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
@@ -80,6 +82,7 @@ class Project:
|
||||
|
||||
@path.setter
|
||||
def path(self, path):
|
||||
check_path_allowed(path)
|
||||
try:
|
||||
os.makedirs(path, exist_ok=True)
|
||||
except OSError as e:
|
||||
@@ -105,7 +108,6 @@ class Project:
|
||||
@asyncio.coroutine
|
||||
def add_compute(self, compute):
|
||||
self._computes.add(compute)
|
||||
yield from compute.post("/projects", self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_node(self, compute, node_id, **kwargs):
|
||||
@@ -116,6 +118,9 @@ class Project:
|
||||
"""
|
||||
if node_id not in self._nodes:
|
||||
node = Node(self, compute, node_id=node_id, **kwargs)
|
||||
if compute not in self._project_created_on_compute:
|
||||
yield from compute.post("/projects", self)
|
||||
self._project_created_on_compute.add(compute)
|
||||
yield from node.create()
|
||||
self._nodes[node.id] = node
|
||||
return node
|
||||
|
||||
Reference in new issue
Block a user