[Kimchi-devel] [PATCH V3 4/5] clone template: update model and mockmodel
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Mon Feb 17 05:58:05 UTC 2014
From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
When clone template, if no name in parameters, kimchi will set a
default name.
Then copy the info from existing template and create a new one.
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
src/kimchi/mockmodel.py | 16 ++++++++++++++++
src/kimchi/model/templates.py | 16 ++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index b7b5952..0c2da8a 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -231,6 +231,22 @@ class MockModel(object):
self._mock_templates[name] = t
return name
+ def template_clone(self, name):
+ # set default name
+ subfixs = [v[len(name):] for v in self.templates_get_list()
+ if v.startswith(name)]
+ indexs = [int(v.lstrip("-clone")) for v in subfixs
+ if v.startswith("-clone") and
+ v.lstrip("-clone").isdigit()]
+ indexs.sort()
+ index = "1" if not indexs else str(indexs[-1] + 1)
+ clone_name = name + "-clone" + index
+
+ temp = self.template_lookup(name)
+ temp['name'] = clone_name
+ ident = self.templates_create(temp)
+ return ident
+
def template_update(self, name, params):
old_t = self.template_lookup(name)
new_t = copy.copy(old_t)
diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
index 3d05e80..5d09813 100644
--- a/src/kimchi/model/templates.py
+++ b/src/kimchi/model/templates.py
@@ -85,6 +85,22 @@ class TemplateModel(object):
t = self.get_template(name, self.objstore, self.conn)
return t.info
+ def clone(self, name):
+ # set default name
+ subfixs = [v[len(name):] for v in self.templates.get_list()
+ if v.startswith(name)]
+ indexs = [int(v.lstrip("-clone")) for v in subfixs
+ if v.startswith("-clone") and
+ v.lstrip("-clone").isdigit()]
+ indexs.sort()
+ index = "1" if not indexs else str(indexs[-1] + 1)
+ clone_name = name + "-clone" + index
+
+ temp = self.lookup(name)
+ temp['name'] = clone_name
+ ident = self.templates.create(temp)
+ return ident
+
def delete(self, name):
with self.objstore as session:
session.delete('template', name)
--
1.8.4.2
More information about the Kimchi-devel
mailing list