Product SiteDocumentation Site

4.3.12. Determine the max Vcpus of the Domain

The maxVcpus method returns the maximum number of virtual CPUs allocated to the domain, This same information can be retrieved via info method.

Example 4.18. Determine the max Vcpus of the Domain

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

cpus = dom.maxVcpus()
if cpus != -1:
    print('The max Vcpus for domain is ' + str(cpus))
else:
    print('There was an error.')

conn.close()
exit(0)