1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Import server config from 1.X GUI

This commit is contained in:
Julien Duponchelle 2016-07-14 15:14:56 +02:00
parent 45591aa74b
commit b745397a3a
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 56 additions and 0 deletions

View File

@ -85,6 +85,7 @@ class Controller:
"""
if not os.path.exists(self._config_file):
yield from self._import_gns3_gui_conf()
self.save()
try:
with open(self._config_file) as f:
@ -115,6 +116,26 @@ class Controller:
except OSError as e:
log.error(str(e))
@asyncio.coroutine
def _import_gns3_gui_conf(self):
"""
Import old config from GNS3 GUI
"""
config_file = os.path.join(os.path.dirname(self._config_file), "gns3_gui.conf")
if os.path.exists(config_file):
with open(config_file) as f:
data = json.load(f)
for remote in data.get("Servers", {}).get("remote_servers", []):
print("a")
yield from self.add_compute(
host=remote.get("host", "localhost"),
port=remote.get("port", 3080),
protocol=remote.get("protocol", "http"),
name=remote.get("url"),
user=remote.get("user"),
password=remote.get("password")
)
@property
def settings(self):
"""

View File

@ -73,6 +73,41 @@ def test_load(controller, controller_config_path, async_run):
}
def test_import_computes(controller, controller_config_path, async_run):
"""
At first start the server should import the
computes from the gns3_gui
"""
gns3_gui_conf = {
"Servers": {
"remote_servers": [
{
"host": "127.0.0.1",
"password": "",
"port": 3081,
"protocol": "http",
"url": "http://127.0.0.1:3081",
"user": ""
}
]
}
}
config_dir = os.path.dirname(controller_config_path)
os.makedirs(config_dir, exist_ok=True)
with open(os.path.join(config_dir, "gns3_gui.conf"), "w+") as f:
json.dump(gns3_gui_conf, f)
async_run(controller.load())
assert len(controller.computes) == 1
compute = list(controller.computes.values())[0]
assert compute.host == "127.0.0.1"
assert compute.port == 3081
assert compute.protocol == "http"
assert compute.name == "http://127.0.0.1:3081"
assert compute.user is None
assert compute.password is None
def test_settings(controller):
controller._notification = MagicMock()
controller.settings = {"a": 1}