1 Reply Latest reply on Oct 29, 2017 8:30 AM by ReazBaksh

    vsphere WaitForUpdatesEx seems not to work

    ReazBaksh Lurker

      0down votefavorite

       

       

      I have a code that utilizes the WaitforUpdatesEx in the vsphere API to get updated recentTask information from a standalone esxi. On the first run of this I get what is listed in the recentTasks. If i do another task it is not updating as it should. If I run it again I get the new recentTask information along with the old, which is fine for now. I just cant get any updated recentTasks. It seems that the WaitForUpdatesEx is not working. Can someone look at the code and let me know where I'm going wrong? I am using vmware.vim and am using version 6.5.

       

      public void listTasks(VimClient client)
         {
      
      
         ManagedObjectReference objRef = new ManagedObjectReference();
        objRef.Type = "ServiceInstance";
        objRef.Value = "ServiceInstance";
         string version = "";
      
         ServiceContent sc = myConfig.client_1.ServiceContent;
         ManagedObjectReference pcMOR = sc.PropertyCollector;
         ManagedObjectReference rootFolderMOR = sc.TaskManager;
      
      
         PropertySpec pSpec = new PropertySpec();
        pSpec.All = false;
        pSpec.Type = "TaskManager";
        pSpec.PathSet = (new String[] { "recentTask" });
      
         SelectionSpec recurseFolders = new SelectionSpec();
        recurseFolders.Name = "hataskmgr";
      
      
         TraversalSpec hataskmgr = new TraversalSpec();
        hataskmgr.Name = "hataskmgr";
        hataskmgr.Type = "TaskManager";
        hataskmgr.Path = "recentTask"; 
        hataskmgr.Skip = false;
        hataskmgr.SelectSet = new SelectionSpec[] { recurseFolders }; 
      
         ObjectSpec oSpec = new ObjectSpec();
        oSpec.Obj = rootFolderMOR; 
        oSpec.Skip = false;//Skip the propertys of the .Obj
        oSpec.SelectSet = new SelectionSpec[] { hataskmgr };
      
      
      
         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(myConfig.client_1, pcMOR);
      
      
         ManagedObjectReference morCF = pCollector.CreateFilter(pFss[0], true);
         UpdateSet uSet = pCollector.WaitForUpdatesEx(version, new WaitOptions() { MaxWaitSeconds = 0 });
        version = uSet.Version;
      
      
         foreach (PropertyFilterUpdate pfUpdate in uSet.FilterSet)
         {
         ObjectUpdate[] oUpdates = pfUpdate.ObjectSet;
         foreach (ObjectUpdate oUpdate in oUpdates)
         {
         PropertyChange[] pChanges = oUpdate.ChangeSet;
         foreach (PropertyChange pChange in pChanges)
         {
         ManagedObjectReference[] pChangeMors = (ManagedObjectReference[])pChange.Val;
         foreach (ManagedObjectReference pChangeMor in pChangeMors)
         {
         VMware.Vim.Task task = (VMware.Vim.Task)myConfig.client_1.GetView(pChangeMor, null);
      
        lvLogging.Items.Add(task.Info.EntityName + " --> " + task.Info.DescriptionId + " --> " + task.Info.StartTime);
         }
         }
         }
         }
      
      
      
      
      
         return;
      }