5 Replies Latest reply on Jan 23, 2010 6:10 PM by lynxbat

    Getting Props back from SessionManager

    lynxbat Novice


      So I have been banging against this for a week now. But, I cannot figure out the proper was to obtain the properties of the SessionManager MOR (namely sessionList).



      I can't find any docs out there showing examples to this either. I can get PropCollect to do almost anything I want except this.






      Anybody got this working and have an example on what to set for PropSpec and ObjectSpec type/path?















        • 1. Re: Getting Props back from SessionManager
          lamw Guru
          VMware EmployeesCommunity Warriors

          I don't recall off the top of my head if MO is available on both vCenter and individual ESX(i) host, or if it's just vCenter. If it is, then you just need to get the MoRef from Service Content and then check whether or not the sessionList array is available, if so, then it'll be returned back as an array of string with each user session as specified: http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.UserSession.html


          e.g. in Perl:


          my $content = Vim::get_service_content();
          my $sessionMgr = Vim::get_view(mo_ref => $content->sessionManager);
          if($sessionMgr->sessionList) {
                  my $sessionLists = $sessionMgr->sessionList;
                  foreach(@$sessionLists) {
                           //do something



          You can also easily verify by browsing the MOB of your vCenter or host, depending on which one you're connecting to and see if there is data available under the sessionManager.







          William Lam

          VMware vExpert 2009

          VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

          Twitter: @lamw

          vGhetto Script Repository

          Getting Started with the vMA (tips/tricks)

          Getting Started with the vSphere SDK for Perl

          VMware Code Central - Scripts/Sample code for Developers and Administrators

          VMware Developer Comuunity




          If you find this information useful, please award points for "correct" or "helpful".


          Message was edited by: lamw

          • 2. Re: Getting Props back from SessionManager
            lynxbat Novice


            I am working with VB.NET(C# examples are fine too) so my approach is different syntax-wise.



            I am having no trouble getting the SessionManager MO to return but I don't get any of the dynamic proporties.









            • 3. Re: Getting Props back from SessionManager
              paul_xtravirt Expert

              Hi There,


              I have knocked this up for you VB - I hope it helps. The code assumes that you have a connecton to vCenter and that the connection is called VCConnection. The service content object has been retrieved and is referenced as SC in the below script.



              The view_object function that is called comes from code released in the VMware Code Samples area of the development community. It is in the VB.NET section, in the script that shows how to retrieve information from objects. (here is the link to the sample code that contains the function ->>   http://communities.vmware.com/docs/DOC-10278 )



              If you need any of the other code that goes around this, let me know and I can post it up.


              Dim session_list As Array = Nothing
              Dim tmp_objects() As VimApi.ObjectContent = view_object(VCConnection, SC.sessionManager)
              For session_element As Integer = 0 To tmp_objects.Length - 1
              Dim session_array As Array
              session_array = tmp_objects(session_element).propSet
              For session_prop As Integer = 0 To session_array.Length - 1
              Dim session_dp As New VimApi.DynamicProperty
              session_dp = session_array(session_prop)
              If session_dp.name = "sessionList" Then
              session_list = session_dp.val
              For Each session_list_entry As VimApi.UserSession In session_list
              MsgBox("Full Name: " & session_list_entry.fullName & vbCrLf & _
              "Username: " & session_list_entry.userName & vbCrLf & _
              "Key: " & session_list_entry.key & vbCrLf & _
              "LoginTime: " & session_list_entry.loginTime)
              End If


              If you found this helpful, please consider awarding some points

              1 person found this helpful
              • 4. Re: Getting Props back from SessionManager
                lynxbat Novice

                Thanks for this man. Leading me to the vc_functions.vb gives me an example of something that works which will help me figure out why I am not grabbing the dynamic properties. The query for the dynamic pieces is easy, I just have my propcollection function not working right.


                I will pour through the sample and figure out where I went wrong.










                Much appreciated












                • 5. Re: Getting Props back from SessionManager
                  lynxbat Novice


                  Found the problem: I was missing the 'VimApi.VimService.PropertySpec.allSpecified = True' setting on my PropertySpec.



                  Funny thing is that property is not listed anywhere I can find in the API reference or UML. I see it now in a bunch of sample stuff though.






                  Thanks for everyone's help