Product SiteDocumentation Site

4.3.13. Fetch the name of the Domain

The name method returns the name of the domain.

Example 4.19. Fetch the name of the Domain

# Example-55.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)

name = dom.name()
print('Thename of the domain is "' + name +'".')

conn.close()
exit(0)