Esempio n. 1
0
        //Copied from samples VMSnapshot
        private ManagedObjectReference traverseSnapshotInTree(
            VirtualMachineSnapshotTree[] snapTree,
            String findName,
            Boolean print)
        {
            ManagedObjectReference snapmor = null;

            if (snapTree == null)
            {
                return(snapmor);
            }
            for (int i = 0; i < snapTree.Length && snapmor == null; i++)
            {
                VirtualMachineSnapshotTree node = snapTree[i];

                Console.WriteLine("Snapshot Name : " + node.name);


                if (findName != null && node.name.Equals(findName))
                {
                    snapmor = node.snapshot;
                }
                else
                {
                    VirtualMachineSnapshotTree[] childTree = node.childSnapshotList;
                    snapmor = traverseSnapshotInTree(childTree, findName, print);
                }
            }

            return(snapmor);
        }
Esempio n. 2
0
        public override void restoreSnapshot()
        {
            VimClientImpl  _vClient = VClient.getConnection();
            VirtualMachine vm       = VClient.getMachine();

            // Find a named snapshot which corresponds to what we're interested in
            VirtualMachineSnapshotTree snapshot = findRecusively(vm.Snapshot.RootSnapshotList, _spec.snapshotFriendlyName);

            // and revert it.
            VirtualMachineSnapshot shot = new VirtualMachineSnapshot(_vClient, snapshot.Snapshot);

            shot.RevertToSnapshot(vm.MoRef, false);
        }
Esempio n. 3
0
 public VirtualMachineSnapshotTree FindSnapInfo(VirtualMachineSnapshotTree[] tree, String snapmoref)
 {
     for (int i = 0; i < tree.Length; i++)
     {
         VirtualMachineSnapshotTree leaf = tree[i];
         if (leaf.snapshot.Value.Equals(snapmoref))
         {
             return(leaf);
         }
         else if (tree[i].childSnapshotList.Length > 0)
         {
             VirtualMachineSnapshotTree testchild = FindSnapInfo(leaf.childSnapshotList, snapmoref);
             if (testchild != null)
             {
                 return(testchild);
             }
         }
     }
     return(null);
 }
Esempio n. 4
0
        public void DiskMonExtended(string vmmoref, int diskid, long blocksizekb, int display)
        {
            var vr = GetVm(vmmoref);

            if (vr != null)
            {
                ManagedObjectReference csnap = null;
                DateTime cdate    = new DateTime(0);
                String   changeId = null;

                bool allok = true;
                while (allok)
                {
                    var snapinfo = (VirtualMachineSnapshotInfo)cb.getServiceUtil().GetDynamicProperty(vr.Mor, "snapshot");
                    if (snapinfo != null)
                    {
                        ManagedObjectReference querycsnap = snapinfo.currentSnapshot;


                        if (querycsnap != null)
                        {
                            VirtualMachineSnapshotTree info = FindSnapInfo(snapinfo.rootSnapshotList, querycsnap.Value);;
                            if (info != null)
                            {
                                if (csnap != null)
                                {
                                    if (!csnap.Value.Equals(querycsnap.Value) && info.createTime > cdate)
                                    {
                                        System.Console.WriteLine("New snapshot '" + info.name + "' detected, calculating diff");
                                        Dictionary <long, CBTQListedDisk> disks = LsDiskExecute(querycsnap.Value);
                                        if (disks.ContainsKey(diskid))
                                        {
                                            csnap = querycsnap;
                                            cdate = info.createTime;
                                            System.Console.WriteLine("New CBT Changeid " + disks[diskid].cbtTimestamp);


                                            var res = vimservice.QueryChangedDiskAreas(vr.Mor, csnap, diskid, 0, changeId);
                                            if (res != null)
                                            {
                                                CBTQChangeCalc c = LsFixedBlockCalc(res, blocksizekb, (display == 2));
                                                DiskMonPrint(c, vmmoref, display);
                                            }



                                            changeId = disks[diskid].cbtTimestamp;
                                        }
                                        else
                                        {
                                            allok = false;
                                            System.Console.WriteLine("VM does not contain disk id, halting");
                                        }
                                    }
                                }
                                else
                                {
                                    System.Console.WriteLine("Detected First Reference Snap '" + info.name + "'");
                                    Dictionary <long, CBTQListedDisk> disks = LsDiskExecute(querycsnap.Value);
                                    if (disks.ContainsKey(diskid))
                                    {
                                        csnap    = querycsnap;
                                        cdate    = info.createTime;
                                        changeId = disks[diskid].cbtTimestamp;

                                        System.Console.WriteLine("CBT Changeid " + changeId);

                                        var res = vimservice.QueryChangedDiskAreas(vr.Mor, csnap, diskid, 0, "*");
                                        if (res != null)
                                        {
                                            CBTQChangeCalc c = LsFixedBlockCalc(res, blocksizekb, (display == 2));
                                            DiskMonPrint(c, vmmoref, display);
                                        }
                                    }
                                    else
                                    {
                                        allok = false;
                                        System.Console.WriteLine("VM does not contain disk id, halting");
                                    }
                                }

                                if (info.name.Equals("stopdiskmon"))
                                {
                                    System.Console.WriteLine("Detected 'stopdiskmon' snapshot");
                                    allok = false;
                                }
                            }
                        }
                    }
                    System.Threading.Thread.Sleep(500);
                }
            }
            else
            {
                System.Console.WriteLine("Could not find VM");
            }
        }
 private ManagedObjectReference FindSnapshotByName(VirtualMachineSnapshotTree[] tree, string name)
 {
     ManagedObjectReference result = null;
     foreach (VirtualMachineSnapshotTree snapshotNode in tree)
     {
         if (snapshotNode.childSnapshotList != null && snapshotNode.childSnapshotList.Length > 0)
         {
             result = FindSnapshotByName(snapshotNode.childSnapshotList, name);
         }
         if (result != null)
         {
             break;
         }
         else//if the result wasn't found farther down in the tree, then we check this snapshot node to see if it matches the name
         {
             if (snapshotNode.name == name)
             {
                 result = snapshotNode.snapshot;
                 break;
             }
         }
     }
     return result;
 }
Esempio n. 6
0
        private ManagedObjectReference traverseSnapshotInTree(
                                           VirtualMachineSnapshotTree[] snapTree,
                                           String findName,
                                           Boolean print)
        {
            ManagedObjectReference snapmor = null;
            if (snapTree == null)
            {
                return snapmor;
            }
            for (int i = 0; i < snapTree.Length && snapmor == null; i++)
            {
                VirtualMachineSnapshotTree node = snapTree[i];
                if (print)
                {
                    Console.WriteLine("Snapshot Name : " + node.name);
                }

                if (findName != null && node.name.Equals(findName))
                {
                    snapmor = node.snapshot;
                }
                else
                {
                    VirtualMachineSnapshotTree[] childTree = node.childSnapshotList;
                    snapmor = traverseSnapshotInTree(childTree, findName, print);
                }
            }

            return snapmor;
        }