Exemple #1
0
        public string TakeSnapshot()
        {
            var key = uuid + ":" + DateTime.Now.ToFileTime();

            VirtualboxUtils.VBoxManage("snapshot " + uuid + " take \"" + key + "\" --pause");
            LoadSnapshots();

            return(Snapshots.Where(ss => ss.Name == key).First().Id);
        }
Exemple #2
0
        public bool DownloadFile(string url, string destination)
        {
            lock (driver)
            {
                string argString = string.Format(
                    "guestcontrol {0} cp \"{1}\" \"{2}\" --username Administrator", uuid, url, destination);

                return(VirtualboxUtils.VBoxManage("guestcontrol " + uuid +
                                                  " cp '" + url + "' '" + destination + "' --username Administrator"));
            }
        }
Exemple #3
0
        void LoadMachines()
        {
            machineMap.Clear();
            IEnumerable <string> machineStrings;

            VirtualboxUtils.VBoxManage("list vms", out machineStrings);
            foreach (var str in machineStrings)
            {
                var               parts   = str.Split(new[] { '"' }, StringSplitOptions.RemoveEmptyEntries);
                string            name    = parts[0].Trim();
                string            uuid    = parts[1].Trim();
                VirtualboxMachine machine = new VirtualboxMachine(this, name, uuid);
                machineMap.Add(uuid, machine);
            }
        }
Exemple #4
0
        public void SaveProperties(VMProperties props)
        {
            lock (driver)
            {
                if (GetCurrentStatus() == MachineStatus.STARTED)
                {
                    Shutdown();
                }

                VirtualboxUtils.VBoxManage("modifyvm " + uuid + " " +
                                           "--memory " + props.MemorySize + " " +
                                           "--vram " + props.VideoMemorySize + " " +
                                           "--cpus " + props.CPUCount);
            }
        }
Exemple #5
0
        public void Start(string snapshotId)
        {
            lock (driver)
            {
                var ms = GetCurrentStatus();
                if (ms == MachineStatus.STARTED)
                {
                    Shutdown();
                }

                snapshotManager.RestoreSnapshot(snapshotId);

                VirtualboxUtils.VBoxManage("startvm " + uuid);
                Thread.Sleep(5000);
            }
        }
Exemple #6
0
        public VMProperties LoadProperties()
        {
            lock (driver)
            {
                var props = new VMProperties();
                IEnumerable <string> propLines;
                if (VirtualboxUtils.VBoxManage("showvminfo " + uuid + " --machinereadable", out propLines))
                {
                    var propMap = propLines.Select(s => s.Split('=')).ToDictionary(parts => parts[0], parts => parts[1]);

                    props.MemorySize      = int.Parse(propMap["memory"]);
                    props.VideoMemorySize = int.Parse(propMap["vram"]);
                    props.CPUCount        = int.Parse(propMap["cpus"]);
                }

                return(props);
            }
        }
Exemple #7
0
        public void LoadSnapshots()
        {
            dict.Clear();

            IEnumerable <string> result;

            if (VirtualboxUtils.VBoxManage("snapshot " + uuid + " list --machinereadable", out result))
            {
                string[] resultArray = result.ToArray();

                for (var i = 0; i < resultArray.Length - 1; i += 2)
                {
                    var      name  = resultArray[i].Split('=')[1].Trim('"');
                    var      suuid = resultArray[i + 1].Split('=')[1].Trim('"');
                    Snapshot ss    = new Snapshot();
                    ss.Id       = suuid;
                    ss.Name     = name;
                    dict[suuid] = ss;
                }
            }
        }
Exemple #8
0
        public MachineStatus GetCurrentStatus()
        {
            lock (driver)
            {
                IEnumerable <string> output;
                bool running = false;

                if (VirtualboxUtils.VBoxManage("list runningvms", out output))
                {
                    running = output.Where(line => line.Contains(uuid)).Any();
                }

                if (running)
                {
                    return(MachineStatus.STARTED);
                }
                else
                {
                    return(MachineStatus.STOPPED);
                }
            }
        }
Exemple #9
0
 public void DeleteSnapshot(string Id)
 {
     VirtualboxUtils.VBoxManage("snapshot " + uuid + " delete " + Id);
     LoadSnapshots();
 }
Exemple #10
0
 public void RestoreSnapshot(string Id)
 {
     VirtualboxUtils.VBoxManage("snapshot " + uuid + " restore " + Id);
 }
Exemple #11
0
 public void CreateMachine(string name, VMProperties properties)
 {
     VirtualboxUtils.VBoxManage("createvm --name " + name + " --register");
 }
Exemple #12
0
 public void Shutdown()
 {
     VirtualboxUtils.VBoxManage(" controlvm " + uuid + " poweroff");
     Thread.Sleep(4000);
 }