5 Replies Latest reply on May 2, 2012 10:06 AM by LucD

    How to grab the view that comes from Onyx?

    Grzesiekk Expert

      Hello,

        i started using Onyx project recently. That's really amazing what it does. I am wondering if there is some possibility to check the main view ... let my try to explain this.

      I want to change option for esxi5 box - advanced/Logging to external syslog server.

      While in gui i did my steps and Onyx prints the output:

      # ------- UpdateOptions -------

       

      $changedValue = New-Object VMware.Vim.OptionValue[] (1)
      $changedValue[0] = New-Object VMware.Vim.OptionValue
      $changedValue[0].key = "Syslog.global.logHost"
      $changedValue[0].value = "tcp://x.x.x.x:514"

       

      $_this = Get-View -Id 'OptionManager-EsxHostAdvSettings-456'
      $_this.UpdateOptions($changedValue)

       

      This is working as expected. I can throw this to powercli and it will set up the option. This will work only for that particular esxi box. I want to create a loop that will change this option for each esxi box in the cluster.

      The view that onyx is using is : "Get-View -Id 'OptionManager-EsxHostAdvSettings-456'"

      So he already knows the view/host moref .

      But if i would like to have this in a loop so it will do it for each host, so  how can i get to that kind of view ?

      So far i could only build something like

      foreach($vmhostview in (get-view -viewtype HostSystem -Searchroot (get-cluster "xxyyzz").id))

      {

       

      $changedValue = New-Object VMware.Vim.OptionValue[] (1)
      $changedValue[0] = New-Object VMware.Vim.OptionValue
      $changedValue[0].key = "Syslog.global.logHost"
      $changedValue[0].value = "tcp://x.x.x.x:514"

      $number=$vmhostview.moref.split("-")[1]

      $_this = Get-View -Id OptionManager-EsxHostAdvSettings-$number
      $_this.UpdateOptions($changedValue)

       

       

      }

      Which is totally stupid approach i belive although it's working.. splitting moref...

       

      After some time i noticed that

      http://pubs.vmware.com/vi-sdk/visdk250/ReferenceGuide/vim.option.OptionManager.html

      Says that OptionManager is the property from Config manager. So from that i could get the id of this view:

      ((get-vmhost myHost |get-view).ConfigManager.AdvancedOption).ToString()

      which will result in output : OptionManager-EsxHostAdvSettings-456

      So having this i could do my loop at the end:

       

      foreach($vmhostview in (get-view -viewtype HostSystem -Searchroot (get-cluster "xxyyzz").id))

      {

       

      $changedValue = New-Object VMware.Vim.OptionValue[] (1)
      $changedValue[0] = New-Object VMware.Vim.OptionValue
      $changedValue[0].key = "Syslog.global.logHost"
      $changedValue[0].value = "tcp://x.x.x.x:514"

      $_this = Get-View -Id ($vmhostview.ConfigManager.AdvancedOption).ToString()

      $_this.UpdateOptions($changedValue)

       

      }

       

      Now i do not know that it was just a luck that i found the location of this view name or is this the way how i am supposed to find the view id name. I am wondering how other people are handling that kind of case, if there is easier way to do it. If someone could share his experience i would really appreciate it.

       

      Regards,

      Greg

        • 1. Re: How to grab the view that comes from Onyx?
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          There is no need to construct these View-Ids as you see them coming from Onyx.

          In fact I would write that script like this

           

          $changedValue = New-Object VMware.Vim.OptionValue[] (1)
          $changedValue[0] = New-Object VMware.Vim.OptionValue
          $changedValue[0].key = "Syslog.global.logHost"
          $changedValue[0].value = "tcp://x.x.x.x:514"

          Get-View -ViewType HostSystem -Searchroot (Get-Cluster "xxyyzz").ExtensionData.MoRef | %{   $optMgr = Get-View $_.ConfigManager.AdvancedOption
            $optMgr.UpdateOptions($changedValue) }

           

          • Move the part that doesn't change with each HostSystem outside the loop
          • The ConfigManager is an array with MoRefs that point to the respective Managers. You can just do a Get-View with a MoRef and it will return the object representing the Manager
          • From the Manager object you can now call the method

           

          Btw, you better consult the latest SDK Reference.

          You can find the HostConfigManager here.

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: How to grab the view that comes from Onyx?
            Grzesiekk Expert

            Hi LucD,

              yes, i've read the sdk manual first , that's how i could come up with that configmanager in first place without that i would be lost.

            Thanks for pointing me out that approch, it's better than this  direct view name, it's more logical for me.

            But i still am wondering what's the approach to find out where is the information "hidden" , is this just a matter of time using the get-view , and some day it will be natural for me that this options sits within this property and so on, or is it just the matter of checking the properties using the sdk manual, and lookup it there ?

            Since we are talking about this logHost value... I wanted to check what's the actual value of this.

            get-view -id $vmhostview.ConfigManager.AdvancedOption  | select -ExpandProperty Setting | ? {$_.Key -like "Syslog.global.logHost"}

             

            Client          : VMware.Vim.VimClient
            Key             : Syslog.global.logHost
            Value           :
            DynamicType     :
            DynamicProperty :

             

            Do you know if i am checking this in a correct way ? I've already set the value for syslog host manualy via vi client and even using powercli, still i am confused as i dont see the value in this logHost key. I believe i am doing it wrong.

             

            Thank you in advance for help !

            Greg

            • 3. Re: How to grab the view that comes from Onyx?
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              I'm afraid that getting to know where to look and where all this stuff is hidden relies a lot on experience.

              Read the SDK, look at other scripts and try to find out how they did it, play around with all the SDK objects and their properties and methods.

              What I find very useful is a GUI debugger with a variable inspector. That will allow you to look at all the properties of the objects.

              I personally prefer PowerShell Plus from Idera, but there are other available.

               

              Yes, that is the good way to inspect that option.

              The Setting property is an array of OptionValue objects, and each of these OptionValue objects has a Key and a Value property.

              In your case, the Value seems to be empty, meaning there was no syslog server defined on that host.

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              1 person found this helpful
              • 4. Re: How to grab the view that comes from Onyx?
                Grzesiekk Expert

                Hey LucD,

                 

                  thank you for your explanation. So i guess it's just matter of time i will get used to get-view .

                 

                I finally have fixed my issue with checking the value of the , i made mistake while checking the value

                get-view (get-vmhost -name hostname |Get-view).ConfigManager.AdvancedOption | select -ExpandProperty Setting |?{$_.Key -like "Syslog.g
                lobal.logHost"} works as expected i just made a typo when choosing the host , and picked those which are waiting to have updated configuration. For some time i just thought that my command is not correct.

                Anyway, thanks again for your help !

                • 5. Re: How to grab the view that comes from Onyx?
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

                  You're welcome.

                  Feel free to post another thread should you encounter problems in your journey through the SDK objects

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz