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); }
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")); } }
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); } }
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); } }
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); } }
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); } }
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; } } }
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); } } }
public void DeleteSnapshot(string Id) { VirtualboxUtils.VBoxManage("snapshot " + uuid + " delete " + Id); LoadSnapshots(); }
public void RestoreSnapshot(string Id) { VirtualboxUtils.VBoxManage("snapshot " + uuid + " restore " + Id); }
public void CreateMachine(string name, VMProperties properties) { VirtualboxUtils.VBoxManage("createvm --name " + name + " --register"); }
public void Shutdown() { VirtualboxUtils.VBoxManage(" controlvm " + uuid + " poweroff"); Thread.Sleep(4000); }