[Kimchi-devel] [kimchi-devel][PATCH 1/2] Fix update vcpu count: Check available vcpu count before update

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Mon Mar 9 13:52:20 UTC 2015


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Currently we just check vcpu count does not exceed host available
count when topology specified.
Actually vcpu count also need to be checked when only vcpu specified.
Move this check outside topology check and add it to param update.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/model/cpuinfo.py   | 8 ++++++--
 src/kimchi/model/templates.py | 7 ++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/kimchi/model/cpuinfo.py b/src/kimchi/model/cpuinfo.py
index 3411ef5..54bfad4 100644
--- a/src/kimchi/model/cpuinfo.py
+++ b/src/kimchi/model/cpuinfo.py
@@ -114,11 +114,15 @@ class CPUInfoModel(object):
         cores = topology['cores']
         threads = topology['threads']
 
+        self.check_vcpus(vcpus)
+
         if not self.guest_threads_enabled:
             raise InvalidOperation("KCHCPUINF0003E")
         if vcpus != sockets * cores * threads:
             raise InvalidParameter("KCHCPUINF0002E")
-        if vcpus > self.cores_available * self.threads_per_core:
-            raise InvalidParameter("KCHCPUINF0001E")
         if threads > self.threads_per_core:
             raise InvalidParameter("KCHCPUINF0002E")
+
+    def check_vcpus(self, vcpus):
+        if vcpus > self.cores_available * self.threads_per_core:
+            raise InvalidParameter("KCHCPUINF0001E")
diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
index 85f0839..9f5b645 100644
--- a/src/kimchi/model/templates.py
+++ b/src/kimchi/model/templates.py
@@ -49,7 +49,7 @@ class TemplatesModel(object):
                                        {'filename': iso, 'user': user,
                                         'err': excp})
 
-        cpu_info = params.get('cpu_info')
+        cpu_info = params.setdefault('cpu_info', dict())
         if cpu_info:
             topology = cpu_info.get('topology')
             # Check, even though currently only topology
@@ -64,8 +64,9 @@ class TemplatesModel(object):
                 # exception if a topology is invalid.
                 CPUInfoModel(conn=self.conn).\
                     check_topology(params['cpus'], topology)
-        else:
-            params['cpu_info'] = dict()
+        if params.get('cpus'):
+            CPUInfoModel(conn=self.conn).check_vcpus(params['cpus'])
+
 
         conn = self.conn.get()
         pool_uri = params.get(u'storagepool', '')
-- 
1.9.1




More information about the Kimchi-devel mailing list