5 Replies Latest reply on Apr 26, 2019 9:22 AM by Duncan Grisby

    Sync mapping traversal assist

    Ryan Nicosia
      Share This:

      Long story short, we have a requirement for a custom view in CMDB to show Hypervisors and the vCenter that they are managed from.  It includes a bunch of other attributes (relationships) such as IP and OS.

       

      I've got all the joins done but in order to do the vCenter, it would take 4 additional joins and that just seems like alot of extra overhead.  So, I'd like to just map that over as an attribute on Computer System.

       

      Whether that is the best solution or not is probably debateable.  That said, I was hoping somebody could at least get me down the road with the traversal.  This is the raw query when I pull it up in Discovery.  I'm just struggling with how to traverse as there are 2 relationships there.

       

       

      This is about as far as I got and I don't think it is right.

       

        mapping from Host_ComputerSystem.host as host

       

      traverse ManagedElement:Management:Manager:SoftwareInstance as softwaresvr

      traverse RunningSoftware:HostedSoftware:Host:Host as ParentHost

      end traverse;

          end mapping;

       

         body

              computersystem := Host_ComputerSystem.computersystem;

       

              if host.type = "Hypervisor" then

      for each softwaresvr do

        • 1. Re: Sync mapping traversal assist
          Duncan Grisby

          You are going along the right path.

           

          In your mapping block, you can put a condition on the "mapping from", so your mapping only executes when you want it to:

           

            mapping from Host_ComputerSystem.host as host where type = "Hypervisor"

           

          It doesn't matter functionally, but it's very confusing to to people reading it to call the first traversal target "softwaresvr", because I read that as "software server", which is the CI class, not the Discovery node kind. Call it something corresponding to what it really is:

           

              traverse ManagedElement:Management:Manager:SoftwareInstance as manager_si

                traverse RunningSoftware:HostedSoftware:Host:Host as manager_host

                end traverse;

              end traverse;

            end mapping;

           

          Then in the body, you no longer need to test the type because it's in the mapping specification. You need two nested loops for the two nested traversals:

           

            body

              computersystem := Host_ComputerSystem.computersystem;

              for each manager_si do

                for each manager_host do

                  computersystem.MyExtendedAttr := manager_host.name; // or whatever you need

                end for;

              end for;

            end body;

           

          3 of 3 people found this helpful
          • 2. Re: Sync mapping traversal assist
            Ryan Nicosia

            Duncan,

            Thanks for the quick response.  As always, you have been super helpful!!

            • 3. Re: Sync mapping traversal assist
              Ryan Nicosia

              I must be missing something.  Getting a syntax error

               

              failed because Syntax error at or near 'where' at line 13.

               

              tpl 1.12 module CMDB.Extension.vCenter_Augment;

               

               

              from CMDB.Host_ComputerSystem import Host_ComputerSystem 2.0;

               

               

              syncmapping vCenter_Augment 1.0

                  """

                  Sync vCenter host that manages Hypervisor to CMDB

                  """

                  overview

                      tags CMDB, Extension;

                  end overview;

               

               

                mapping from Host_ComputerSystem.host as host where type = "Hypervisor"

               

              traverse ManagedElement:Management:Manager:SoftwareInstance as manager_si

                         traverse RunningSoftware:HostedSoftware:Host:Host as manager_host

                         end traverse;

                      end traverse;

                end mapping;

               

               

                body

                  computersystem := Host_ComputerSystem.computersystem;

                  for each manager_si do

                    for each manager_host do

                      computersystem.vCenterHost := manager_host.name;

                    end for;

                  end for;

                end body;

              end syncmapping;

              • 4. Re: Sync mapping traversal assist
                Ryan Nicosia

                Think I found the issue with the syntax error.  Switched the mapping to read

                 

                mapping from Host_ComputerSystem.host where type = "Hypervisor" as host

                1 of 1 people found this helpful
                • 5. Re: Sync mapping traversal assist
                  Duncan Grisby

                  Yes, sorry, I accidentally put it in the wrong order.