mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-23 23:38:21 +00:00
A client could not erase the local compute node config in the controller
Fix #499
This commit is contained in:
parent
4342b4346e
commit
390401000f
@ -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
|
||||
|
@ -108,6 +108,15 @@ def test_getCompute(controller, async_run):
|
||||
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):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
uuid2 = str(uuid.uuid4())
|
||||
|
Loading…
Reference in New Issue
Block a user