在nova/virt/driver.py 中的ComputeDriver 类中定义了load_compute_driver来加载用于虚拟化的driver。
def load_compute_driver(virtapi, compute_driver=None):
"""Load a compute driver module.
Load the compute driver module specified by the compute_driver
configuration option or, if supplied, the driver name supplied as an
argument.
Compute drivers constructors take a VirtAPI object as their first object
and this must be supplied.
:param virtapi: a VirtAPI instance
:param compute_driver: a compute driver name to override the config opt
:returns: a ComputeDriver instance
"""
if not compute_driver:
compute_driver = CONF.compute_driver
if not compute_driver:
LOG.error(_LE("Compute driver option required, but not specified"))
sys.exit(1)
LOG.info(_LI("Loading compute driver '%s'"), compute_driver)
try:
driver = importutils.import_object(
'nova.virt.%s' % compute_driver,
virtapi)
return utils.check_isinstance(driver, ComputeDriver)
except ImportError:
LOG.exception(_LE("Unable to load the virtualization driver"))
sys.exit(1)
可以compute_driver 是在CONF.compute_driver得到的,本例中compute_driver=libvirt.LibvirtDriver
因此最终会通过import_object 导入nova.virt.libvirt.LibvirtDriver
nova 根据conf动态加载虚拟化驱动
最新推荐文章于 2022-12-29 12:12:52 发布