Import GNS3VM settings from 1.5

Fix #643
pull/712/head
Julien Duponchelle 8 years ago
parent 0573c3f7d5
commit bc5b5969eb
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

@ -180,7 +180,8 @@ class Controller:
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", []):
server_settings = data.get("Servers", {})
for remote in server_settings.get("remote_servers", []):
yield from self.add_compute(
host=remote.get("host", "localhost"),
port=remote.get("port", 3080),
@ -189,6 +190,27 @@ class Controller:
user=remote.get("user"),
password=remote.get("password")
)
if "vm" in server_settings:
vm_settings = server_settings["vm"]
if vm_settings["virtualization"] == "VMware":
engine = "vmware"
vmname = vm_settings.get("vmname", "")
elif vm_settings["virtualization"] == "VirtualBox":
engine = "virtualbox"
vmname = vm_settings.get("vmname", "")
else:
engine = "remote"
# In case of remote server we match the compute with url parameter
for compute in self._computes.values():
if compute.host == vm_settings.get("remote_vm_host") and compute.port == vm_settings.get("remote_vm_port"):
vmname = compute.name
self.gns3vm.settings = {
"engine": engine,
"enable": vm_settings.get("auto_start", False),
"auto_stop": vm_settings.get("auto_stop", True),
"headless": vm_settings.get("headless", False),
"vmname": vmname
}
@property
def settings(self):

@ -222,6 +222,7 @@ class GNS3VM:
name="GNS3 VM ({})".format(self._current_engine().vmname),
host=None,
force=True)
@asyncio.coroutine
def auto_stop_vm(self):
if self.enable and self.auto_stop:
@ -241,13 +242,13 @@ class GNS3VM:
engine.vmname = self._settings["vmname"]
yield from engine.start()
yield from self._controller.add_compute(compute_id="vm",
name="GNS3 VM ({})".format(engine.vmname),
protocol=self.protocol,
host=self.ip_address,
port=self.port,
user=self.user,
password=self.password,
force=True)
name="GNS3 VM ({})".format(engine.vmname),
protocol=self.protocol,
host=self.ip_address,
port=self.port,
user=self.user,
password=self.password,
force=True)
@locked_coroutine
def _stop(self):

@ -80,10 +80,10 @@ def test_load(controller, controller_config_path, async_run):
assert controller.gns3vm.settings["vmname"] == "Test VM"
def test_import_computes(controller, controller_config_path, async_run):
def test_import_computes_1_x(controller, controller_config_path, async_run):
"""
At first start the server should import the
computes from the gns3_gui
computes from the gns3_gui 1.X
"""
gns3_gui_conf = {
"Servers": {
@ -115,6 +115,96 @@ def test_import_computes(controller, controller_config_path, async_run):
assert compute.password is None
def test_import_gns3vm_1_x(controller, controller_config_path, async_run):
"""
At first start the server should import the
gns3vm settings from the gns3_gui 1.X
"""
gns3_gui_conf = {
"Servers": {
"vm": {
"adjust_local_server_ip": True,
"auto_start": True,
"auto_stop": False,
"headless": True,
"remote_vm_host": "",
"remote_vm_password": "",
"remote_vm_port": 3080,
"remote_vm_protocol": "http",
"remote_vm_url": "",
"remote_vm_user": "",
"virtualization": "VMware",
"vmname": "GNS3 VM",
"vmx_path": "/Users/joe/Documents/Virtual Machines.localized/GNS3 VM.vmwarevm/GNS3 VM.vmx"
}
}
}
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)
controller.gns3vm.settings["engine"] = None
async_run(controller.load())
assert controller.gns3vm.settings["engine"] == "vmware"
assert controller.gns3vm.settings["enable"]
assert controller.gns3vm.settings["headless"]
assert controller.gns3vm.settings["auto_stop"] is False
assert controller.gns3vm.settings["vmname"] == "GNS3 VM"
def test_import_remote_gns3vm_1_x(controller, controller_config_path, async_run):
"""
At first start the server should import the
computes and remote GNS3 VM from the gns3_gui 1.X
"""
gns3_gui_conf = {
"Servers": {
"remote_servers": [
{
"host": "127.0.0.1",
"password": "",
"port": 3080,
"protocol": "http",
"url": "http://127.0.0.1:3080",
"user": ""
},
{
"host": "127.0.0.1",
"password": "",
"port": 3081,
"protocol": "http",
"url": "http://127.0.0.1:3081",
"user": ""
}
],
"vm": {
"adjust_local_server_ip": True,
"auto_start": True,
"auto_stop": False,
"headless": True,
"remote_vm_host": "127.0.0.1",
"remote_vm_password": "",
"remote_vm_port": 3081,
"remote_vm_protocol": "http",
"remote_vm_url": "http://127.0.0.1:3081",
"remote_vm_user": "",
"virtualization": "remote",
"vmname": "GNS3 VM",
"vmx_path": "/Users/joe/Documents/Virtual Machines.localized/GNS3 VM.vmwarevm/GNS3 VM.vmx"
}
}
}
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 controller.gns3vm.settings["engine"] == "remote"
assert controller.gns3vm.settings["vmname"] == "http://127.0.0.1:3081"
def test_settings(controller):
controller._notification = MagicMock()
controller.settings = {"a": 1}

Loading…
Cancel
Save