On 11/29/2012 07:07 PM, Wayne Sun wrote:
v2: break down the case to small cases with separate flags * Use setVcpusFlags API to set domain vcpus with flags * 3 cases added, each only deal with one set flag value as in config, live or maximum * cases are independent on domain states, API will report error if not suitable for certain states * the sample conf is only one scenario of hotplug domain vcpus v3: merge config and maximum case to config * maximum flag can only work when domain is shutoff, merge it to config case to simplify code Signed-off-by: Wayne Sun <gsun@xxxxxxxxxx> --- cases/set_vcpus_flags.conf | 67 +++++++++++++++++++++++++ repos/setVcpus/set_vcpus_config.py | 93 ++++++++++++++++++++++++++++++++++ repos/setVcpus/set_vcpus_live.py | 96 ++++++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+), 0 deletions(-) create mode 100644 cases/set_vcpus_flags.conf create mode 100644 repos/setVcpus/__init__.py create mode 100644 repos/setVcpus/set_vcpus_config.py create mode 100644 repos/setVcpus/set_vcpus_live.py diff --git a/cases/set_vcpus_flags.conf b/cases/set_vcpus_flags.conf new file mode 100644 index 0000000..6cf595f --- /dev/null +++ b/cases/set_vcpus_flags.conf @@ -0,0 +1,67 @@ +domain:install_linux_cdrom + guestname + $defaultname + guestos + $defaultos + guestarch + $defaultarch + vcpu + $defaultvcpu + memory + $defaultmem + hddriver + $defaulthd + nicdriver + $defaultnic + imageformat + qcow2 + +domain:destroy + guestname + $defaultname + +setVcpus:set_vcpus_config + guestname + $defaultname + vcpu + 1 + maxvcpu + 8 + +domain:start + guestname + $defaultname + +setVcpus:set_vcpus_live + guestname + $defaultname + vcpu + 3 + username + $username + password + $password + +setVcpus:set_vcpus_config + guestname + $defaultname + vcpu + 5 + +domain:destroy + guestname + $defaultname + +domain:start + guestname + $defaultname + +domain:destroy + guestname + $defaultname + +domain:undefine + guestname + $defaultname + +options cleanup=enable diff --git a/repos/setVcpus/__init__.py b/repos/setVcpus/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/repos/setVcpus/set_vcpus_config.py b/repos/setVcpus/set_vcpus_config.py new file mode 100644 index 0000000..08eb53f --- /dev/null +++ b/repos/setVcpus/set_vcpus_config.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# Test set domain vcpu with flag VIR_DOMAIN_AFFECT_CONFIG, also set +# and check max vcpu with flag VIR_DOMAIN_VCPU_MAXIMUM if maxvcpu +# param is given + +from xml.dom import minidom + +import libvirt +from libvirt import libvirtError + +from src import sharedmod + +required_params = ('guestname', 'vcpu', ) +optional_params = {'maxvcpu': 8, + } + +def get_vcpu_number(domobj): + """dump domain config xml description to get vcpu number, return + current vcpu and maximum vcpu number + """ + try: + guestxml = domobj.XMLDesc(2) + logger.debug("domain %s xml is :\n%s" %(domobj.name(), guestxml)) + xml = minidom.parseString(guestxml) + vcpu = xml.getElementsByTagName('vcpu')[0] + maxvcpu = int(vcpu.childNodes[0].data) + logger.info("domain max vcpu number is: %s" % maxvcpu) + + if vcpu.hasAttribute('current'): + attr = vcpu.getAttributeNode('current') + current = int(attr.nodeValue) + else: + logger.info("no 'current' atrribute for element vcpu") + current = int(vcpu.childNodes[0].data) + + logger.info("domain current vcpu number is: %s" % current) + + except libvirtError, e: + logger.error("libvirt call failed: " + str(e)) + return False + + return current, maxvcpu + +def set_vcpus_config(params): + """set domain vcpu with config flag and check, also set and check + max vcpu with maximum flag if optional param maxvcpu is given + """ + global logger + logger = params['logger'] + params.pop('logger') + guestname = params['guestname'] + vcpu = int(params['vcpu']) + maxvcpu = params.get('maxvcpu', None)
Either vcpu or maxvcpu could be optional, if both are given, we set them all.
In your case, only maxvcpu is optional. Guannan -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list