How to set the target device name for VM to track port in openvswitch ?

by iman

in general, when we add a virtual network interface card to your virtual machine, some generic name will be appear as device port on openvswitch like this :
root@vt127:~# ovs-vsctl show
Bridge “ovsbr0”
Port “vnet0”
tag: 36
Interface “vnet0”
Port “ovsbr0”
Interface “ovsbr0”
type: internal
Port “vnet3”
tag: 34
Interface “vnet3”
Port “vlan36”
tag: 36
Interface “vlan36”
type: internal
Port “vnet2”
tag: 36
Interface “vnet2”
Port “vnet4”
Interface “vnet4”
Port “p6p1”
trunks: [24, 35, 36]
Interface “p6p1”
ovs_version: “2.0.1”

so we don’t know which port is assigned to which vm’s nic card (vnet0, vnet1, …). I strongly recommend to set the target device name. This is the name of the network interface seen on the openvswitch. I always start the name with “veth”. The number following is the interface number on the guest. And I add the name of the VM. So veth0-vmtest corresponds to eth0 on the guest vmtest. If you do not set the interface name, they will get vnet. If you have to troubleshoot something on the virtual network, predefined interface names help a lot. do it like this in your xml’s domain :

<interface type=’bridge’>
<virtualport type=’openvswitch’>
      <target dev=’veth0-vmtest’/>
<model type=’virtio’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x06′ function=’0x0’/>