Commit 6c04efc6 by Guba Sándor

instance: added clone method to InstanceTemplate

parent 114dba11
......@@ -157,6 +157,36 @@ class InstanceTemplate(AclBase, VirtualMachineDescModel, TimeStampedModel):
if is_new:
self.set_level(self.owner, 'owner')
def clone(self, user=None, **kwargs):
"""Cloning a Template to a new Template.
It returns the new Template object.
Disk cloning handled paralell and asynchronusly.
"""
import copy
tmpl = copy.deepcopy(self)
tmpl.name = "Cloned from " + self.name
tmpl.pk = None
tmpl.full_clean() # Avoiding database errors.
tmpl.save()
def __clone_disk(disk):
cloned_disk = Disk.create(datastore=disk.datastore,
name=disk.name, size=disk.size,
type=disk.type)
#Paralell cloning disks
disk.clone_async(cloned_disk, user=user)
return cloned_disk
try:
tmpl.disks.add(*[__clone_disk(disk)
for disk in self.disks.all()])
tmpl.interface_set.add(*self.interface_set.all())
except:
tmpl.delete()
raise
else:
return tmpl
@permalink
def get_absolute_url(self):
return ('dashboard.views.template-detail', None, {'pk': self.pk})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment