0 Replies Latest reply on Oct 4, 2017 5:06 PM by ReazBaksh

    Help with TraversalSpec

    ReazBaksh Lurker

      Hello
      I trying to retrieve data from a standlone esxi host using c# and the vmware.vim.dll. 
      I am trying to do this using the Property Controller along with the TraversalSpec.  The following code is what I have but when I run it I get the following:

      "Additional information: A specified parameter was not correct: undefined TraversalSpec name" at the 
      ObjectContent[] objs =pCollector.RetrieveProperties(pFss);


      Without the TraversalSpec section I can get the maxCollector value if I change the "ipAddress" to "maxCollector" but I'm trying to get the ipAddress that is within the latestEvent property.
      This is just a test to see that it works.  So far I cant get the TraversalSpec part to work.

      Any help would be appreciated.

      public void listTasks(VimClientImpl client)
       
              {
          ManagedObjectReference objRef = new ManagedObjectReference();
       
                  objRef.Type = "ServiceInstance";
       
                  objRef.Value = "ServiceInstance";
       
       
       
                  ServiceContent sc = client.ServiceContent;
       
                  
       
                  ManagedObjectReference pcMOR = sc.PropertyCollector;
       
                  
       
                  ManagedObjectReference rootFolderMOR = sc.EventManager;
       
                  PropertySpec pSpec = new PropertySpec();
       
                  pSpec.All = false;
       
                  pSpec.Type = rootFolderMOR.Type;
       
                  pSpec.PathSet = (new String[] { "ipAddress" });
       
       
       
                  ObjectSpec oSpec = new ObjectSpec();
       
                  oSpec.Obj = rootFolderMOR;
       
       
       
                  TraversalSpec folderToChild = new TraversalSpec();
       
                  folderToChild.Name = "folderToChild";
       
                  folderToChild.Type = rootFolderMOR.Type;
       
                  folderToChild.Path = "latestEvent";
       
                  folderToChild.Skip = false;
       
       
       
                  SelectionSpec foldersSSpec = new SelectionSpec();
       
                  foldersSSpec.Name = "folderToChild";
       
                  SelectionSpec[] ftcArr = new SelectionSpec[] { foldersSSpec };
       
                  oSpec.SelectSet = ftcArr;
       
       
       
       
       
                  PropertyFilterSpec[] pFss = new PropertyFilterSpec[1];
       
                  pFss[0] = new PropertyFilterSpec();
       
                  pFss[0].ObjectSet = (new ObjectSpec[] { oSpec });
       
                  pFss[0].PropSet = (new PropertySpec[] { pSpec });
       
       
       
                  PropertyCollector pCollector = new PropertyCollector(client, pcMOR);
       
       

                  //fails at this point

                  ObjectContent[] objs =pCollector.RetrieveProperties(pFss);
       
       
       
                  if (objs!=null&&objs[0]!=null)
       
                  {
       
                      for (int i =0; i<objs.Length;i++)
       
                      {
       
                          DynamicProperty[] dps = objs[i].PropSet;
       
                          foreach (DynamicProperty d in dps)
       
                          {
       
                              listview1.Items.Add(d.Val);
                          }
       
                      }    
       
                  }
       
               }
       

      Thanks

      public void listTasks(VimClientImpl client)
       
              {
          ManagedObjectReference objRef = new ManagedObjectReference();
       
                  objRef.Type = "ServiceInstance";
       
                  objRef.Value = "ServiceInstance";
       
       
       
                  ServiceContent sc = client.ServiceContent;
       
                  
       
                  ManagedObjectReference pcMOR = sc.PropertyCollector;
       
                  
       
                  ManagedObjectReference rootFolderMOR = sc.EventManager;
       
       
       
                  
       
                  
       
                  PropertySpec pSpec = new PropertySpec();
       
                  pSpec.All = false;
       
                  pSpec.Type = rootFolderMOR.Type;
       
                  pSpec.PathSet = (new String[] { "ipAddress" });
       
       
       
                  ObjectSpec oSpec = new ObjectSpec();
       
                  oSpec.Obj = rootFolderMOR;
       
       
       
                  TraversalSpec folderToChild = new TraversalSpec();
       
                  folderToChild.Name = "folderToChild";
       
                  folderToChild.Type = rootFolderMOR.Type;
       
                  folderToChild.Path = "latestEvent";
       
                  folderToChild.Skip = false;
       
       
       
                  SelectionSpec foldersSSpec = new SelectionSpec();
       
                  foldersSSpec.Name = "folderToChild";
       
                  SelectionSpec[] ftcArr = new SelectionSpec[] { foldersSSpec };
       
                  oSpec.SelectSet = ftcArr;
       
       
       
       
       
                  PropertyFilterSpec[] pFss = new PropertyFilterSpec[1];
       
                  pFss[0] = new PropertyFilterSpec();
       
                  pFss[0].ObjectSet = (new ObjectSpec[] { oSpec });
       
                  pFss[0].PropSet = (new PropertySpec[] { pSpec });
       
       
       
                  PropertyCollector pCollector = new PropertyCollector(client, pcMOR);
       
       
       
                  ObjectContent[] objs =pCollector.RetrieveProperties(pFss);
       
       
       
                  if (objs!=null&&objs[0]!=null)
       
                  {
       
                      for (int i =0; i<objs.Length;i++)
       
                      {
       
                          DynamicProperty[] dps = objs[i].PropSet;
       
                          foreach (DynamicProperty d in dps)
       
                          {
       
                              
       
                                   
       
                              listview1.Items.Add(d.Val);
       
                                  
       
                          }
       
                      }    
       
                  }
       
               }