After creating a VM using a libvirt-based utility, you can add the network configuration, including the port profile information,
either to the domain XML of the VM or to a separate network XML file that you can reference from the domain XML. One of the
advantages of adding the configuration information to a separate network XML file is that you can specify a pool of devices.
For more information about the network XML file components and attributes, see https://libvirt.org/formatnetwork.html.
For more information about the domain XML file components and attributes, see the libvirt documentation at https://libvirt.org/formatdomain.html#elementsNICS.
Step 1 |
Shut down the VM
to be configured.
|
Step 2 |
Using the virsh
editor, open the domain XML file of the VM for editing.
This example
opens a domain XML file for editing in the virsh editor:
[root@chassis1blade5 qemu]# virsh edit vm1-rhel6.2
|
Step 3 |
In the devices
section of the domain XML file, add an interface element that describes a vNIC
for the VM.
The components
and attributes of the interface element are described in the Example section.
|
Step 4 |
Restart the VM.
|
Example for SR-IOV with MacVTap Mode
This example shows an interface element added to the domain XML file of a VM for connection in SR-IOV with MacVTap (MacVTap
Passthrough) topology:
<domain type='kvm'>
<name>vm1-rhel6.2</name>
...
<devices>
...
<interface type='direct'>
<mac address='01:23:45:67:89:ab' />
<source dev='eth4' mode='passthrough' />
<virtualport type='802.1Qbh'>
<parameters profileid='my-port-profile-3' />
</virtualport>
<model type='virtio' />
<driver name='vhost' />
</interface>
...
</devices>
...
</domain>
This list describes the components and attributes of the interface element:
-
interface type='direct'
The direct
type attribute value selects a direct logical attachment of the vNIC to the physical interface of the hypervisor, using the
MacVTap driver.
-
mac address='01:23:45:67:89:ab'
Explicit specification of the MAC address is optional. Enter a MAC address obtained from your network administrator. If this
line is omitted, libvirt generates a MAC address for the vNIC.
Note |
We recommend that you do not assign a MAC address used by another VM, even if that VM is currently shut down or is no longer
used. If you must reuse a MAC address from a previous VM, make sure that the retention timer has expired and ensure that the
previous VM is no longer present in the Cisco UCS Manager view.
|
-
source dev='eth4' mode='passthrough'
The passthrough
mode attribute value specifies that each VM is connected to the network by a macvtap direct connection with a virtual function
(VF). The source interface must be a VF, and not a physical function (PF).
-
virtualport type='802.1Qbh'
The 802.1Qbh
type attribute value specifies that the vNIC is connected to an 802.1Qbh extended port for external switching.
-
parameters profileid='my-port-profile-3'
This line specifies the name of the port profile to be associated with the interface. The port profile name is case sensitive.The
specified port profile must be already defined in Cisco UCS Manager and use the naming syntax described in Creating a Port Profile.
-
model type='virtio'
This line specifies that the guest interface uses the VirtIO paravirtualized front-end device driver.
-
driver name='vhost'
This line specifies that, for higher performance, the host side interface uses the vhost kernel back-end device driver and
not the qemu userspace back-end driver.
Example for SR-IOV Passthrough Mode
This example shows an interface element that is added to the domain XML file of a VM for a connection in SR-IOV Passthrough
topology:
<domain type='kvm'>
<name>vm1-rhel6.3</name>
...
<devices>
...
<interface type='hostdev' managed='yes'>
<source>
<address type='pci' domain='0' bus='0x09' slot='0x0' function='0x01'/>
</source>
<mac address='01:23:45:67:89:ab' />
<virtualport type='802.1Qbh'>
<parameters profileid='my-port-profile-3' />
</virtualport>
</interface>
...
</devices>
...
</domain>
This list describes the components and attributes of the interface element that differ from those described in the SR-IOV
with MacVTap mode example:
-
interface type='hostdev'
The hostdev
type attribute allows you to assign a host device directly to a guest.
-
address type='pci' domain='0' bus='0x09' slot='0x0' function='0x01'
.
The address type
attribute value specifies the PCI address of the host VF. To obtain the address information, you can run the lspci
command at the Linux prompt. When you run the command, an address string is displayed, for example, 09:00.1 Ethernet controller: Cisco Systems Inc Device 0071 (rev a2)
. In the address string 09.00.1
, 09 indicates the bus, 00 indicates the slot, and 1 indicates the function.
-
mac address='01:23:45:67:89:ab'
Explicit specification of the MAC address is optional. Enter a MAC address that you obtained from your network administrator.
If this line is omitted, libvirt generates a MAC address for the vNIC.
Note |
We recommend that you do not assign a MAC address used by another VM, even if that VM is currently shut down or is no longer
used. If you must reuse a MAC address from a previous VM, make sure that the retention timer has expired and ensure that the
previous VM is no longer present in the Cisco UCS Manager view.
|
Example of Using a Network XML File to Specify a Pool of Devices
This example shows how to use a network XML file to specify a pool of devices. In RHEL 6.2 or later, create the network file
in /etc/libvirt/qemu/networks. List the devices and define a portgroup:
<network>
<name>macvtap_passthru_network</name>
<forward mode='passthrough'>
<interface dev='eth2' />
<interface dev='eth3' />
</forward>
<portgroup name='engineering'>
<virtualport type='802.1Qbh'>
<parameters profileid='my-port-profile-3' />
</virtualport>
</portgroup>
</network>
Edit the domain XML file of the VM to reference the network file and portgroup:
<domain type='kvm'>
<name>vm1-rhel6.2</name>
...
<devices>
...
<interface type='network'>
<mac address='01:23:45:67:89:ab' />
<source network='macvtap_passthru_network' portgroup='engineering' />
<model type='virtio' />
</interface>
...
</devices>
...
</domain>
After you create the new network XML file, use the virsh net-define <new-xml-filename>
command to create the new network from the new network XML file.
Tip |
You can find the network-related virsh commands with virsh help | grep net-
You can view help on any virsh command with virsh help <command-name>
|
This list describes the components and attributes of the interface element that differ from those described in the SR-IOV
with MacVTap mode example:
-
interface type='network'
The network
type attribute value specifies an attachment of the VM vNIC to a PCI network device from the pool listed in a separate network
file.
-
source network='macvtap_passthru_network' portgroup='engineering'
The network
and portgroup
attribute values specify the name of a network XML file and its pool of network devices.