Ejemplo n.º 1
0
        public string Snapshot(P2PBackup.Common.Node vm, string snapshotName)
        {
            ManagedObjectReference searchIndex = this.serviceContent.searchIndex;
            ManagedObjectReference vmMor       = service.FindByUuid(searchIndex, null, vm.InternalId, true);

            LogEvent(this, new LogEventArgs(0, Severity.DEBUG, "VM search returned vmMor '" + vmMor.Value + "'"));
            LogEvent(this, new LogEventArgs(0, Severity.DEBUG, "About to create a snapshot with name '" + snapshotName + "'"));
            ManagedObjectReference taskMor = service.CreateSnapshot_Task(vmMor, snapshotName, "", false, true);

            //TaskInfo ti = new TaskInfo();
            if (LogEvent != null)
            {
                LogEvent(this, new LogEventArgs(0, Severity.TRIVIA, "Snapshot task has mor '" + taskMor.Value + "'"));
            }
            TaskInfo snapTaskInfo = new TaskInfo();

            while (true)
            {
                try{
                    ObjectContent[] oCary = GetObjectProperties("Task", new string[] { "info" }, taskMor);
                    snapTaskInfo = snapTaskInfo = (TaskInfo)oCary[0].propSet[0].val;
                    if (LogEvent != null)
                    {
                        LogEvent(this, new LogEventArgs(700, Severity.DEBUG, "Snapshot task completion " + snapTaskInfo.progress + "%, state=" + snapTaskInfo.state.ToString()));
                    }
                    if (snapTaskInfo.state == TaskInfoState.running || snapTaskInfo.state == TaskInfoState.queued)
                    {
                        System.Threading.Thread.Sleep(10000);
                    }
                    else
                    {
                        break;
                    }
                }
                catch {}
            }
            if (snapTaskInfo.state != TaskInfoState.success)
            {
                throw new Exception("Couldn't get VM snapshot, task ended with status " + snapTaskInfo.state + ", reason=" + snapTaskInfo.reason.ToString());
            }
            ManagedObjectReference snapMor = (ManagedObjectReference)snapTaskInfo.result;

            //	Console.WriteLine ("VMWareHandler.Snapshot') : task mor="+snapName);
            if (LogEvent != null)
            {
                LogEvent(this, new LogEventArgs(0, Severity.INFO, "Created VM snapshot with mor '" + snapMor.Value + "'"));
            }
            return(snapMor.Value);
        }