virInterface
, but you may only have the name or MAC address of the interface. You can use interfaceLookupByName
and interfaceLookupByMACString
to get the virInterface
instance in these cases.
Example 7.7. Fetching the virInterface instance for a given interface name
# Example-7.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()) conn.close() exit(0)
Example 7.8. Fetching the virInterface instance for a given interface MAC Address
# Example-8.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.interfaceLookupByMACString('00:01:02:03:04:05') print("The interface name is: "+iface.name()) conn.close() exit(0)