Add UEFI boot mode option for Qemu VMs

This commit is contained in:
grossmj committed 2023-06-21 17:56:34 +09:30
1 parent e5eeab662e
commit 40c265152b
6 files changed
+51

No files matched your search

+29
View File
@@ -153,6 +153,7 @@ class QemuVM(BaseNode):
self._kernel_command_line = ""
self._replicate_network_connection_state = True
self._tpm = False
self._uefi = False
self._create_config_disk = False
self._on_close = "power_off"
self._cpu_throttling = 0 # means no CPU throttling
@@ -900,6 +901,30 @@ class QemuVM(BaseNode):
log.info(f'QEMU VM "{self._name}" [{self._id}] has disabled the Trusted Platform Module (TPM)')
self._tpm = tpm
@property
def uefi(self):
"""
Returns whether UEFI boot mode is activated for this QEMU VM.
:returns: boolean
"""
return self._uefi
@uefi.setter
def uefi(self, uefi):
"""
Sets whether UEFI boot mode is activated for this QEMU VM.
:param uefi: boolean
"""
if uefi:
log.info(f'QEMU VM "{self._name}" [{self._id}] has enabled the UEFI boot mode')
else:
log.info(f'QEMU VM "{self._name}" [{self._id}] has disabled the UEFI boot mode')
self._uefi = uefi
@property
def options(self):
"""
@@ -2245,6 +2270,8 @@ class QemuVM(BaseNode):
options = []
if self._bios_image:
if self._uefi:
raise QemuError("Cannot use a bios image and the UEFI boot mode at the same time")
if not os.path.isfile(self._bios_image) or not os.path.exists(self._bios_image):
if os.path.islink(self._bios_image):
raise QemuError(
@@ -2253,6 +2280,8 @@ class QemuVM(BaseNode):
else:
raise QemuError(f"bios image '{self._bios_image}' is not accessible")
options.extend(["-bios", self._bios_image.replace(",", ",,")])
elif self._uefi:
options.extend(["-bios", "OVMF.fd"]) # the OVMF bios image should be in the image directory
return options
def _linux_boot_options(self):
+1
View File
@@ -204,6 +204,7 @@ class QemuTemplate(Template):
replicate_network_connection_state = Column(Boolean)
create_config_disk = Column(Boolean)
tpm = Column(Boolean)
uefi = Column(Boolean)
on_close = Column(String)
cpu_throttling = Column(Integer)
process_priority = Column(String)
Binary file not shown.
+1
View File
@@ -206,6 +206,7 @@ class QemuBase(BaseModel):
None, description="Automatically create a config disk on HDD disk interface (secondary slave)"
)
tpm: Optional[bool] = Field(None, description="Enable Trusted Platform Module (TPM)")
uefi: Optional[bool] = Field(None, description="Enable UEFI boot mode")
on_close: Optional[QemuOnCloseAction] = Field(None, description="Action to execute on the VM is closed")
cpu_throttling: Optional[int] = Field(None, ge=0, le=800, description="Percentage of CPU allowed for QEMU")
process_priority: Optional[QemuProcessPriority] = Field(None, description="Process priority for QEMU")
@@ -81,6 +81,7 @@ class QemuTemplate(TemplateBase):
False, description="Automatically create a config disk on HDD disk interface (secondary slave)"
)
tpm: Optional[bool] = Field(False, description="Enable Trusted Platform Module (TPM)")
uefi: Optional[bool] = Field(False, description="Enable UEFI boot mode")
on_close: Optional[QemuOnCloseAction] = Field("power_off", description="Action to execute on the VM is closed")
cpu_throttling: Optional[int] = Field(0, ge=0, le=800, description="Percentage of CPU allowed for QEMU")
process_priority: Optional[QemuProcessPriority] = Field("normal", description="Process priority for QEMU")