VMware Cloud Community
jrackliffe
Hot Shot
Hot Shot
Jump to solution

Fully rehydrating a Vimclient from Vim.dll

Not for Powershell, but the undelrying Vim.dll.

I wish to use this in a web environ and rather than deal with file management nightmares I want to scrape the vmware_soap_session cookie, serialize the value for it, and restore the session from the cookie on the callback rather than relogging in etc.

Well I have the cookie and the reconnect done, but after restoring the Cookie I still have a null ServiceContent. The LoadSession does not have this issue so I imagine there is something I can do to kick the VimClient so it reestablishes the underlying connection. Seems like if I call a GetView for a known entity that can help, but it seems rather brute force. Is there a more elegant way to reestablish the connection after restoring the cookie?

Also, I wish to second the need for a VimClient method for determining if a session is live after restoring. I used to just call CurrentTime on ServiceInstance in the WebServices and capture the exception. The "isSessionActive" in SessionManager needs the username and rather than having to carry that around tooit would be easier to have a bool that used the currentSession data in the cookie. In any case before kicking the VimClient SessionManager is null so its a no go anyways.

J

Reply
0 Kudos
1 Solution

Accepted Solutions
ykalchev
VMware Employee
VMware Employee
Jump to solution

Hi,

If you don't want to save/restore session cookie to/from file you can directly add VMware session cookie to VimClient.WebService.CookieContainer (actually LoadSession do the same):


Cookie sessionCookie = ....; // Already get vmware_soap_session cookie

VimClient vimClient;
vimClient = new VimClient();
vimClient.Connect(serviceUrl);
vimClient.VimService.CookieContainer.Add(sessionSookie);
SessionManager sessionMngr = 
       new SessionManager(vimClient, vimClient.ServiceContent.SessionManager);
sessionMngr.UpdateViewData();

if (sessionMngr.CurrentSession == null) {
   throw new InvalidOperationException("Fail to reuse session cookie");
}

Regards,

Yasen

Yasen Kalchev, vSM Dev Team

View solution in original post

Reply
0 Kudos
5 Replies
harkamal
Expert
Expert
Jump to solution

Can you not use VimClient.LoadSession to load the cookie?

LoadSession        Method     System.Void LoadSession(String fileName)

Reply
0 Kudos
ykalchev
VMware Employee
VMware Employee
Jump to solution

Hi,

If you don't want to save/restore session cookie to/from file you can directly add VMware session cookie to VimClient.WebService.CookieContainer (actually LoadSession do the same):


Cookie sessionCookie = ....; // Already get vmware_soap_session cookie

VimClient vimClient;
vimClient = new VimClient();
vimClient.Connect(serviceUrl);
vimClient.VimService.CookieContainer.Add(sessionSookie);
SessionManager sessionMngr = 
       new SessionManager(vimClient, vimClient.ServiceContent.SessionManager);
sessionMngr.UpdateViewData();

if (sessionMngr.CurrentSession == null) {
   throw new InvalidOperationException("Fail to reuse session cookie");
}

Regards,

Yasen

Yasen Kalchev, vSM Dev Team
Reply
0 Kudos
jrackliffe
Hot Shot
Hot Shot
Jump to solution

harkamal

The LoadSession regrettably requires you use the file system and rather than deal with the annoyance of having our IIS team set proper pers and have them revert over time I wanted to use shelves in memory thus extractingt he cookie. I am hoping Carter will add an overload for non-file based Session management, but last time i looked that was the only option. Again... trying to stay away from the File system to avoid cleanup and perm issues. Hey I am hoping they will opensource the whole Vim library so we can extend, but that may take a bit more time.

ykalchev

That was exactly what I was looking for. I didn't even think of creating a brand new SessionMgr and then calling an update. Makes complete sense! Thanks for that as I had 90% of the cookie work done, but just was missing what was the proper way to reconnect the VimClient to the active session without just brute forcing a getView that I know would fail.

Reply
0 Kudos
harkamal
Expert
Expert
Jump to solution

Okay thanks, that helped me understand more. I was also thinking of using Memory stream and then using FileStream for LoadSession.

Good night

Reply
0 Kudos
jrackliffe
Hot Shot
Hot Shot
Jump to solution

Yeah I had hoped to follow that model as well, but because the LoadSession is void and it's blackbox implementation doesn't allow for you to bypass the actual File creation (redirect to a MemoryStream or FS) you would still need to deal with the perms even for the fraction of time the file existed. Not the end of the world, but scraping the vmware_soap_session cookie is pretty easy and with the rehydrate process you can keep it lean and mean.

Reply
0 Kudos