VMware {code} Community
hppp
Contributor
Contributor

Problem to list vm with soap and php

hi everytbody

i want to list my vm present in my vshpere datacenter with a web interface. I want use soap and php.

For the moment i am correctly connect but i don't now wath i need to list my vm.

I read this page : http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ServiceInstance.html and i have find this script, but it didn't work :

function FindVMByName( $vm ) {
          // this section is used to navigate to the VM folder for a datacenter (if you have an easier way, please, let me know)
          $soapVal = new soapval('_this', false, $this->session_result[propertyCollector], false, false, array("type" => "PropertyCollector"));
          $soapmsg[this] = $soapVal;
          $soapmsg[specSet][propSet][type] = "Folder";
          $soapmsg[specSet][propSet][pathSet] = "childEntity";
          $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $this->session_result[rootFolder], false, false, array("type" => "Folder"));
          $soapmsg[specSet][objectSet][skip] = false;    
          $temp = $this->process("RetrieveProperties", $soapmsg);
    
         $dataCenter = $temp[propSet][val][ManagedObjectReference];
    
            unset($temp);
            unset($soapmsg);
          $soapmsg[this] = $soapVal;
          $soapmsg[specSet][propSet][type] = "Datacenter";
          $soapmsg[specSet][propSet][pathSet] = "vmFolder";
          $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $dataCenter, false, false, array("type" => "Datacenter"));
          $soapmsg[specSet][objectSet][skip] = false;    
          $temp = $this->process("RetrieveProperties", $soapmsg);
            $vmFolder = $temp[propSet][val];
        
// once the vmFolder is retrieved, a simple FindChild using the vm name is used, this is the displayed VM name, not the generated entity name "vm-277".
          unset($soapmsg);
          $soapmsg[this] = new soapval('_this', false, $this->session_result[searchIndex], false, false, array("type" => "SearchIndex"));
          $soapmsg[entity] = new soapval('entity', false, $vmFolder, false, false, array("type" => "Folder"));
          $soapmsg[name] = $vm;
          $result = $this->process("FindChild", $soapmsg);
         
          return $result;
     }

you can help me please?

Thank everybody 

Tags (1)
Reply
0 Kudos
3 Replies
stumpr
Virtuoso
Virtuoso

So I will strongly recommend using HTML::Mason and the Perl SDK vs trying to formulate the scripts in PHP.  You'll find it a lot easier.

Just a quick look at your script sample looks like you're missing some TraversalSpecs and I don't see your PropertySpecs.  I would guess it's throwing out a SOAP fault.

Reuben Stump | http://www.virtuin.com | @ReubenStump
hppp
Contributor
Contributor

ok so CGI/PERL. It was my first idea Smiley Wink

Thank

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

It will save you a lot of work and troubleshooting.  Hand crafting the TraversalSpecs in PHP with SOAP is painful.

If you need a PHP like environment, you can look into Perl HTML::Mason (http://www.masonhq.com/).  It'll give you access to sessions and the usual inline HTML coding.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos