On 02/15/2014 04:12 AM, Aline Manera wrote:
On 02/13/2014 07:35 AM, shaohef(a)linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef(a)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(a)linux.vnet.ibm.com>
> ---
> src/kimchi/mockmodel.py | 17 +++++++++++++++++
> src/kimchi/model/templates.py | 17 +++++++++++++++++
> 2 files changed, 34 insertions(+)
>
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index 441c0e4..b2f67dd 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -202,6 +202,23 @@ 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)
> + print cherrypy.url()
> + raise cherrypy.HTTPRedirect("/templates/%s" % ident, 303)
cherrypy should be restrict to control
agree. when I write code here, I have known
that I should not
HTTPRedirect here.
But this POST is different with POST method, other POST method will not
create a resource.
Here we will create a resource like PUT method.
So we should HTTPRedirect explicitly, let the client know there is a new
resource.
I will touch the control to enhance it. seen next version.
I think we don't need to return anything here
> +
> 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 a5c73cc..30673f2 100644
> --- a/src/kimchi/model/templates.py
> +++ b/src/kimchi/model/templates.py
> @@ -22,6 +22,7 @@
>
> import copy
>
> +import cherrypy
> import libvirt
>
> from kimchi import xmlutils
> @@ -85,6 +86,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)
> + raise cherrypy.HTTPRedirect("/templates/%s" % ident, 303)
> +
> def delete(self, name):
> with self.objstore as session:
> session.delete('template', name)
--
Thanks and best regards!
Sheldon Feng(冯少合)<shaohef(a)linux.vnet.ibm.com>
IBM Linux Technology Center