使用virsh将networking接口添加到KVM主机上的VM时出错

我正在尝试为一个centos 6 guest添加一个networking接口的脚本。 我知道可以使用virt-manager gui来设置接口,但是使用virsh attach-interface或者virt-install的一部分来添加它作为Ansible操作手册的一部分是非常理想的。

所需的接口应该是这样的(尽pipe有一个新的MAC地址)

<interface type='direct'> <mac address='52:54:00:39:f8:3a'/> <source dev='enp3s0' mode='bridge'/> <target dev='macvtap8'/> <model type='virtio'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> 

我一直无法复制这使用virsh attach-interfacevirt-install 。 我试过使用以下

 virsh attach-interface 16 --type direct --source enp3s0 --model virtio --config --live 

但不幸的是,这不会设置源模式,所以我最终以下面的界面

 <interface type='direct'> <mac address='52:54:00:e1:d8:2c'/> <source dev='enp3s0' mode='vepa'/> <target dev='macvtap15'/> <model type='virtio'/> <alias name='net1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> </interface> 

在理想的世界中,我希望能够做到这样的事情

 virsh attach-interface 16 --type direct --source enp3s0 --model virtio --mode bridge --config --live 

但是这会返回以下错误,我无法find指定此操作的正确选项。

 error: command 'attach-interface' doesn't support option --mode 

既然您已经知道了NIC所需的确切XML,则应避免使用virsh attach-interface命令,而使用virsh attach-deviceattach-device命令直接为新设备接受完整的XML文档。 attach-interface仅仅是为你生成XML的attach-device一个愚蠢的包装。 所以既然你已经有了XML,那么使用attach-interface就没有意义了