public void CleanUp() { if (usedMachines.Count > 0) { foreach (IMachine machine in provider.GetMachines()) { if (usedMachines.Contains(machine.Id)) { // Revert to initial snapshot string ssId = GetInitSnapshotId(machine); if (ssId != null) { machine.Start(ssId); } // Remove the junk from our trunk ssFunc.CleanupSnapshots(); // Shutdown VM machine.Shutdown(); } } usedMachines.Clear(); } }
IMachine GetMachine(string nameOrId) { // Search for machine by id: IEnumerable <IMachine> machines = provider.GetMachines().Where(m => m.Id == nameOrId); if (machines.Any()) { return(machines.First()); } machines = provider.GetMachines().Where(m => m.Name == nameOrId); if (machines.Any()) { return(machines.First()); } throw new Exception("Unable to find machine for string: " + nameOrId); }