Product SiteDocumentation Site

7.3.3. Retrieving Detailed Interface Information

You may also find yourself with a virInterface instance, and need the name or MAC address of the interface, or want to examine the full interface configuration. The name, MACString, and XMLDesc methods provide this capability.

Example 7.9. Fetching the name and mac address from an interface object

# Example-9.py
#!/usr/bin/env python3
import sys
import libvirt

conn = None
try:
    conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)
    exit(1)

iface = conn.interfaceLookupByName('eth0')

print("The interface name is: "+iface.name())
print("The interface mac string is: "+iface.MACString())

conn.close()
exit(0)

Example 7.10. Fetching the XML configuration string from an interface object

# Example-10.py
#!/usr/bin/env python3
import sys
import libvirt

conn = None
try:
    conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)
    exit(1)

iface = conn.interfaceLookupByName('eth0')

print("The interface XML description is:\n"+iface.XMLDesc(0))

conn.close()
exit(0)