如何使用Xenserver API创建快照

时间:2015-09-08 15:31:45

标签: c# virtual-machine citrix xen

我正在使用C#和Xenserver API编写模拟XenCenter的WPF应用程序。我已从https://github.com/xenserver/xenadmin中删除了XenAPI解决方案并在我的应用程序中实现;我可以成功启动,停止,恢复和克隆虚拟机。不幸的是,我无法为所有VM拍摄快照。我正在使用两个VM来测试应用程序。 Windows XP SP3(未安装操作系统,仅安装VM)和Ubuntu 14.04 Trusty Tahr(操作系统已安装并正常运行)。当我调用快照功能时,它适用于Windows机器,但不适用于Ubuntu机器。两次尝试都在调试中提供类似的输出(如下)。我已经在https://github.com/xenserver/xenadmin/blob/master/XenModel/Actions/VM/VMSnapshotCreateAction.cs之后模拟了我的尝试。我会问Citrix问题是什么,但他们需要支付报酬而且我只是一名学生。有人可以帮忙吗?

2015-09-08 11:16:47.3372 DiagTrc Attemping VM snapshot
2015-09-08 11:16:47.3702 DiagTrc Attempting to Snapshot VM Windows XP SP3 (32-bit)...
------Entering if-----
------Executed Disk Snap-----
------VM: OpaqueRef:b410fa67-f0fa-0aec-4db6-0430ae6b795b-----
------Result: -----
VM Snap Completed with possible errors
The thread 0x596a0 has exited with code 0 (0x0).
The thread 0x59b74 has exited with code 259 (0x103).
The program '[366012] WPFClient.vshost.exe' has exited with code 0 (0x0).    

public String SnapshotVM(string vmName)
    {
        String retStatus = "Successfully Created VM Snapshot";
        _logger.Debug("Attempting to Snapshot VM {0}...", vmName);

        if (!ValidateActiveVM(vmName))
        {
            retStatus = String.Format("Error: VM not found");
            _logger.Error(retStatus);
        }
        else
        {
          //  try
           // {


                XenRef<VM> vmRef = VM.get_by_uuid(_session, GetUUIDByName(vmName)); //VM = XenAPI.VM
                XenRef<XenAPI.Task> _relatedTask2 = null;
                SnapshotType m_Type = SnapshotType.DISK; //hardcoded snapshot type
                string snapshot_name = "TestingSnapshot";
                string m_NewDescription = "SnapshotTestVM snap";

                System.Console.WriteLine("------Entering if-----");

                if (m_Type == SnapshotType.QUIESCED_DISK)
                {
                   _relatedTask = XenAPI.VM.async_snapshot_with_quiesce(_session, vmRef.opaque_ref, snapshot_name);

                   System.Console.WriteLine("------Executed Quiesced Snap-----");
                }
                else if (m_Type == SnapshotType.DISK_AND_MEMORY)
                {
                   _relatedTask = XenAPI.VM.async_checkpoint(_session, vmRef.opaque_ref, snapshot_name);
                }
                else
                {
                    _relatedTask2 = XenAPI.VM.async_snapshot(_session, vmRef.opaque_ref, snapshot_name);
                   System.Console.WriteLine("------Executed Disk Snap-----");
                   System.Console.WriteLine("------VM: {0}-----",vmRef.opaque_ref);

                }
               // PollToCompletion();  // should probably implement this 

                string taskResult = XenAPI.Task.get_result(_session, _relatedTask2.opaque_ref);

                 System.Console.WriteLine("------Result: {0}-----", taskResult);


                if (String.IsNullOrEmpty(taskResult) || !taskResult.StartsWith("<value>") || !taskResult.EndsWith("</value>"))
                {
                    System.Console.WriteLine("VM Snap Completed with possible errors");
                    return "VM Snap Completed with possible errors";
                }
                //string newVmRef = taskResult.Substring(7, taskResult.Length - 15);

               // XenAPI.VM.set_name_description(_session, newVmRef, m_NewDescription);//set vm name/description
          //  }
         /*   catch (Exception ex)
            {
                retStatus = String.Format("Error: {0}", ex.Message);
                System.Console.WriteLine("====> Exception Generated {0}",ex.Message);
                _logger.Error(retStatus);
            }*/
        }

        return retStatus;

    }

0 个答案:

没有答案