Hello All:
I am trying to write an application using PHP to automate a few things, e.g: cloning, retrive information, etc .... I've already tried to use nusoap as well as the native PHP5 soap class. However I am running into some issues.
Does anyone has any reference/documentation for some sample code in php? I am able to get a couple of methods to work (Login/Logout/ QueryConnectionInfo). However, when I try other methods using the same format, the code fails to the following fault:
InvalidRequestFault
Thanks in advance,
Alfredo
Below is the request/response received for the method (operation) failing:
Fault
Array
(
(
)
)
Request
POST /sdk/vim.wsdl HTTP/1.1
Host: pv-test-vc
User-Agent: NuSOAP/0.7.3 (1.114)
Connection: close
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: ""
Content-Length: 706
Cookie: vmware_soap_session="C812ACBF-DAE4-4657-A859-946C2A27F72A";
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns6275:QueryConnectionInfo xmlns:ns6275="urn:vim25"><_this xsi:type="xsd:string" type="Datacenter">Datacenter</_this><username xsi:type="xsd:string">user</username><password xsi:type="xsd:string">passwd</password><hostname xsi:type="xsd:string">pv-vmware-02.cisco.com</hostname></ns6275:QueryConnectionInfo></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
HTTP/1.1 500 Internal Server Error
Date: Wed, 7 May 2008 18:18:50 GMT
Cache-Control: no-cache
Content-Type: text/xml; charset=utf-8
Content-Length: 535
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault><faultcode>ServerFaultCode</faultcode><faultstring>hostname</faultstring><detail><InvalidRequestFault xmlns="urn:vim25" xsi:type="InvalidRequest"></InvalidRequestFault></detail></soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Answering my own question here.
I ended up writing a php class to handle all the basic operations needed to use the VI-SDK SOAP API.
It's a scaled down version of the perl tool kit in php, around 800 lines of code, nothing too crazy; just enough to allow for
specialized classes to be built extending the functionality of the base class which provides methods as previously mentioned to retrieve properties and invoke operations.
Alfredo
lawwton AT gmail DOT com
Hey lawwton; any chance of getting ahold of what work you did do in PHP?
I'm beginning a similar project and I think your sample code would probably help kick start my project!
Any help is greatly appreciated :
dmclain AT expressdynamics DOT com
Thanks!
I sent you an email with some ideas.
Hope it helps,
Alfredo
Hi lawwton,
I was wondering if you would mind sending me a copy of the class and details also. I'm basically in the same position as dmclain
My address is joe <dot> tiedeman <at> hesa <dot> ac <dot uk
Many Thanks
Joe
I have started to research how quickly i could write a simple reporting script like this. If you could email me any notes or code parts that would help me a lot thanks. jselinger< a t >corpitsol <d ot>com. thanks
I'm trying to use the PHP SOAP Toolkit (PST) with the WSDL's provided by VMware. Not having a lot of luck with the automated stuff, so I wanted to take a look at your code to see if it helps. If you don't mind sending it, I'm olaf.gradin at Gmail.
It takes a viking to raze a village.
olafgradin:
I don't think there is a PHP Tool Kit. I only know of a perl tool kit. If you can use perl in your environment that is probably your best option.
I wrote a base class in php that provides enough functionality to allow for the retrieval as well as invoking operations. I was planning on making the code public (open) but I was told not to due to company policy
I can help you though if you decide to write your own base class (php) and feel that you need a bit of help.
Regards,
Alfredo
I know it's been a looooong time. Is there a way you could give some pointers on getting PHP to work via SOAP to the VI SDK? I'm trying to use NUSOAP to communicate with it, but can't even connect, it just gives odd errors (and I've tried with and without SSH)
Thanks in advance
I'm also looking at using PHP for this and have made some good progress, however I've become a bit stuck at the point of trying to find the machines using methods such as:
FindByInventoryPath
FindByIp
Has anyone got any PHP examples to work from?
Sorry, I can't even get it to connect using NUSOAP, it just fails but never gives a proper error. What method have you used to connect and get the basic information?
I've had no problem connecting, however I then can't seem to figure out how to carry out commands. I get the following results:
-
Array
(
=> AXBXF388-5173-4434-X971-B212C7X6C61F
=> 2009-03-10T15:16:22.0625Z
=> 2009-03-10T15:16:22.0625Z
)
-
string(0) ""
-
If you look at the code I would have thought it would have returned information on the virtual machine I'm searching for!
So I've made a lot of progress in terms of this and can now power on/off a machine based on the UUID (see attached script).
However I haven't been able to return information on the "powerState" of the server from the data object "VirtualMachineRuntimeInfo", although I can see this information in the mob.
Does anyone have any ideas?
Thanks.
I can connect to my vCenter without any problems but the same code doesnt work when try to connect to a standalone ESX or ESXi Server. I'am right that everyone use the modified NuSoap which was provided by run-virtual.com?
Can someone report please if its possible to connect to a single server also?
I was succesfull in fetching
- the connection information from the serviceinstance and in modifying some off the settings
- sending a complete XML string with a prop-,specset and a traversal through existing folders to get the VirtualMachine object which returns all information about runtime stats and hardware infos
- simple VM modifications like shutdown/startup/reset and so on
Regards,
Joerg
Hi Altix
Could you possibly send me some of your code? I am really having trouble trying to get my head around this. Some example code would go a long way to getting me on track. It would be much appreciated.
My email address is andrew[dot]rall[at]gmail[dot]com
Thanks
I think you may want to take a look at the open source VI Java API because it's implemented from scratch, and you can borrow the idea to PHP as needed.
Steve Jin, Author of VMware VI and vSphere SDK, http://www.doublecloud.org
Hi Altix,
could u pls help me how to get a virtual machine utilization details like cpu usage,memory usage etc using vsphere webservices sdk.Is there any webservice method provided by vsphere webservices sdk which gives vm utilization details.i want to consume that webservice using php.
Actually i am able to login to the server by consuming "login" functionality.
Thanks and Regards
Maheswari