1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +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.
This commit is contained in:
grossmj 2020-08-15 16:14:16 +09:30
parent 56aba96a5f
commit 464fd804ce
2 changed files with 17 additions and 16 deletions

View File

@ -103,10 +103,10 @@ class QemuVM(BaseNode):
self._hdb_disk_image = ""
self._hdc_disk_image = ""
self._hdd_disk_image = ""
self._hda_disk_interface = "ide"
self._hdb_disk_interface = "ide"
self._hdc_disk_interface = "ide"
self._hdd_disk_interface = "ide"
self._hda_disk_interface = "none"
self._hdb_disk_interface = "none"
self._hdc_disk_interface = "none"
self._hdd_disk_interface = "none"
self._cdrom_image = ""
self._bios_image = ""
self._boot_priority = "c"
@ -1760,13 +1760,15 @@ class QemuVM(BaseNode):
for disk_index, drive in enumerate(drives):
disk_image = getattr(self, "_hd{}_disk_image".format(drive))
interface = getattr(self, "hd{}_disk_interface".format(drive))
if not disk_image:
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 os.path.islink(disk_image):
raise QemuError("{} disk image '{}' linked to '{}' is not accessible".format(disk_name, disk_image, os.path.realpath(disk_image)))
@ -1826,9 +1828,9 @@ class QemuVM(BaseNode):
else:
disk_name = getattr(self, "config_disk_name")
disk = os.path.join(self.working_dir, disk_name)
interface = getattr(self, "hdd_disk_interface", "ide")
if interface == "ide":
interface = getattr(self, "hda_disk_interface", "none")
if self.hdd_disk_interface == "none":
# use the HDA interface type if none has been configured for HDD
self.hdd_disk_interface = getattr(self, "hda_disk_interface", "none")
await self._import_config()
disk_exists = os.path.exists(disk)
if not disk_exists:
@ -1838,8 +1840,7 @@ class QemuVM(BaseNode):
except OSError as e:
log.warning("Could not create '{}' disk image: {}".format(disk_name, e))
if disk_exists:
options.extend(self._disk_interface_options(disk, 3, interface, "raw"))
self.hdd_disk_image = disk
options.extend(self._disk_interface_options(disk, 3, self.hdd_disk_interface, "raw"))
return options

View File

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