public void PowerOnTest() { VirtualMachineRepository vmr = new VirtualMachineRepository(); VirtualMachine vm = vmr.GetAllRegisteredVirtualMachines().GetEnumerator().Current; // TODO: Initialize to an appropriate value RegisteredVirtualMachineService target = new RegisteredVirtualMachineService(vm); // TODO: Initialize to an appropriate value if (target.GetStatus() == VirtualMachine.STOPPED) { target.PowerOn(); Assert.IsTrue(target.GetStatus() == VirtualMachine.POWERINGON || target.GetStatus() == VirtualMachine.RUNNING); } else Assert.Inconclusive(); }
public void PauseTest() { VirtualMachineRepository vmr = new VirtualMachineRepository(); VirtualMachine vm = vmr.GetAllRegisteredVirtualMachines().GetEnumerator().Current; // TODO: Initialize to an appropriate value RegisteredVirtualMachineService target = new RegisteredVirtualMachineService(vm); // TODO: Initialize to an appropriate value if (target.GetStatus() == VirtualMachine.RUNNING) { target.Pause(); Assert.Equals(target.GetStatus(), VirtualMachine.PAUSED); } else Assert.Inconclusive(); }
private void InitializeDataContext() { var registeredImages = RegisteredVirtualMachineService.GetRegisteredVMImagePaths(); foreach (var image in registeredImages) { int startIndex = image.IndexOf("] ") + "] ".Length; int length = image.IndexOf('/', startIndex) - startIndex; string projectName = image.Substring(startIndex, length); var service = new RegisteredVirtualMachineService(image); if (!dataDB.Projects.Select(p => p.ProjectName).Contains(projectName)) { var project = new Project(projectName); dataDB.Projects.Add(project); dataDB.SaveChanges(); } startIndex = image.LastIndexOf('/') + 1; length = image.LastIndexOf('.') - startIndex; string machineName = image.Substring(startIndex, length); VirtualMachine vm; try { vm = dataDB.VirtualMachines.Single(v => v.MachineName == machineName); } catch (Exception) { vm = new VirtualMachine(); dataDB.VirtualMachines.Add(vm); } //PowerOn(vm, service); vm.MachineName = machineName; vm.ImagePathName = image; vm.Status = service.GetStatus(); //TODO reset //vm.Hostname = "test-hostname"; vm.Hostname = service.GetHostname(); vm.IP = service.GetIP(); vm.Project = dataDB.Projects.Single(p => p.ProjectName == projectName); dataDB.SaveChanges(); } }
public void ReinitializeAllRegisteredVirtualMachines() { var imagePathNames = RegisteredVirtualMachineService.GetRegisteredVMImagePaths(); foreach (var image in imagePathNames) { int startIndex = image.IndexOf("] ") + "] ".Length; int length = image.IndexOf('/', startIndex) - startIndex; string projectName = image.Substring(startIndex, length); var service = new RegisteredVirtualMachineService(image); if (!dataDB.Projects.Select(p => p.ProjectName).Contains(projectName)) { var project = new Project(projectName); dataDB.Projects.Add(project); dataDB.SaveChanges(); } startIndex = image.LastIndexOf('/') + 1; length = image.LastIndexOf('.') - startIndex; string machineName = image.Substring(startIndex, length); if (!dataDB.VirtualMachines.Select(v => v.MachineName).Contains(machineName)) { VirtualMachine vm = new VirtualMachine(); vm.MachineName = machineName; vm.ImagePathName = image; vm.Status = service.GetStatus(); vm.Hostname = service.GetHostname(); vm.IP = service.GetIP(); vm.Project = dataDB.Projects.Single(p => p.ProjectName == projectName); dataDB.VirtualMachines.Add(vm); dataDB.SaveChanges(); } } }
public ICollection<Project> GetAllProjects() { foreach (var vm in dataDB.VirtualMachines.Where(v => v.Status != VirtualMachine.ARCHIVED && v.Status != VirtualMachine.PENDING)) { RegisteredVirtualMachineService service = null; try { service = new RegisteredVirtualMachineService(vm.ImagePathName); } catch (Vestris.VMWareLib.VMWareException) { dataDB.VirtualMachines.Remove(vm); continue; } vm.Status = service.GetStatus(); if (vm.IP == null && vm.Status == VirtualMachine.RUNNING) vm.IP = service.GetIP(); if (vm.Hostname == null && vm.Status == VirtualMachine.RUNNING) vm.Hostname = service.GetHostname(); } dataDB.SaveChanges(); return dataDB.Projects.ToList(); }