mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +00:00
Auto create the local compute node
This commit is contained in:
parent
b126c396c9
commit
df73f80bf5
@ -45,6 +45,18 @@ class Controller:
|
||||
config_path = os.path.join(os.path.expanduser("~"), ".config", "GNS3")
|
||||
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):
|
||||
"""
|
||||
Save the controller configuration on disk
|
||||
@ -98,9 +110,7 @@ class Controller:
|
||||
|
||||
# We disallow to create from the outside the
|
||||
if compute_id == 'local':
|
||||
compute_server = self._create_local_compute()
|
||||
self.notification.emit("compute.created", compute_server.__json__())
|
||||
return compute_server
|
||||
return None
|
||||
|
||||
compute_server = Compute(compute_id=compute_id, controller=self, **kwargs)
|
||||
self._computes[compute_id] = compute_server
|
||||
@ -110,20 +120,6 @@ class Controller:
|
||||
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
||||
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
|
||||
def notification(self):
|
||||
"""
|
||||
@ -145,8 +141,6 @@ class Controller:
|
||||
try:
|
||||
return self._computes[compute_id]
|
||||
except KeyError:
|
||||
if compute_id == "local":
|
||||
return self._create_local_compute()
|
||||
raise aiohttp.web.HTTPNotFound(text="Compute ID {} doesn't exist".format(compute_id))
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -112,13 +112,15 @@ def test_getCompute(controller, async_run):
|
||||
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 default test controller is not local
|
||||
assert len(controller._computes) == 0
|
||||
Config.instance().set("Server", "local", True)
|
||||
async_run(controller.add_compute("local", host="example.org"))
|
||||
assert controller.get_compute("local").host == "localhost"
|
||||
c = Controller()
|
||||
assert len(c._computes) == 1
|
||||
|
||||
|
||||
def test_addProject(controller, async_run):
|
||||
|
Loading…
Reference in New Issue
Block a user