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

Fix #499
This commit is contained in:
Julien Duponchelle committed 2016-05-11 15:02:35 +02:00
1 parent 4342b4346e
commit 390401000f
2 files changed
+32

No files matched your search

+23
View File
@@ -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.get("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