I'm working with the API to create a utility for cloning a vm template. I'm borrowing a lot of code from the install.py
example.
In our deployment we are using the local hard disk to store the VM
images. The code example looks for a default storage repository, which doesn't exist if local storage is used exclusively. I have looked at the XAPI
reference and I can't find any way to list local storage - this is necessary because I need the UUID
of a storage repository to save the VM
image to.
First get the SR
object
sr_ref = self.session.xenapi.SR.get_by_uuid(local_storage_uuid)
Then get the template
object which you want to clone
template = self.session.xenapi.VM.get_by_uuid(template_uuid)
Suggest a name for the VM that would be cloned
vm_id = "Test_Cone_VM"
Now If your template repo
and the cloned VM repo
is same then use Async.VM.clone
. And if the repos are different then use Async.VM.copy
self.session.xenapi.Async.VM.copy(template, vm_id, sr_ref)
or
self.session.xenapi.Async.VM.clone(template, vm_id)
Have a look at the Xenserver API for more info.