1

I'm attempting to script adding a network interface to a centos 6 guest. I know the interface can be set up using the virt-manager gui but it's highly desirable for it to be added as part of an Ansible playbook using virsh attach-interface or alternatively as part of virt-install.

The desired interface should look like this (although with a new mac adress)

<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>

I have been unable to replicate this using virsh attach-interface or virt-install. I've tried using the following

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

but this, unfortunately, doesn't set the source mode so I end up with the following interface

<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>

in an ideal world I would like to be able to do something like

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

but this returns the following error and I can't find the correct option to specify for this operation.

error: command 'attach-interface' doesn't support option --mode
  • I never use macvtap, but actual Linux bridge. This makes VM setup a bit easier and more reliable, and you don't necessarily have to create a libvirt virtual network either. – Michael Hampton Dec 16 '16 at 15:28
2

Since you already know the exact XML you want for the NIC, you should just avoid the virsh attach-interface command and instead use virsh attach-device. The attach-device command accepts the full XML document directly for the new device. attach-interface is just a dumb wrapper around attach-device which generates XML for you. So since you have the XML already there's no point in using attach-interface

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.