第 18 章 生成自定义 libvirt 脚本

18.1. 使用带 virsh 的 XML 配置文件

这部分将为旨在使用 libvirt 编写自定义脚本的程序员和系统管理员提供一些有用信息。

第 17 章 提示及陷阱 is recommended reading for programmers thinking of writing new applications which use libvirt.

18.1. 使用带 virsh 的 XML 配置文件

virsh can handle XML configuration files. You may want to use this to your advantage for scripting large deployments with special options. You can add devices defined in an XML file to a running para-virtualized guest. For example, to add a ISO file as hdc to a running guest create an XML file:

  1. # cat satelliteiso.xml
  2. <disk type="file" device="disk">
  3. <driver name="file"/>
  4. <source file="/var/lib/libvirt/images/rhn-satellite-5.0.1-11-redhat-linux-as-i386-4-embedded-oracle.iso"/>
  5. <target dev="hdc"/>
  6. <readonly/>
  7. </disk>

Run virsh attach-device to attach the ISO as hdc to a guest called “satellite” :

  1. # virsh attach-device satellite satelliteiso.xml