higebu / pysphere

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

R78 issue with VMclone #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Calling CloneVM with sync_run true results in Attribute error
2.
3.

What is the expected output? What do you see instead?
What I try to do: use a template to clone a VM from a template residing on 
another datastore.  Since the command executes flawless (I monitor it in 
vsphere), my argument are correct and so is the core section of the 
CloneVM_task in pysphere.  It goes wrong in the wrap-up of the call. I run the 
task against vCenter instead of the hypervisor (since only vcenter supports 
cloning)

IMHO there are two issues:
1. Minor: CloneVM returns different object types based on the value of one of 
its arguments, the sync_run parameter:  sync_run=true --> return 
VIVirtualMachine; sync_run=false --> returns VITask. While technically OK, it's 
a bit confusing and you need to be careful to test the value or sync_run to 
deal with the correct return type.  Other pysphere tasks do not have that 
behavior.

2. Major: IMHO the call to "return VIVirtualMachine(self._server, 
vi_task.get_result())" is not correct. vi_task.get_result() does not return a 
MOR but a VIProperty, hence you get the attribute non existing error for the 
call to instantiate the VIVirtualMachine class which expects a MOR.  The 
correct call would be:  "return VIVirtualMachine(self._server, 
vi_task.get_result()._obj)"

When I implemented this change my whole code ran OK.

What version of the product are you using? On what operating system?
Pysphere: R78.
Host: Windows 2008 R2, 64-bit
Python: 2.7 in 32 bit mode.
Vcenter and Vsphere: 5.0 U1

Please provide any additional information below.
My code:
vm.clone(name, sync_run=True, folder=None, resourcepool=rp_mor,
                                             datastore=ds_mor, host=host_mor, power_on=False)

Where I believe the problem is: vi_virtual_machine.py around line 530

            if sync_run:
                status = vi_task.wait_for_state([vi_task.STATE_SUCCESS,
                                                 vi_task.STATE_ERROR])
                if status == vi_task.STATE_ERROR:
                    raise VIException(vi_task.get_error_message(),
                                      FaultTypes.TASK_ERROR)
                return VIVirtualMachine(self._server, vi_task.get_result()) 

            return vi_task

Original issue reported on code.google.com by e.comha...@gmail.com on 10 Sep 2012 at 9:39

GoogleCodeExporter commented 9 years ago
Thanks for the detailed information. This has been fixed in r80. The bug was 
introduced in r73 when VITask started using VIProperty.

I agree with you regarding the first issue you mention (the method returning 
two different object types depending on the sync_run parameter). These should 
probably be two separate methods. I've created issue #21 to evaluate if this 
should be changed.

Thanks again!

Original comment by argo...@gmail.com on 10 Sep 2012 at 3:35