mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-19 04:47:54 +00:00
Merge branch '2.0' into 2.1
This commit is contained in:
commit
5036079deb
@ -53,6 +53,9 @@ class Controller:
|
|||||||
self.gns3vm = GNS3VM(self)
|
self.gns3vm = GNS3VM(self)
|
||||||
self.symbols = Symbols()
|
self.symbols = Symbols()
|
||||||
|
|
||||||
|
# Store settings shared by the different GUI will be replace by dedicated API later
|
||||||
|
self._settings = None
|
||||||
|
|
||||||
self._config_file = os.path.join(Config.instance().config_dir, "gns3_controller.conf")
|
self._config_file = os.path.join(Config.instance().config_dir, "gns3_controller.conf")
|
||||||
log.info("Load controller configuration file {}".format(self._config_file))
|
log.info("Load controller configuration file {}".format(self._config_file))
|
||||||
|
|
||||||
@ -83,6 +86,7 @@ class Controller:
|
|||||||
if name == "gns3vm":
|
if name == "gns3vm":
|
||||||
name = "Main server"
|
name = "Main server"
|
||||||
|
|
||||||
|
computes = yield from self._load_controller_settings()
|
||||||
yield from self.add_compute(compute_id="local",
|
yield from self.add_compute(compute_id="local",
|
||||||
name=name,
|
name=name,
|
||||||
protocol=server_config.get("protocol", "http"),
|
protocol=server_config.get("protocol", "http"),
|
||||||
@ -92,7 +96,11 @@ class Controller:
|
|||||||
user=server_config.get("user", ""),
|
user=server_config.get("user", ""),
|
||||||
password=server_config.get("password", ""),
|
password=server_config.get("password", ""),
|
||||||
force=True)
|
force=True)
|
||||||
yield from self._load_controller_settings()
|
for c in computes:
|
||||||
|
try:
|
||||||
|
yield from self.add_compute(**c)
|
||||||
|
except aiohttp.web_exceptions.HTTPConflict:
|
||||||
|
pass # Skip not available servers at loading
|
||||||
yield from self.load_projects()
|
yield from self.load_projects()
|
||||||
yield from self.gns3vm.auto_start_vm()
|
yield from self.gns3vm.auto_start_vm()
|
||||||
yield from self._project_auto_open()
|
yield from self._project_auto_open()
|
||||||
@ -116,6 +124,9 @@ class Controller:
|
|||||||
"""
|
"""
|
||||||
Save the controller configuration on disk
|
Save the controller configuration on disk
|
||||||
"""
|
"""
|
||||||
|
# We don't save during the loading otherwise we could lost stuff
|
||||||
|
if self._settings is None:
|
||||||
|
return
|
||||||
data = {
|
data = {
|
||||||
"computes": [],
|
"computes": [],
|
||||||
"settings": self._settings,
|
"settings": self._settings,
|
||||||
@ -151,18 +162,17 @@ class Controller:
|
|||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
except (OSError, ValueError) as e:
|
except (OSError, ValueError) as e:
|
||||||
log.critical("Cannot load %s: %s", self._config_file, str(e))
|
log.critical("Cannot load %s: %s", self._config_file, str(e))
|
||||||
return
|
self._settings = {}
|
||||||
|
return []
|
||||||
|
|
||||||
if "settings" in data:
|
if "settings" in data and data["settings"] is not None:
|
||||||
self._settings = data["settings"]
|
self._settings = data["settings"]
|
||||||
|
else:
|
||||||
|
self._settings = {}
|
||||||
if "gns3vm" in data:
|
if "gns3vm" in data:
|
||||||
self.gns3vm.settings = data["gns3vm"]
|
self.gns3vm.settings = data["gns3vm"]
|
||||||
|
|
||||||
for c in data["computes"]:
|
return data["computes"]
|
||||||
try:
|
|
||||||
yield from self.add_compute(**c)
|
|
||||||
except aiohttp.web_exceptions.HTTPConflict:
|
|
||||||
pass # Skip not available servers at loading
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def load_projects(self):
|
def load_projects(self):
|
||||||
@ -264,12 +274,14 @@ class Controller:
|
|||||||
"headless": vm_settings.get("headless", False),
|
"headless": vm_settings.get("headless", False),
|
||||||
"vmname": vmname
|
"vmname": vmname
|
||||||
}
|
}
|
||||||
|
self._settings = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def settings(self):
|
def settings(self):
|
||||||
"""
|
"""
|
||||||
Store settings shared by the different GUI will be replace by dedicated API later. Dictionnary
|
Store settings shared by the different GUI will be replace by dedicated API later. Dictionnary
|
||||||
"""
|
"""
|
||||||
|
assert self._settings is not None
|
||||||
return self._settings
|
return self._settings
|
||||||
|
|
||||||
@settings.setter
|
@settings.setter
|
||||||
|
@ -249,13 +249,6 @@ class WebServer:
|
|||||||
time.sleep(1) # this is to prevent too many request to slow down the server
|
time.sleep(1) # this is to prevent too many request to slow down the server
|
||||||
log.debug("UDP server discovery stopped")
|
log.debug("UDP server discovery stopped")
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def _on_startup(self, *args):
|
|
||||||
"""
|
|
||||||
Called when the HTTP server start
|
|
||||||
"""
|
|
||||||
yield from Controller.instance().start()
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
Starts the server.
|
Starts the server.
|
||||||
@ -295,9 +288,8 @@ class WebServer:
|
|||||||
for key, val in os.environ.items():
|
for key, val in os.environ.items():
|
||||||
log.debug("ENV %s=%s", key, val)
|
log.debug("ENV %s=%s", key, val)
|
||||||
|
|
||||||
|
self._loop.run_until_complete(Controller.instance().start())
|
||||||
self._app = aiohttp.web.Application()
|
self._app = aiohttp.web.Application()
|
||||||
# Background task started with the server
|
|
||||||
self._app.on_startup.append(self._on_startup)
|
|
||||||
|
|
||||||
# Allow CORS for this domains
|
# Allow CORS for this domains
|
||||||
cors = aiohttp_cors.setup(self._app, defaults={
|
cors = aiohttp_cors.setup(self._app, defaults={
|
||||||
|
@ -179,6 +179,7 @@ def controller(tmpdir, controller_config_path):
|
|||||||
Controller._instance = None
|
Controller._instance = None
|
||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
controller._config_file = controller_config_path
|
controller._config_file = controller_config_path
|
||||||
|
controller._settings = {}
|
||||||
return controller
|
return controller
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,23 +57,8 @@ def test_load_controller_settings(controller, controller_config_path, async_run)
|
|||||||
data["gns3vm"] = {"vmname": "Test VM"}
|
data["gns3vm"] = {"vmname": "Test VM"}
|
||||||
with open(controller_config_path, "w+") as f:
|
with open(controller_config_path, "w+") as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
async_run(controller._load_controller_settings())
|
assert len(async_run(controller._load_controller_settings())) == 1
|
||||||
assert controller.settings["IOU"]
|
assert controller.settings["IOU"]
|
||||||
assert controller.computes["test1"].__json__() == {
|
|
||||||
"compute_id": "test1",
|
|
||||||
"connected": False,
|
|
||||||
"host": "localhost",
|
|
||||||
"port": 8000,
|
|
||||||
"protocol": "http",
|
|
||||||
"user": "admin",
|
|
||||||
"name": "http://admin@localhost:8000",
|
|
||||||
"cpu_usage_percent": None,
|
|
||||||
"memory_usage_percent": None,
|
|
||||||
"capabilities": {
|
|
||||||
"version": None,
|
|
||||||
"node_types": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert controller.gns3vm.settings["vmname"] == "Test VM"
|
assert controller.gns3vm.settings["vmname"] == "Test VM"
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user