[Kimchi-devel] [PATCH v5 3/3] Forbid user to edit CPU value if topology is defined
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Sun Oct 4 22:37:19 UTC 2015
- When a cpu topology is defined, the number of cpus must always be the
product of sockets * cores * threads, otherwise libvirt will complain
about it.
Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
src/wok/plugins/kimchi/i18n.py | 1 +
src/wok/plugins/kimchi/model/vms.py | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/src/wok/plugins/kimchi/i18n.py b/src/wok/plugins/kimchi/i18n.py
index 2207e9e..fbb0e12 100644
--- a/src/wok/plugins/kimchi/i18n.py
+++ b/src/wok/plugins/kimchi/i18n.py
@@ -112,6 +112,7 @@ messages = {
"KCHVM0054E": _("VM '%(vm)s' cannot have more than %(cpus)d CPUs. Please update the CPU value when the VM is not running."),
"KCHVM0055E": _("VM '%(vm)s' cannot have less than %(cpus)d CPUs. Please update the CPU value when the VM is not running."),
"KCHVM0056E": _("Unable to hotplug CPUs. Details: %(err)s"),
+ "KCHVM0057E": _("Cannot change VCPU value because '%(vm)s' has a topology defined - sockets: %(sockets)s, cores: %(cores)s, threads: %(threads)s."),
"KCHVMHDEV0001E": _("VM %(vmid)s does not contain directly assigned host device %(dev_name)s."),
"KCHVMHDEV0002E": _("The host device %(dev_name)s is not allowed to directly assign to VM."),
diff --git a/src/wok/plugins/kimchi/model/vms.py b/src/wok/plugins/kimchi/model/vms.py
index 9e6a4d7..021580e 100644
--- a/src/wok/plugins/kimchi/model/vms.py
+++ b/src/wok/plugins/kimchi/model/vms.py
@@ -87,6 +87,8 @@ XPATH_DOMAIN_DEV_CPU_ID = '/domain/devices/spapr-cpu-socket/@id'
XPATH_NUMA_CELL = './cpu/numa/cell'
+XPATH_TOPOLOGY = './cpu/topology'
+
# key: VM name; value: lock object
vm_locks = {}
@@ -841,6 +843,28 @@ class VMModel(object):
cpus = params['cpus']
if DOM_STATE_MAP[dom.info()[0]] == 'shutoff':
+
+ # user cannot change vcpu if topology is defined. In this case
+ # vcpu must always be sockets * cores * threads.
+ xml = dom.XMLDesc(0)
+ sockets = xpath_get_text(xml, XPATH_TOPOLOGY + '/@sockets')
+ cores = xpath_get_text(xml, XPATH_TOPOLOGY + '/@cores')
+ threads = xpath_get_text(xml, XPATH_TOPOLOGY + '/@threads')
+ current_vcpu = dom.vcpusFlags(libvirt.VIR_DOMAIN_VCPU_MAXIMUM)
+
+ if sockets and cores and threads:
+ if current_vcpu != cpus:
+ raise InvalidOperation('KCHVM0057E',
+ {'vm': dom.name(),
+ 'sockets': sockets[0],
+ 'cores': cores[0],
+ 'threads': threads[0]})
+
+ # do not need to update vcpu if the value edit did not
+ # change
+ else:
+ return
+
try:
# set maximum VCPU count
cpu_model = CPUInfoModel(conn=self.conn)
--
1.9.1
More information about the Kimchi-devel
mailing list