isActive
method returns a boolean flag indicating whether or not the domain is active (running).
Example 4.14. Determine if the Domain is running
# Example-51.py #!/usr/bin/env python3 import sys import libvirt from xml.dom import minidom domName = 'CentOS7' conn = None try: conn = libvirt.open("qemu:///system") except libvirt.libvirtError as e: print(repr(e), file=sys.stderr) exit(1) dom = None try: dom = conn.lookupByName(domName) except libvirt.libvirtError as e: print(repr(e), file=sys.stderr) exit(1) flag = dom.isActive() if flag == True: print('The domain is active.') else: print('The domain is not active.') conn.close() exit(0)