| 1 |
|
| 2 |
""" |
| 3 |
Sets the vCPU count via the guest agent and sets the metadata element |
| 4 |
used by guest-vcpu-daemon.py example |
| 5 |
""" |
| 6 |
|
| 7 |
import libvirt |
| 8 |
from argparse import ArgumentParser |
| 9 |
|
| 10 |
customXMLuri = "guest-cpu.python.libvirt.org" |
| 11 |
|
| 12 |
parser = ArgumentParser(description=__doc__) |
| 13 |
parser.add_argument("--config", "-c", action="store_true", help="Modify persistent domain configuration") |
| 14 |
parser.add_argument("--live", "-l", action="store_true", help="Modify live domain configuration") |
| 15 |
parser.add_argument("domain") |
| 16 |
parser.add_argument("count", type=int) |
| 17 |
parser.add_argument("uri", nargs="?", default="qemu:///system") |
| 18 |
args = parser.parse_args() |
| 19 |
|
| 20 |
flags = (libvirt.VIR_DOMAIN_AFFECT_CONFIG if args.config else 0) | (libvirt.VIR_DOMAIN_AFFECT_LIVE if args.live else 0) |
| 21 |
|
| 22 |
conn = libvirt.open(args.uri) |
| 23 |
dom = conn.lookupByName(args.domain) |
| 24 |
|
| 25 |
if flags == 0 or args.config: |
| 26 |
confvcpus = dom.vcpusFlags(libvirt.VIR_DOMAIN_AFFECT_CONFIG) |
| 27 |
|
| 28 |
if confvcpus < args.count: |
| 29 |
print("Persistent domain configuration has only " + str(confvcpus) + " vcpus configured") |
| 30 |
exit(1) |
| 31 |
|
| 32 |
if flags == 0 or args.live: |
| 33 |
livevcpus = dom.vcpusFlags(libvirt.VIR_DOMAIN_AFFECT_LIVE) |
| 34 |
|
| 35 |
if livevcpus < args.count: |
| 36 |
print("Live domain configuration has only " + str(livevcpus) + " vcpus configured") |
| 37 |
exit(1) |
| 38 |
|
| 39 |
if flags == 0 or args.live: |
| 40 |
dom.setVcpusFlags(args.count, libvirt.VIR_DOMAIN_AFFECT_LIVE | libvirt.VIR_DOMAIN_VCPU_GUEST) |
| 41 |
|
| 42 |
meta = "<ncpus count='" + str(args.count) + "'/>" |
| 43 |
|
| 44 |
dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, meta, "guestvcpudaemon", customXMLuri, flags) |