Product SiteDocumentation Site

4.5. Domain Configuration

Domains are defined in libvirt using XML. Everything related only to the domain, such as memory and CPU, is defined in the domain XML. The domain XML format is specified at http://libvirt.org/formatdomain.html. This can be accessed locally in /usr/share/doc/libvirt-devel-version/ if your system has the libvirt-devel package installed.
Configuration information for a guest domain can be obtained by using the XMLDesc method. This method returns the current description of a domain as an XML data stream. This stream can then be parsed to obtain detailed information about the domain and all the parts that make up the domain.
The flags parameter may contain any number of the following constants:
VIR_DOMAIN_XML_SECURE
VIR_DOMAIN_XML_INACTIVE
VIR_DOMAIN_XML_UPDATE_CPU
VIR_DOMAIN_XML_MIGRATABLE
The following example shows how to obtain some basic information about the domain.

Example 4.35. Get basic domain information from the domain's XML description

# Example-36.py
#!/usr/bin/env python3
import sys
import libvirt
from xml.dom import minidom

domName = 'Fedora22-x86_64-1'

conn = None
try:
    conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)
    exit(1)

dom = conn.lookupByID(5)
if dom == None:
    print('Failed to find the domain '+domName, file=sys.stderr)
    exit(1)

raw_xml = dom.XMLDesc(0)
xml = minidom.parseString(raw_xml)
domainTypes = xml.getElementsByTagName('type')
for domainType in domainTypes:
    print(domainType.getAttribute('machine'))
    print(domainType.getAttribute('arch'))

conn.close()
exit(0)

4.5.1. Emulator

To discover the guest domain's emulator find and display the content of the emulator XML tag.

Example 4.36. Get domain's emulator information

# Example-37.py
#!/usr/bin/env python3
import sys
import libvirt
from xml.dom import minidom

domName = 'Fedora22-x86_64-1'

conn = None
try:
    conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)
    exit(1)

dom = conn.lookupByID(5)
if dom == None:
    print('Failed to find the domain '+domName, file=sys.stderr)
    exit(1)

raw_xml = dom.XMLDesc(0)
xml = minidom.parseString(raw_xml)
domainEmulator = xml.getElementsByTagName('emulator')
print('emulator: '+domainEmulator[0].firstChild.data)

conn.close()
exit(0)
The XML configuration for the Emulator is typically as follows:

Example 4.37. Domain Emulator XML information

<domain type='kvm'>
    ...
    <emulator>/usr/libexec/qemu-kvm</emulator>
    ...
</domain>