4 Replies Latest reply on Aug 7, 2017 2:08 AM by nemo14

    PowerCli .NET and Connection status

    nemo14 Lurker

      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

        • 1. Re: PowerCli .NET and Connection status
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          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.

          • 2. Re: PowerCli .NET and Connection status
            nemo14 Lurker

            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);
            • 3. Re: PowerCli .NET and Connection status
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              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.

              1 person found this helpful
              • 4. Re: PowerCli .NET and Connection status
                nemo14 Lurker

                Many thanks all it's clear now.