[Kimchi-devel] [PATCH][Kimchi 3/6] Fix checking duplicate template before creating it

Ramon Medeiros ramonn at linux.vnet.ibm.com
Tue Mar 22 19:20:12 UTC 2016


Template was being check if duplicated after calling for VMTemplate,
which can make unecessary work. Check it before creating the class.

Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
 model/templates.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/model/templates.py b/model/templates.py
index 92705b6..b49ac50 100644
--- a/model/templates.py
+++ b/model/templates.py
@@ -72,8 +72,11 @@ class TemplatesModel(object):
                 raise InvalidParameter("KCHTMPL0003E", {'network': net_name,
                                                         'template': name})
         # Creates the template class with necessary information
-        # Checkings will be done while creating this class, so any exception
-        # will be raised here
+        # template with the same name already exists: raise exception
+        with self.objstore as session:
+            if name in session.get_list('template'):
+                raise InvalidOperation("KCHTMPL0001E", {'name': name})
+
         t = LibvirtVMTemplate(params, scan=True, conn=self.conn)
 
         # Validate cpu info
@@ -93,8 +96,6 @@ class TemplatesModel(object):
         name = params['name']
         try:
             with self.objstore as session:
-                if name in session.get_list('template'):
-                    raise InvalidOperation("KCHTMPL0001E", {'name': name})
                 session.store('template', name, t.info,
                               get_kimchi_version())
         except InvalidOperation:
-- 
2.5.5




More information about the Kimchi-devel mailing list