Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/ugrd/kmod/platform.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from zenlib.util import colorize as c_
from zenlib.util import contains

__version__ = "0.1.1"
__version__ = "0.1.2"

VM_PRODUCT_NAMES = {
"Virtual Machine": ["virtio_blk"],
Expand Down Expand Up @@ -30,16 +30,22 @@ def get_platform_info(self):

@contains("hostonly", "hostonly is not enabled, skipping VM detection.", log_level=30)
def autodetect_virtual_machine(self):
"""Detects if the system is running in a virtual machine, adds relevant kernel modules to the list.
"""Detects if the system is running in a virtual machine, using DMI information.
Uses the system vendor to add required kmods
uses the product name to add additional kmods.

Sets the `virtual_machine` attribute to True if a VM is detected, to be used by other modules.
"""
kmods = set()
kmods.update(VM_PRODUCT_NAMES.get(self["_dmi_product_name"], []))
kmods.update(VM_VENDOR_NAMES.get(self["_dmi_system_vendor"], []))
vendor_kmods = VM_VENDOR_NAMES.get(self["_dmi_system_vendor"], [])
product_kmods = VM_PRODUCT_NAMES.get(self["_dmi_product_name"], [])
kmods = set(vendor_kmods + product_kmods)

if kmods:
self.logger.info(
f"[{c_(self['_dmi_system_vendor'], color='cyan', bold=True)}]({c_(self['_dmi_product_name'], color='cyan', bright=True)}) Detected VM kmods: {c_((' ').join(kmods), color='magenta', bright=True)}"
)
self["virtual_machine"] = True
self["kmod_init"] = list(kmods)
if vendor_kmods:
self["kmod_init"] = vendor_kmods
if product_kmods:
self["_kmod_auto"] = product_kmods