ESXi

 View Only
  • 1.  vSphere and php

    Posted Feb 05, 2011 12:16 AM

    Hello to all vSphere community.

    Has anybody succeded in controlling vSphere through php?

    Is vmware going to create api for controlling vms through php?

    Thanks



  • 2.  RE: vSphere and php

    Posted Feb 05, 2011 12:21 AM

    vSpere uses PowerCLI (based on powershell) to control and automate vSphere management. The nearest if could find is here controlling powershell via PHP @ http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/3881d0a3-9580-4d2f-a8ec-9671b23fc6de



  • 3.  RE: vSphere and php

    Posted Feb 05, 2011 12:41 AM

    You might want to have a look at http://blog.peacon.co.uk/wiki/Esxi-control.pl

    While that is perl, it is using SOAP calls to ESX(i). The script is well documented so you could use it as a guide as you develop your php.



  • 4.  RE: vSphere and php

    Broadcom Employee
    Posted Feb 05, 2011 01:07 AM

    To answer your question, no VMware does not have a vSphere PHP binding ... having said that, VMware does provide the actual WSDL in which you can use to generate a set of PHP bindings. User's have done this

    Here are two examples of this and the latter actually someone created an non-VMware PHP binding for vSphere:

    http://www.run-virtual.com/?page_id=125

    https://github.com/nfabre/vmware-vsphere-api-php

    Use at your own risk.

    VMware does not have vSphere binding to PHP, but it does provide a PHP binding to their vCloud Director API - http://communities.vmware.com/community/developer/forums/vcloudsdkphp

    You could take a look there to get ides on how they generated the stubs.



  • 5.  RE: vSphere and php

    Posted Feb 05, 2011 01:40 AM

    Thank you for replies

    As i understand there is no api for creating/pre-configuring VMs, starting and providing ready VM, only for similar operations such as start/stop and etc.



  • 6.  RE: vSphere and php

    Posted Feb 05, 2011 01:51 AM

    No there is an API - its a SOAP API.  Theres just no pre done bindings for PHP, so you'd eitherhave to create your own binding or send SOAP calls directly from PHP.



  • 7.  RE: vSphere and php

    Posted Jul 25, 2024 04:48 AM
    Edited by Régis Jul 25, 2024 04:50 AM

    In PHP, you can create an object derived from SoapClient such as this:

    class ESXI_SOAP extends SoapClient {
     private $ServiceInstance;
     private $session;

     public function __construct( $url , $user , $pass ) {
      try {
       parent::__construct( $url . '/vimService.wsdl' ,
        [ 'trace'      => true
        , 'exceptions' => true
        , "location"   => $url
        , 'stream_context' => stream_context_create(
           [ 'ssl' => [ 'verify_peer' => false
           , 'verify_peer_name' => false , 'allow_self_signed' => true ]
           ]
          )
        ]
       ) ;
       $SI = $this->ServiceInstance =
        $this->RetrieveServiceContent(
         [ "_this" => new SoapVar( "ServiceInstance", XSD_STRING , "ServiceInstance" ) ]
        )->returnval ;

       $this->session =
        $this->Login(
         [ '_this'    => $this->ServiceInstance->sessionManager
         , 'userName' => $user
         , 'password' => $pass
         ]
        )->returnval ;
       echo "login successful\n\nServiceInstance:\n" ;
       var_dump($this->ServiceInstance);
       echo "\nSession:\n";
       var_dump( $this->session ) ;
      } catch( Exception $e ) {
       printf("Login failed: %sn",$e->__toString() ) ;
       return false ;
      }
      echo $this->__getLastResponseHeaders();

      /*** Logout ***/
      try{
       echo "attempting logout()\n";
       $result = $this->Logout(
        [ "_this"          => $SI
        ]
       ) ;
      } catch (Exception $e) {

       printf("%sn",$e->__toString());
       return false;
      }
      echo "logout successful\n";
      return true;
     }

    // Other methods as required

    }

    The problem with this code is that it logs in to the ESXi successfully, but loses the object immediately and even the Logout fails (same when connecting to a vCenter), despite $this->__getLastResponseHeaders(); showing everything fine, including cookies.

    Besides that tiny inconvenient detail, that's probably where you would start to control your VMware infrastructure with PHP.




  • 8.  RE: vSphere and php

    Broadcom Employee
    Posted Feb 05, 2011 01:52 AM

    Not sure what you mean by that, the vSphere API is pretty much parity complete with the things you can do using the vSphere Client minus a few tiny things. If you can do it using the vSphere Client, then you can automate it using the vSphere API. Which means you can create the PHP stubs to perform a specific operation in PHP