From 906f29d5fc1ff3641657e11d5c58dcfa2f95dbb3 Mon Sep 17 00:00:00 2001 From: David Kreitschmann Date: Tue, 3 Sep 2019 15:54:51 +0200 Subject: [PATCH 1/2] Add id value to all qemu drives A fixed id doesn't hurt and now we can select Disk Interface=none in GNS3 and e.g. attach the volume as a USB thumb drive with -device usb-storage,drive=drive0,... --- gns3server/compute/qemu/qemu_vm.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 62eaef90..df922708 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -1641,10 +1641,10 @@ class QemuVM(BaseNode): if interface == "sata": # special case, sata controller doesn't exist in Qemu options.extend(["-device", 'ahci,id=ahci{},bus=pci.{}'.format(disk_index, disk_index)]) - options.extend(["-drive", 'file={},if=none,id=drive-sata-disk{},index={},media=disk'.format(disk, disk_index, disk_index)]) - options.extend(["-device", 'ide-drive,drive=drive-sata-disk{},bus=ahci{}.0,id=drive-sata-disk{}'.format(disk_index, disk_index, disk_index)]) + options.extend(["-drive", 'file={},if=none,id=drive{},index={},media=disk'.format(disk, disk_index, disk_index)]) + options.extend(["-device", 'ide-drive,drive=drive{},bus=ahci{}.0,id=drive{}'.format(disk_index, disk_index, disk_index)]) else: - options.extend(["-drive", 'file={},if={},index={},media=disk'.format(disk, interface, disk_index)]) + options.extend(["-drive", 'file={},if={},index={},media=disk,id=drive{}'.format(disk, interface, disk_index, disk_index)]) return options From 077432ff2fecf3bd9f6599289c83ca8ffbe1ecd5 Mon Sep 17 00:00:00 2001 From: David Kreitschmann Date: Tue, 3 Sep 2019 16:45:50 +0200 Subject: [PATCH 2/2] Add qemu drive id to tests --- tests/compute/qemu/test_qemu_vm.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 4624ac0e..bdaeeb39 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -352,7 +352,7 @@ def test_disk_options(vm, tmpdir, loop, fake_qemu_img_binary): args, kwargs = process.call_args assert args == (fake_qemu_img_binary, "create", "-o", "backing_file={}".format(vm._hda_disk_image), "-f", "qcow2", os.path.join(vm.working_dir, "hda_disk.qcow2")) - assert options == ['-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk'] + assert options == ['-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk,id=drive0'] def test_cdrom_option(vm, tmpdir, loop, fake_qemu_img_binary): @@ -407,10 +407,10 @@ def test_disk_options_multiple_disk(vm, tmpdir, loop, fake_qemu_img_binary): options = loop.run_until_complete(asyncio.ensure_future(vm._disk_options())) assert options == [ - '-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk', - '-drive', 'file=' + os.path.join(vm.working_dir, "hdb_disk.qcow2") + ',if=ide,index=1,media=disk', - '-drive', 'file=' + os.path.join(vm.working_dir, "hdc_disk.qcow2") + ',if=ide,index=2,media=disk', - '-drive', 'file=' + os.path.join(vm.working_dir, "hdd_disk.qcow2") + ',if=ide,index=3,media=disk' + '-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk,id=drive0', + '-drive', 'file=' + os.path.join(vm.working_dir, "hdb_disk.qcow2") + ',if=ide,index=1,media=disk,id=drive1', + '-drive', 'file=' + os.path.join(vm.working_dir, "hdc_disk.qcow2") + ',if=ide,index=2,media=disk,id=drive2', + '-drive', 'file=' + os.path.join(vm.working_dir, "hdd_disk.qcow2") + ',if=ide,index=3,media=disk,id=drive3' ]