【问题标题】:How to wait a task after cloning VM with VMWare.vim.dll?使用 VMWare.vim.dll 克隆 VM 后如何等待任务?
【发布时间】:2017-02-07 08:59:26
【问题描述】:

我正在开发一个管理 vsphere Esx 5.5 上的虚拟机的 Web 界面。我的程序是使用 .net 网络表单(不是 MVC)开发的。

我关注了 jeffpaton 的帖子(使用 VMware.Vim),这些帖子帮助了我(感谢您,Jeff)https://communities.vmware.com/thread/434579

但现在我冻结了这个主题。克隆 VM 后,我不知道如何等待任务。我的网站使用 vmware.vim 向 Vsphere Esx 启动 vsphere 命令。我需要知道 vpshere 何时完成他的工作以启动另一条指令。

我尝试使用 PropertyCollector 但我不知道如何使用它:

我红了这篇文章但没有成功:

这是我尝试的代码的一部分,但我被阻止了。我使用 jeffpaton 函数。

using VMware.Vim;
...
VimClient client;
string serverUrl = "..."
client.Connect("https://" + serverUrl + "/sdk");
client.Login(userLogin, userPassword);
...
ManagedObjectReference cloneTask_MoRef = null;

//1 waiting the cloning task
cloneTask_MoRef = sourceVm.cloneVM_Task(sourceVm.Parent, "cloneName", mySpec);

if (cloneTask_MoRef == null) {
 //error
}else
{
    PropertyCollector pc = new PropertyCollector(client, cloneTask_MoRef);

    PropertyFilterSpec[] pfs = null;
    RetrieveOptions ro = new RetrieveOptions();
    RetrieveResult rResult = new RetrieveResult();


    //PropertySpec
    //pc.CreateFilter(pfs, true);
    //rResult = pc.RetrievePropertiesEx(pfs,ro);
    //

   //2 PowerOn the CloneVM                                                       
   cloneVM = this.vimClientTools.getVirtualMachines(selectedDC, cloneName)[0];

   //3 waiting the powerOn Task...

      //What could i do to know if the task is over or in progress ? :-(

我需要一些帮助。如果有人有建议开始...

谢谢大家。

【问题讨论】:

    标签: c# vmware powercli


    【解决方案1】:

    这可能为时已晚,但这里是。

    VimClient 有一个 WaitForTask 方法;

    client.WaitForTask(cloneTask_MoRef);
    

    或者,您可以获取任务并查看其进度;

    var task = (Task) client.GetView(cloneTask_MoRef, null);
    
    while (task.Info.State != TaskInfoState.success)
    {
        Thread.Sleep(5000);
        task.UpdateViewData();
        if (task.Info.State == TaskInfoState.error)
            throw new Exception($"The clone failed: {task.Info.Error.LocalizedMessage}");
    
        Console.WriteLine(task.Info.Progress);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-10
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-06
      • 2021-04-09
      • 1970-01-01
      • 2012-07-15
      相关资源
      最近更新 更多