How to use vSphere Automation APIs to connect to a Lifecycle Manager offline depot.
vSphere Lifecycle Manager
VMware vCenter Server
A vCenter user session ticket needs to be created and passed to the vLCM fileupload login endpoint (i.e. https://{VC}:9087/vum-fileupload/login) to authenticate and authorize a user for access to the offline depot.
You call a POST method to https://<vcenter>/api/session with the username and password as headers. The post method in curl would look like something like the following:
curl -X POST -H "Username:<user>" -H "Password:<pass>" https://<vcenter>/api/session
Here is also a script using pyVmomi to create a session ticket:
#PYTHONPATH=/usr/lib/vmware/site-packages python /root/pyvmomi.pyimport pyVmomiimport pyVim.taskfrom pyVmomi import integrity, vim, vmodlimport datetime, timeimport threadingfrom pyVmomi import Vim, Vmodl, SoapStubAdapter # Disable Python Certificate Validation. Otherwise the following connection to a VUM with a self-signed certificate fails.import os, sslssl._create_default_https_context = ssl._create_unverified_contextstub = pyVmomi.SoapStubAdapter("127.0.0.1",version="vim.version.version8", port=80, sslProxyPath="/sdkTunnel")vcsi = pyVmomi.vim.ServiceInstance("ServiceInstance", stub)content = vcsi.RetrieveContent()userSession = content.sessionManager.Login('[email protected]', 'Admin!23', None)#userSession = content.sessionManager.Login('[email protected]', 'Admin!23', None)print("VC connection established session with key: " + userSession.key)sessionCookie = stub.cookie.split('"')print("Login Session Cookie: ")print(sessionCookie)# stub.cookie = "" # Done to remove the cookie, if we do this, the AcquireSessionTicket call fails as unauthenticatedsessionTicket = content.sessionManager.AcquireSessionTicket()print("Session Ticket is: " + sessionTicket)hasPriv = content.authorizationManager.HasPrivilegeOnEntity(content.GetRootFolder(), userSession.key, "VcIntegrity.lifecycleSettings.Write")# stub.cookie = "" # Done to remove the cookie, if we do this, the GetCurrentSession call fails as unauthenticateduserSession2 = content.sessionManager.GetCurrentSession()print("stub.cookie: " + stub.cookie)print("userSession2: " + userSession2.key)print("Has Privileges : ")print(hasPriv)This session ticket can then be used in any following commands to the vCenter, including logging into the vLCM offline depot and getting a session cookie from there. The below command should produce a session cookie in the headers of the response. You will want to save this value for the vum-fileupload/login call. This is how that might look in curl:
curl -X POST -d "sessionticket=<ticket>" https://<vcenter>:9087/vum-fileupload/login
The cookie produced in the last call will be named "vmware_soap_session". This cookie you will pass as a header to the vum-fileupload/upload call. Along with file-size, file-type, and file-data. In curl it might look like this:
curl -X POST -H "vmware_soap_session=<session_id>" -d "file-size=<size of file>" -d "file-type=<type of file>" -d "file-data=<file_name_with_extension>" https://<vcenter>:9087/vum-fileupload/upload
Please see the below for common failures:
Failure, Authentication failed, not a valid user" - KB 411037Failure, Authorization failed, user doesn't have enough privileges to upload file" - KB 411048Failure, unsupported file extension" - KB 411049