Product SiteDocumentation Site

4.3.4. Determining if the domain has a current snapshot

The hasCurrentSnapshot method returns a boolean value indicating if a current snapshot is available. This method always returns a valid value and is not dependent on the running state of the domain.

Example 4.10. Determining if the domain has a current snapshot

# Example-47.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.hasCurrentSnapshot()
print('The value of the current snapshot flag is ' + str(flag))

conn.close()
exit(0)