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

Set default disk interface type to "none".

Fail-safe: use "ide" if an image is set but no interface type is configured.
Use the HDA disk interface type if none has been configured for HDD.

(cherry picked from commit 464fd804ce)
This commit is contained in:
grossmj 2020-08-15 16:14:16 +09:30 committed by Bernhard Ehlers
parent a56b816c1a
commit ec02150fd2
2 changed files with 17 additions and 16 deletions

View File

@ -104,10 +104,10 @@ class QemuVM(BaseNode):
self._hdb_disk_image = "" self._hdb_disk_image = ""
self._hdc_disk_image = "" self._hdc_disk_image = ""
self._hdd_disk_image = "" self._hdd_disk_image = ""
self._hda_disk_interface = "ide" self._hda_disk_interface = "none"
self._hdb_disk_interface = "ide" self._hdb_disk_interface = "none"
self._hdc_disk_interface = "ide" self._hdc_disk_interface = "none"
self._hdd_disk_interface = "ide" self._hdd_disk_interface = "none"
self._cdrom_image = "" self._cdrom_image = ""
self._bios_image = "" self._bios_image = ""
self._boot_priority = "c" self._boot_priority = "c"
@ -1782,13 +1782,15 @@ class QemuVM(BaseNode):
for disk_index, drive in enumerate(drives): for disk_index, drive in enumerate(drives):
disk_image = getattr(self, "_hd{}_disk_image".format(drive)) disk_image = getattr(self, "_hd{}_disk_image".format(drive))
interface = getattr(self, "hd{}_disk_interface".format(drive))
if not disk_image: if not disk_image:
continue continue
disk_name = "hd" + drive interface = getattr(self, "hd{}_disk_interface".format(drive))
# fail-safe: use "ide" if there is a disk image and no interface type has been explicitly configured
if interface == "none":
setattr(self, "hd{}_disk_interface".format(drive), "ide")
disk_name = "hd" + drive
if not os.path.isfile(disk_image) or not os.path.exists(disk_image): if not os.path.isfile(disk_image) or not os.path.exists(disk_image):
if os.path.islink(disk_image): if os.path.islink(disk_image):
raise QemuError("{} disk image '{}' linked to '{}' is not accessible".format(disk_name, disk_image, os.path.realpath(disk_image))) raise QemuError("{} disk image '{}' linked to '{}' is not accessible".format(disk_name, disk_image, os.path.realpath(disk_image)))
@ -1848,9 +1850,9 @@ class QemuVM(BaseNode):
else: else:
disk_name = getattr(self, "config_disk_name") disk_name = getattr(self, "config_disk_name")
disk = os.path.join(self.working_dir, disk_name) disk = os.path.join(self.working_dir, disk_name)
interface = getattr(self, "hdd_disk_interface", "ide") if self.hdd_disk_interface == "none":
if interface == "ide": # use the HDA interface type if none has been configured for HDD
interface = getattr(self, "hda_disk_interface", "none") self.hdd_disk_interface = getattr(self, "hda_disk_interface", "none")
await self._import_config() await self._import_config()
disk_exists = os.path.exists(disk) disk_exists = os.path.exists(disk)
if not disk_exists: if not disk_exists:
@ -1860,8 +1862,7 @@ class QemuVM(BaseNode):
except OSError as e: except OSError as e:
log.warning("Could not create '{}' disk image: {}".format(disk_name, e)) log.warning("Could not create '{}' disk image: {}".format(disk_name, e))
if disk_exists: if disk_exists:
options.extend(self._disk_interface_options(disk, 3, interface, "raw")) options.extend(self._disk_interface_options(disk, 3, self.hdd_disk_interface, "raw"))
self.hdd_disk_image = disk
return options return options

View File

@ -116,7 +116,7 @@ QEMU_TEMPLATE_PROPERTIES = {
"hda_disk_interface": { "hda_disk_interface": {
"description": "QEMU hda interface", "description": "QEMU hda interface",
"enum": ["ide", "sata", "nvme", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"], "enum": ["ide", "sata", "nvme", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"],
"default": "ide" "default": "none"
}, },
"hdb_disk_image": { "hdb_disk_image": {
"description": "QEMU hdb disk image path", "description": "QEMU hdb disk image path",
@ -126,7 +126,7 @@ QEMU_TEMPLATE_PROPERTIES = {
"hdb_disk_interface": { "hdb_disk_interface": {
"description": "QEMU hdb interface", "description": "QEMU hdb interface",
"enum": ["ide", "sata", "nvme", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"], "enum": ["ide", "sata", "nvme", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"],
"default": "ide" "default": "none"
}, },
"hdc_disk_image": { "hdc_disk_image": {
"description": "QEMU hdc disk image path", "description": "QEMU hdc disk image path",
@ -136,7 +136,7 @@ QEMU_TEMPLATE_PROPERTIES = {
"hdc_disk_interface": { "hdc_disk_interface": {
"description": "QEMU hdc interface", "description": "QEMU hdc interface",
"enum": ["ide", "sata", "nvme", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"], "enum": ["ide", "sata", "nvme", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"],
"default": "ide" "default": "none"
}, },
"hdd_disk_image": { "hdd_disk_image": {
"description": "QEMU hdd disk image path", "description": "QEMU hdd disk image path",
@ -146,7 +146,7 @@ QEMU_TEMPLATE_PROPERTIES = {
"hdd_disk_interface": { "hdd_disk_interface": {
"description": "QEMU hdd interface", "description": "QEMU hdd interface",
"enum": ["ide", "sata", "nvme", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"], "enum": ["ide", "sata", "nvme", "scsi", "sd", "mtd", "floppy", "pflash", "virtio", "none"],
"default": "ide" "default": "none"
}, },
"cdrom_image": { "cdrom_image": {
"description": "QEMU cdrom image path", "description": "QEMU cdrom image path",