使用 virsh,我可以使用以下 cli 命令将活动磁盘移动到另一个位置:
virsh blockcopy --domain 'mydomain' vda /my_new_path/disk.qcow2 --wait --verbose --pivot
但是,当我尝试使用 libvirt api 执行相同操作时:
source = 'vda'
dest_xml = """
<disk>
<destination type='file'>/my_new_path/disk.qcow2</destination>
<format type='qcow2'/>
</disk>
"""
domain.blockCopy(source, dest_xml, {}, flags=0)
我收到以下错误:
libvirt.libvirtError: missing source information for device.
我尝试将源设置为 vda,或源文件的完整路径 - 没有成功。
有人解决这个问题了吗?源值需要是多少?
我的错误。有点令人困惑的是,destination块设备路径需要在 xml 片段中标记为“源”,因此:
<disk>
<destination type='file'>/my_new_path/disk.qcow2</destination>
<format type='qcow2'/>
</disk>
应该是:
<disk>
<source type='file'>/my_new_path/disk.qcow2</destination>
<format type='qcow2'/>
</disk>
这当然有道理。现在一切正常 - 我现在可以将虚拟磁盘迁移到不同的路径。
希望人们会发现这个答案有帮助。 /p