diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index 48b6ebac..53518b26 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -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 diff --git a/tests/controller/test_controller.py b/tests/controller/test_controller.py index 57f7b52e..dd9adc02 100644 --- a/tests/controller/test_controller.py +++ b/tests/controller/test_controller.py @@ -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())