Red Hat Training

A Red Hat training course is available for Red Hat Virtualization

A.10. 使用 VDSM Hooking 模块

VDSM 附带了 Python hooking 模块,为 VDSM hook 脚本提供助手功能。此模块作为示例提供,仅与使用 Python 编写的 VDSM hook 相关。
hooking 模块支持将虚拟机 libvirt XML 读入 DOM 对象。然后,hook 脚本可以使用 xml.domhttp://docs.python.org/release/2.6/library/xml.dom.html()中构建的 Python 来操作对象。
然后,可以使用 hooking 模块将修改的对象保存到 libvirt XML 中。hooking 模块提供以下功能来支持 hook 开发:

表 A.2. hooking 模块功能

Name 参数 Description
tobool 字符串 将字符串 "true" 或 "false" 转换为布尔值
read_domxml - 将虚拟机的 libvirt XML 读到 DOM 对象中
write_domxml DOM 对象 DOM 对象写入虚拟机的 libvirt XML