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.
Original Message:
Sent: Feb 05, 2011 01:50 AM
From: mcowger
Subject: vSphere and php
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.