1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

Auto create the local compute node

This commit is contained in:
Julien Duponchelle 2016-05-24 15:45:06 +02:00
parent b126c396c9
commit df73f80bf5
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 18 additions and 22 deletions

View File

@ -45,6 +45,18 @@ class Controller:
config_path = os.path.join(os.path.expanduser("~"), ".config", "GNS3") config_path = os.path.join(os.path.expanduser("~"), ".config", "GNS3")
self._config_file = os.path.join(config_path, "gns3_controller.conf") self._config_file = os.path.join(config_path, "gns3_controller.conf")
server_config = Config.instance().get_section_config("Server")
print(server_config)
if server_config.getboolean("local", False) is True:
print("MMOOOOOOONKEYYYYYY")
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", ""))
def save(self): def save(self):
""" """
Save the controller configuration on disk Save the controller configuration on disk
@ -98,9 +110,7 @@ class Controller:
# We disallow to create from the outside the # We disallow to create from the outside the
if compute_id == 'local': if compute_id == 'local':
compute_server = self._create_local_compute() return None
self.notification.emit("compute.created", compute_server.__json__())
return compute_server
compute_server = Compute(compute_id=compute_id, controller=self, **kwargs) compute_server = Compute(compute_id=compute_id, controller=self, **kwargs)
self._computes[compute_id] = compute_server self._computes[compute_id] = compute_server
@ -110,20 +120,6 @@ class Controller:
self.notification.emit("compute.updated", self._computes[compute_id].__json__()) self.notification.emit("compute.updated", self._computes[compute_id].__json__())
return self._computes[compute_id] return self._computes[compute_id]
def _create_local_compute(self):
"""
Create the local compute node. It is 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 @property
def notification(self): def notification(self):
""" """
@ -145,8 +141,6 @@ class Controller:
try: try:
return self._computes[compute_id] return self._computes[compute_id]
except KeyError: except KeyError:
if compute_id == "local":
return self._create_local_compute()
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

@ -112,13 +112,15 @@ def test_getCompute(controller, async_run):
assert controller.get_compute("dsdssd") assert controller.get_compute("dsdssd")
def test_addComputeLocal(controller, controller_config_path, async_run): def test_initControllerLocal(controller, controller_config_path, async_run):
""" """
The local node is the controller itself you can not change the informations The local node is the controller itself you can not change the informations
""" """
# The default test controller is not local
assert len(controller._computes) == 0
Config.instance().set("Server", "local", True) Config.instance().set("Server", "local", True)
async_run(controller.add_compute("local", host="example.org")) c = Controller()
assert controller.get_compute("local").host == "localhost" assert len(c._computes) == 1
def test_addProject(controller, async_run): def test_addProject(controller, async_run):