VMware Cloud Community
nemo14
Contributor
Contributor
Jump to solution

PowerCli .NET and Connection status

Dear,

i'm using VMWare.Vim library for .NET application,  to inspect my hypervisor. Usually i start a request with Connect() method,querying items and Disconnect(), and all works. 

I would like to avoid Connect/Disconnect every time to improve performance but i notes there's no property o method to check if connection is alive (just for example the  network fall down).

So I would like to know if is there a suggestion to check connection status or if i must connect/disconnect every time.

Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you check the SessionManager, the CurrentSession property indicates if a there is a live session.

If you want to avoid doing a Connect-Disconnect each time, you also look at the SaveSession and LoadSession methods.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

If you check the SessionManager, the CurrentSession property indicates if a there is a live session.

If you want to avoid doing a Connect-Disconnect each time, you also look at the SaveSession and LoadSession methods.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
nemo14
Contributor
Contributor
Jump to solution

Thanks for your reply. I'm newbie in vSphere PowerCLI and I'm not able to get access to  SessionManager property from VimClientImpl.ServiceContent (see attached file). Where am I wrong (below my connection code)?

 

VimClient _connectionclient = new VimClientImpl();

string connectionstring = "https://" + _connectionname + "/sdk";

_connectionclient.Connect(connectionstring);

_connectionclient.Login(_username, _password)

 

 if (_connectionclient == null ) _connectionclient = new VimClientImpl();
                string connectionstring = "https://" + _connectionname + "/sdk";
                logMessage = string.Format("[{0} Plugin] connection String: {1} Username: {2} Password: {3}", Runclass.PluginNameST(), connectionstring, _username, _password);
                LogMain.Info(logMessage);
                LogPlugin.Info(logMessage);
                Console.WriteLine(logMessage);
                _connectionclient.Connect(connectionstring);
                _connectionclient.Login(_username, _password);
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The SessionManager in ServiceContent is a MoRef (a Managed Object Reference).

Kind of like a pointer, you will have to use GetView method to get the actual object from the MoRef.

In the vSphere SDK for .NET Developer’s Guide you'll find examples.

Also have a look at the VMware{code} site, they have examples as well.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

nemo14
Contributor
Contributor
Jump to solution

Many thanks all it's clear now.

0 Kudos