I've succesfully written some Javascript to handle some VM tasks within Virtual Center (power on, off, clone etc.). I'm now trying to get info out of our (non-VC managed) ESXi hosts using the web services API and can't even get a succesful login. All I'm trying to do at the moment is login, then logout. I assumed all I'd need to do is modify the SDK location url, username and password in my working script, but am getting no session cookie returned and "Login, SOAP fault string: The session is not authenticated" error.
Am I missing some fundamental difference between the VC API and the ESXi API?
Cheers, Nick.
Regarding making the connection, its the same string URL htts://<server_name_ip>/sdk, I would check to see if you can make a connection first and then proceed further. It sounds like you're not able to even make a connection which means you're running into an authentication/connection issue, check to make sure the user/password is valid. Once, you're able to successfully make a connection, there are some objects/properties that are only available from vCenter versus an individual ESX(i) host and this is described pretty well within the vSphere API docs:
One simple way is try to connect to the MOB via a standard web browser, this will validate the user you're trying to use and let you know if its your code or the user. Point your browser to https:///mob and login with the username and see if you can successfully connect.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Thanks for the response - I'm really starting to pull my hair out over this. I thought it would be trivial to reuse my working code with ESXi.
Not sure what you mean by making a connection first - the first function I invoke is "Login" - I don't need to "connect" prior to that do I? I can connect to the mob web interface no problem with the same credentials that I am using in my code. I also tested the code against my VC server with wrong credentials and got "SOAP fault string: Login failed due to a bad username or password", which leads me to think that it's not an authentication issue with ESXi - I'd expect the same SOAP fault.
I've configured the ESXi web service to use HTTP so I can capture the SOAP conversation. This is what I see when the "Login" function is invoked:
POST /sdk HTTP/1.1 Accept-Language: en-gb Content-Length: 379 Accept: / Content-Type: text/plain; Charset=UTF-8 User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5) Host: myesxihost.com Connection: Keep-Alive <?xml version="1.0" encoding="utf-8"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><env:Body><Login xmlns="urn:vim25"><_this type="SessionManager">SessionManager</_this><userName>myusername</userName><password>mypassword</password></Login></env:Body></env:Envelope>
HTTP/1.1 500 Internal Server Error Date: Tue, 28 Jul 2009 08:06:35 GMT Cache-Control: no-cache Content-Type: text/xml; charset=utf-8 Content-Length: 657 <?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>The session is not authenticated.</faultstring><detail><NotAuthenticatedFault xmlns="urn:vim25" xsi:type="NotAuthenticated"><object type="SessionManager">SessionManager</object><privilegeId>System.View</privilegeId></NotAuthenticatedFault></detail></soapenv:Fault> </soapenv:Body> </soapenv:Envelope>
Any ideas greatly appreciated.
Cheers, Nick.
Hmm .. I can successfully call "RetrieveServiceContent" without authenticating .... not sure what that tells me though
Think I've got there. In my original code I didn't make a call to "RetrieveServiceContent" to get the value for the SessionManager object - it was"hard" coded as "SessionManager". The ESXi SessionManager object appears to be called "ha-sessionmgr" (don't know if this is the same for every host) - changing this gave me a succesful logon. At least now I can make some progress.
Cheers, Nick.
Hi Nick,
Could you please specify the code you are using for conncting to a host? I am trying to figure out connecting to a host directly from vCO so I can change the root password through a workflow.
Thanks is advance,
Bas