1
0
mirror of https://github.com/GNS3/gns3-server synced 2025-01-11 08:30:57 +00:00

Look for qemu images in ~/GNS3/images

This commit is contained in:
Julien Duponchelle 2015-03-07 11:56:07 +01:00
parent ee578d3c12
commit 1b68a54234
3 changed files with 31 additions and 4 deletions

View File

@ -32,6 +32,7 @@ from ..adapters.ethernet_adapter import EthernetAdapter
from ..nios.nio_udp import NIOUDP
from ..base_vm import BaseVM
from ...schemas.qemu import QEMU_OBJECT_SCHEMA
from ...config import Config
import logging
log = logging.getLogger(__name__)
@ -182,6 +183,10 @@ class QemuVM(BaseVM):
:param hda_disk_image: QEMU hda disk image path
"""
if hda_disk_image[0] != "/":
server_config = Config.instance().get_section_config("Server")
hda_disk_image = os.path.join(os.path.expanduser(server_config.get("images_path", "~/GNS3/images")), hda_disk_image)
log.info("QEMU VM {name} [id={id}] has set the QEMU hda disk image path to {disk_image}".format(name=self._name,
id=self._id,
disk_image=hda_disk_image))
@ -205,6 +210,10 @@ class QemuVM(BaseVM):
:param hdb_disk_image: QEMU hdb disk image path
"""
if hdb_disk_image[0] != "/":
server_config = Config.instance().get_section_config("Server")
hdb_disk_image = os.path.join(os.path.expanduser(server_config.get("images_path", "~/GNS3/images")), hdb_disk_image)
log.info("QEMU VM {name} [id={id}] has set the QEMU hdb disk image path to {disk_image}".format(name=self._name,
id=self._id,
disk_image=hdb_disk_image))

View File

@ -56,7 +56,7 @@ def test_qemu_create(server, project, base_params):
def test_qemu_create_with_params(server, project, base_params):
params = base_params
params["ram"] = 1024
params["hda_disk_image"] = "hda"
params["hda_disk_image"] = "/tmp/hda"
response = server.post("/projects/{project_id}/qemu/vms".format(project_id=project.id), params, example=True)
assert response.status == 201
@ -64,7 +64,7 @@ def test_qemu_create_with_params(server, project, base_params):
assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id
assert response.json["ram"] == 1024
assert response.json["hda_disk_image"] == "hda"
assert response.json["hda_disk_image"] == "/tmp/hda"
def test_qemu_get(server, project, vm):
@ -122,13 +122,13 @@ def test_qemu_update(server, vm, tmpdir, free_console_port, project):
"name": "test",
"console": free_console_port,
"ram": 1024,
"hdb_disk_image": "hdb"
"hdb_disk_image": "/tmp/hdb"
}
response = server.put("/projects/{project_id}/qemu/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), params, example=True)
assert response.status == 200
assert response.json["name"] == "test"
assert response.json["console"] == free_console_port
assert response.json["hdb_disk_image"] == "hdb"
assert response.json["hdb_disk_image"] == "/tmp/hdb"
assert response.json["ram"] == 1024

View File

@ -284,3 +284,21 @@ def test_build_command_without_display(vm, loop, fake_qemu_binary):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
assert "-nographic" in cmd
def test_hda_disk_image(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
vm.hda_disk_image = "/tmp/test"
assert vm.hda_disk_image == "/tmp/test"
vm.hda_disk_image = "test"
assert vm.hda_disk_image == str(tmpdir / "test")
def test_hdb_disk_image(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
vm.hdb_disk_image = "/tmp/test"
assert vm.hdb_disk_image == "/tmp/test"
vm.hdb_disk_image = "test"
assert vm.hdb_disk_image == str(tmpdir / "test")