numOfInterfaces
and numOfDefinedInterfaces
method. A list of those interfaces' names can be obtained with listInterfaces
method and listDefinedInterfaces
method ("defined" interfaces are those that have been defined, but are currently inactive). The list methods return a Python list
. All four functions return None
if an error is encountered.
Example 7.5. Getting a list of active ("up") interfaces on a host
# Example-5.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) ifaceNames = conn.listInterfaces() print("Active host interfaces:") for ifaceName in ifaceNames: print(' '+ifaceName) conn.close() exit(0)
Example 7.6. Getting a list of inactive ("down") interfaces on a host
# Example-6.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) ifaceNames = conn.listDefinedInterfaces() print("Inactive host interfaces:") for ifaceName in ifaceNames: print(' '+ifaceName) conn.close() exit(0)