public void CreateVirtualMachine()
        {
            // Arrange
            var imageLocation = @"c:/vm.vmx";
            var mHost = new Mock<IVirtualHost>();
            var mVM = new Mock<IVirtualMachine>();
            var service = new CreateVirtualMachineService(mVM.Object);
            mHost.Setup(host => host.ConnectToVMWareServer("vmat.reshall.rose-hulman.edu", "Nathan", "Vmat1234"));
            mHost.Setup(host => host.Open(imageLocation)).Returns(mVM.Object);
            mVM.Setup(vm => vm.WaitForToolsInGuest());
            mVM.Setup(vm => vm.LoginInGuest("Administrator", "password"));

            // Act
            service.CreateVM();

            // Assert
            mHost.VerifyAll();
            mVM.VerifyAll();
        }
示例#2
0
        public static void CreatePendingVMs()
        {
            var ls = dataDB.VirtualMachines.Where(v => v.Status == VirtualMachine.PENDING);
            foreach (Models.VirtualMachine pendingVM in ls)
            {
                new SchedulerInfo("Beginning creation of machine " + pendingVM.MachineName).LogElmah(); //todo Hostname field is empty
                var service = new CreateVirtualMachineService(pendingVM);
                Models.VirtualMachine regVM = null;
                try
                {
                    regVM = service.CreateVM();
                }
                catch (Exception ex)
                {
                    new SchedulerInfo("Uncaught VM creation error",ex).LogElmah();
                }

                //if that excepts, this should still continue
                try
                {
                    //done: now that every VM is the same type, should we just change the flag and save?
                    pendingVM.Status = VirtualMachine.STOPPED;
                    //dataDB.VirtualMachines.Remove(pendingVM); //TODO: do we just want to remove this before starting to create the VM?
                    //dataDB.VirtualMachines.Add(regVM);
                }
                catch (Exception ex)
                {
                    new SchedulerInfo("Error updating database post-VM creation, may need manual modification", ex).LogElmah();
                }
                try
                {
                    dataDB.SaveChanges();
                }
                catch (Exception ex)
                {
                    new SchedulerInfo("Error saving database post-VM creation, may need manual modification", ex).LogElmah();
                }
            }
            new SchedulerInfo("All creation completed").LogElmah();
        }