Code Monkey home page Code Monkey logo

Comments (18)

rgrwkmn avatar rgrwkmn commented on June 28, 2024

Is that the exact code you are running? Where does the "error is - " line come from? It would be good to print_r the array you are giving to CloneVM_Task so we can see exactly what is being sent.

from vmwarephp.

rgrwkmn avatar rgrwkmn commented on June 28, 2024

Oh, the "error is - " is coming from your debugging output in Service.php. You should echo something in between each line, maybe it's not even making it to the CloneVM_Task call.

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

Thank you for a prompt reply.
Yes, it's my debugging code and I should have added at least the "\n" there..
Here is my debugging code : It in the catch block, so it happens after the error :

diff --git a/library/Vmwarephp/Service.php b/library/Vmwarephp/Service.php
index 52030ed..527e5e4 100644
--- a/library/Vmwarephp/Service.php
+++ b/library/Vmwarephp/Service.php
@@ -71,6 +71,9 @@ class Service {
                        $result = $this->soapClient->$method($soapMessage);
                } catch (\SoapFault $soapFault) {
                        $this->soapClient->_classmap = null;
+                       echo 'error is - ' ;
+                       print_r($method);
+                       print_r($soapMessage);
                        throw new \Vmwarephp\Exception\Soap($soapFault);
                }
                $this->soapClient->_classmap = null;

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

I tried to do the print_r of the arguments array passed to the CloneVM_Task, but as the $vm->parent object has a lot of recursions it's likely worthless to include it here. Is there a working example with CloneVM_Task function ? may be someone is already using it in live systems?

from vmwarephp.

rgrwkmn avatar rgrwkmn commented on June 28, 2024

I use it all the time, which is why I was thinking it may be failing before it gets to that call. Looks like your clone spec is good. Are you positive it's making it to the CloneVM_Task call? Can you echo something in between each line of your code so it's easy to see where the error is thrown?

It looks like it's failing when it tries to retrieve the name property of a folder with the ID ha-folder-vm.

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

Ok, If the code looks ok, then may be it's the esx host issue.. I have version 5.1.0 799733..
I also tried to use CreateVM_Task and got similar error. Can you paste me a working script for creating or cloning VM? I'd test it on my host and confirmed if problem is on the host or in the code..

The CloneVM_Task is definitely run, I updated the code like this :

$vhost = new \Vmwarephp\Vhost('*****','*****','*****');

$vm = $vhost->findManagedObjectByName("VirtualMachine", "test1", array());
echo "vms is : $vm->name\n";

$cfs = new VirtualMachineCloneSpec();
$cfs->powerOn=FALSE;
$cfs->template=FALSE;
$cfs->snapshot=$vm->snapshot->currentSnapshot;
$cfs->location =new VirtualMachineRelocateSpec();
$cfs->location->diskMoveType='createNewChildDiskBacking';

$args =array('folder' => $vm->parent, 'name' => $vm->name .'-clone', 'spec' => $cfs);
echo " running clone : \n";
$ret = $vm->CloneVM_Task($args);

Got output like this :

vms is : test1
 running clone : 
method : RetrieveProperties
error is : Array
(
    [_this] => ManagedObjectReference Object
        (
            [_] => ha-property-collector
            [type] => PropertyCollector
        )

    [specSet] => PropertyFilterSpec Object
...

the debug output is more readable now :)

from vmwarephp.

rgrwkmn avatar rgrwkmn commented on June 28, 2024

Try putting it in a different folder than $vm->parent.

Also, side note, if the VM doesn't have any snapshots then $vm->snapshot will be null and you will get an error trying to do $vm->snapshot->currentSnapshot.

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

I'm using this host in standalone mode, so I can't create any other Folders in the hierarchy.
Thanks for the tip with snapshots, I pre-created a snapshot to avoid any errors like this :)
Is it worth to migrate to vsphere hypervisor 5.5 ? Would vmwarephp support it ?
In the readme it's said that it supports up to 5.1, but not a word about 5.5...

from vmwarephp.

rgrwkmn avatar rgrwkmn commented on June 28, 2024

I only have experience with 5.1.

No idea what's going on with this! Can you print_r that array you're passing to CloneVM_Task again, put it all in a gist and link it here?

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

I think I found why it doesn't work in my config. It seems Clone operation is working only trough the vCenter server.

"You must be connected to vCenter Server in order to clone a virtual machine. You cannot clone virtual machines if you connect directly to an ESXi host. "

Are you running ESX in standalone mode without vCenter ?

http://pubs.vmware.com/vsphere-51/index.jsp#com.vmware.vsphere.vm_admin.doc/GUID-5C504B67-CDB3-42FC-8B3B-737201A725DD.html?resultof=%2522%2543%256c%256f%256e%2565%2522%2520%2522%2563%256c%256f%256e%2565%2522%2520%2522%2576%2569%2572%2574%2575%2561%256c%2522%2520%2522%256d%2561%2563%2568%2569%256e%2565%2522%2520%2522%256d%2561%2563%2568%2569%256e%2522%2520

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

Here is a gist I've created dumping the arguments to CloneVM_Task :
https://gist.github.com/anikushkin/3c07155ce64f118e961f

from vmwarephp.

rgrwkmn avatar rgrwkmn commented on June 28, 2024

I don't know exactly what my setup is, somebody else manages it. I don't see any issues with your CloneVM_Task array, so your setup may be the issue.

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

If you can create the Folders in the tree, then it's definitely trough the vCenter, I already tried to create a sub-folder and received clear error message about that.
It's really strange that I have the same error in CreateVM_Task, which should work on 100%. Will keep trying to hack it :)

from vmwarephp.

rgrwkmn avatar rgrwkmn commented on June 28, 2024

Yeah, I create folders, in fact I wrote the Folder ManagedObject Extension class :)

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

I'm hacking with perl SDK now - their vmcreate.pl and vmclone.pl are working fine on my host. I assume it's something missing in my code, as the way it's done in perl contains much more operations and much more data passed via SOAP. If I'll manage to make it work, I'll paste working code here.
I think this issue is not a bug, may be just a lack of documentation in vmware SDK. Most likely it's just differencies in vCenter and standalone modes

from vmwarephp.

anikushkin avatar anikushkin commented on June 28, 2024

finally, I found the root cause of the problem.

  1. Clone is not supported on standalone ESX hosts
  2. we need to pass REFERENCES to the objects, instead of the objects themselves;
    here is my final code and result confirming it :
$vhost = new \Vmwarephp\Vhost('*****','*****','*****');

$vm = $vhost->findManagedObjectByName("VirtualMachine", "test1", array('parent', 'name'));
echo "vms is : $vm->name\n";

$cfs = new VirtualMachineCloneSpec();
$cfs->powerOn=FALSE;
$cfs->template=FALSE;
$cfs->snapshot=$vm->snapshot->currentSnapshot->reference;
$cfs->location =new VirtualMachineRelocateSpec();
$cfs->location->diskMoveType='createNewChildDiskBacking';

$args =array('folder' => $vm->parent->reference, 'name' => $vm->name .'-clone', 'spec' => $cfs);
echo " running clone : \n";
$ret = $vm->CloneVM_Task($args);

while (in_array($ret->info->state, array('running', 'queued'))){
        echo " " .$ret->info->progress .'%, ('. $ret->info->state .')';
        sleep(1);
}

print_r($ret->info->error);

Result is :

vms is : test1
 running clone : 
LocalizedMethodFault Object
(
    [fault] => 
    [localizedMessage] => The operation is not supported on the object.
)

from vmwarephp.

rgrwkmn avatar rgrwkmn commented on June 28, 2024

Oh man, I should have caught the reference thing. Nice job debugging that, the error message you were getting did not give you much to go on!

from vmwarephp.

rajukumargupta avatar rajukumargupta commented on June 28, 2024

this error come because your user dnot have permission to clone vm task.

from vmwarephp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.