Product SiteDocumentation Site

4.3.3. Fetching the OS type of a domain

The type of OS hosted by a domain is also available. Only running domains have an ID, fetching the ID of a non-running domain always returns -1. This same information may be retrieved via the info method.

Example 4.9. Fetching the ID of a domain

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

type = dom.OSType()
print('The OS type of the domain is "' + type + '"')

conn.close()
exit(0)