axxyhtrx / pysphere

Automatically exported from code.google.com/p/pysphere
0 stars 0 forks source link

Templates #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We are using vCenter 5.0 and our team has created many templates from which 
VM's are deployed.  I would like to know if pysphere can be used to automate 
this process.

The docs for VIVirtualMachine.clone seem to indicate that this is possible 
although I could not get it to work.

>>> vms = server.get_registered_vms()
>>> templates = [vm for vm in vms if '[iSCSI-Templates]' in vm]
>>> templates[1]
'[iSCSI-Templates] 
WindowsVista-SP1-IE8-x86-Template/WindowsVista-SP1-IE8-x86-Template.vmtx'
>>> vm = server.get_vm_by_path(templates[1])
>>> new_vm = vm.clone("Clone")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pysphere\vi_virtual_machine.py", line 537,
 in clone
    FaultTypes.TASK_ERROR)
pysphere.resources.vi_exception.VIException: [Task Error]: The operation is not
allowed in the current state of the host.

Original issue reported on code.google.com by tniliesf...@gmail.com on 12 Sep 2013 at 8:16

GoogleCodeExporter commented 9 years ago
I'm also wondering about templates.
There is a clone feature, but it doesn't work for me.

If i try to clone a regular vm (non-template) I get

VIException: [Task Error]: The operation is not supported on the object.

new_vm = vm2.clone("Ubuntu_Cluster_02", sync_run=True, template=False, 
power_on=True, resourcepool="redacted.com" )

Templates don't show up in server.get_registered_vms().
So i can't try on a template.
The vm clones fine in vsphere.
So what objects can I clone on?

thanks

kesten
---------------------------------------------------------------------------
VIException                               Traceback (most recent call last)
<ipython-input-41-d9895f03b036> in <module>()
      1 # only new name is required.  These are all the defualt values (folder, resourcepool same as parent)
      2 # , folder="Templates"
----> 3 new_vm = vm2.clone("Ubuntu_Cluster_02", sync_run=True, template=False, 
power_on=True, resourcepool="21ct-lynxesx02.21technologies.com" )

/Library/Python/2.7/site-packages/pysphere/vi_virtual_machine.pyc in 
clone(self, name, sync_run, folder, resourcepool, datastore, host, power_on, 
template, snapshot, linked)
    535                 if status == vi_task.STATE_ERROR:
    536                     raise VIException(vi_task.get_error_message(),
--> 537                                       FaultTypes.TASK_ERROR)
    538                 return VIVirtualMachine(self._server, vi_task.get_result()._obj)
    539 

VIException: [Task Error]: The operation is not supported on the object.

Original comment by kesten.b...@gmail.com on 11 Oct 2013 at 3:01