[Kimchi-devel] [PATCH V2 3/4] clone template: update model and mockmodel

Aline Manera alinefm at linux.vnet.ibm.com
Fri Feb 14 19:55:06 UTC 2014


On 02/14/2014 05:51 PM, Aline Manera wrote:
> On 02/13/2014 07:35 AM, shaohef at linux.vnet.ibm.com wrote:
>> 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       | 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()
>
> Need to remove this line
>

I will do it before applying :-)

>> +        raise cherrypy.HTTPRedirect("/templates/%s" % ident, 303)
>> +
>>       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)
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>




More information about the Kimchi-devel mailing list