<domain> ... <vcpu placement='static' cpuset="1-4,^3,6" current="1">2</vcpu> ... </domain>
<domain> ... <maxMemory slots='16' unit='KiB'>1524288</maxMemory> <memory unit='KiB'>524288</memory> <currentMemory unit='KiB'>524288</currentMemory> ... </domain>
setVcpus
or the setVcpusFlags
methods. The number CPUs may not exceed the hypervisor maximum discussed above.
Example 4.39. Set the number of maximum virtual cpus for a domain
# Example-29.py #!/usr/bin/env python3 import sys import libvirt 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(6) if dom == None: print('Failed to find the domain '+domName, file=sys.stderr) exit(1) dom.setVcpus(2) conn.close() exit(0)
setMemory
or the setMemoryFlags
methods. The amount of memory should be expressed in kilobytes.
Example 4.40. Set the amount of memory for a domain
# Example-30.py #!/usr/bin/env python3 import sys import libvirt 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(6) if dom == None: print('Failed to find the domain '+domName, file=sys.stderr) exit(1) dom.setMemory(4096) # 4 GigaBytes conn.close() exit(0)
setMemory
method, the alternative method setMemoryFlags
is also available.