1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-24 15:58:08 +00:00

A client could not erase the local compute node config in the controller

Fix #499
This commit is contained in:
Julien Duponchelle 2016-05-11 15:01:57 +02:00
parent 4342b4346e
commit 390401000f
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 32 additions and 0 deletions

View File

@ -91,14 +91,35 @@ class Controller:
""" """
Add a server to the dictionnary of computes controlled by GNS3 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 :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: if compute_id not in self._computes:
compute = Compute(compute_id=compute_id, controller=self, **kwargs) compute = Compute(compute_id=compute_id, controller=self, **kwargs)
self._computes[compute_id] = compute self._computes[compute_id] = compute
self.save() self.save()
return self._computes[compute_id] 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.get("port", 3080),
user=server_config.get("user", ""),
password=server_config.get("password", ""))
return self._computes["local"]
@property @property
def computes(self): def computes(self):
""" """
@ -113,6 +134,8 @@ class Controller:
try: try:
return self._computes[compute_id] return self._computes[compute_id]
except KeyError: except KeyError:
if compute_id == "local":
return self._createLocalCompute()
raise aiohttp.web.HTTPNotFound(text="Compute ID {} doesn't exist".format(compute_id)) raise aiohttp.web.HTTPNotFound(text="Compute ID {} doesn't exist".format(compute_id))
@asyncio.coroutine @asyncio.coroutine

View File

@ -108,6 +108,15 @@ def test_getCompute(controller, async_run):
assert controller.getCompute("dsdssd") assert controller.getCompute("dsdssd")
def test_addComputeLocal(controller, controller_config_path, async_run):
"""
The local node is the controller itself you can not change the informations
"""
Config.instance().set("Server", "local", True)
async_run(controller.addCompute("local", host="example.org"))
assert controller.getCompute("local").host == "localhost"
def test_addProject(controller, async_run): def test_addProject(controller, async_run):
uuid1 = str(uuid.uuid4()) uuid1 = str(uuid.uuid4())
uuid2 = str(uuid.uuid4()) uuid2 = str(uuid.uuid4())