Example #1
0
 static void Main(string[] args)
 {
     ValidateLaunch vl = new ValidateLaunch();
     bool result = vl.VerifyLaunchConditions();
     Console.WriteLine(result.ToString());
     Console.ReadLine();
 }
Example #2
0
        static void Main(string[] args)
        {
            ValidateLaunch vl     = new ValidateLaunch();
            bool           result = vl.VerifyLaunchConditions();

            Console.WriteLine(result.ToString());
            Console.ReadLine();
        }
        public void Should_Error_if_Missing_HyperV_Password_Setting()
        {
            string expectedMessage = "Missing Configuration Setting: HYPERV_PWD";
            string oldConfig       = RemoveConfigNode(configPath, "HYPERV_PWD");

            DefaultConfigurationStore store = DefaultConfigurationStore.Current;

            IVMData                hyperV    = new HyperVData();
            ValidateLaunch         canLaunch = new ValidateLaunch(store, hyperV);
            ConfigurationException ex        = Assert.Throws <ConfigurationErrorsException>(() => canLaunch.VerifyLaunchConditions());

            RestoreConfiguration(configPath, oldConfig);
            Assert.Equal(expectedMessage, ex.Message);
        }
        public void Should_Error_if_Missing_Max_VM_Running_Setting()
        {
            string expectedMessage = "Missing Configuration Setting: MAX_NUMBER_OF_VMs_RUNNING";
            string oldConfig       = RemoveConfigNode(configPath, "MAX_NUMBER_OF_VMs_RUNNING");

            DefaultConfigurationStore store = DefaultConfigurationStore.Current;

            IVMData hyperV = new StubIVMData()
            {
                GetNumberOfRunningVMsStringStringString = (string a, string b, string c) => { return(2); }
            };

            ValidateLaunch         canLaunch = new ValidateLaunch(store, hyperV);
            ConfigurationException ex        = Assert.Throws <ConfigurationErrorsException>(() => canLaunch.VerifyLaunchConditions());

            RestoreConfiguration(configPath, oldConfig);
            Assert.Equal(expectedMessage, ex.Message);
        }
Example #5
0
        public static void CreateVirtualMachine(VMRequest vmToProcess, VMFSupportContext db)
        {
            #region Start VM Creation process

            #region Lauch conditions
            // Check for launch conditions
            Console.WriteLine("Checking for launch conditions.");

            // Call the lauunch checker module
            bool           readyToLounch   = false;
            ValidateLaunch launchValidator = new ValidateLaunch();
            readyToLounch = launchValidator.VerifyLaunchConditions();
            Console.WriteLine("Completed with the result [{0}]", readyToLounch.ToString());

            // dump the screen info
            Console.WriteLine("Checking lounch conditions: {0}", "<TBD> Lounch conditions status");

            #endregion

            if (readyToLounch)
            {
                Console.WriteLine(String.Format("Reserving VM request : {0} ({1})", vmToProcess.MachineName, vmToProcess.Id));  vmToProcess.RequestStatus = (int)RequestStatus.Queued; vmToProcess.ProcessLog = "";  var valErrors = db.GetValidationErrors();  if (valErrors.Count() > 0)
                {
                    foreach (var valErr in valErrors)
                    {
                        foreach (var valerrCol in valErr.ValidationErrors)
                        {
                            Console.WriteLine(String.Format("Validation errors on update: {0} - {1}", valerrCol.PropertyName, valerrCol.ErrorMessage));
                        }
                    }
                }
                else
                {
                    db.SaveChanges();
                } Console.WriteLine(String.Format("Calling the StartProcess for VM : {0} ({1})", vmToProcess.MachineName, vmToProcess.Id)); vmToProcess.RequestStatus = (int)RequestStatus.InProgress; vmToProcess.ProcessLog = "Copying and importing base VM."; db.SaveChanges();   string baseVmSourcePath = DefaultConfigurationStore.Current.BaseVmSourcePath; string destinationFolder = vmToProcess.DestinationFolder;  string baseVmConfigFile = DefaultConfigurationStore.Current.BaseVmConfigFilePath.Replace(baseVmSourcePath, destinationFolder); string newVmName = vmToProcess.DisplayName; string baseVmName = DefaultConfigurationStore.Current.BaseVmName; HyperVHelper.CopyAndImportVM(baseVmName, baseVmSourcePath, destinationFolder, baseVmConfigFile, newVmName);  vmToProcess.ProcessLog = "Preloading boot data."; db.SaveChanges();  string driveLetter = DefaultConfigurationStore.Current.TemporaryDriveLetter; string dismPath = DefaultConfigurationStore.Current.DismPath; string vmId = vmToProcess.Id.ToString(); string vmStatusSvcUrl = DefaultConfigurationStore.Current.VmfStatusServiceUrl; string cfgFileName = DefaultConfigurationStore.Current.VmfConfigFile;  HyperVHelper.PreLoadVHDBootData(driveLetter, dismPath, vmToProcess.DisplayName, vmId, vmStatusSvcUrl, cfgFileName);  vmToProcess.ProcessLog = "Starting VM."; db.SaveChanges();  HyperVHelper.StartVM(vmToProcess.DisplayName);  Console.WriteLine(String.Format("Transferred control for MDT for VM: {0} ({1})", vmToProcess.MachineName, vmToProcess.Id));
            }
            else
            {
                Console.WriteLine("No resources available at the moment. Skipping cycle");  Thread.Sleep(DefaultConfigurationStore.Current.WaitTimeBetweenCicles * 1000);
            }
            #endregion
        }
        public void Should_Error_if_ConfigurationStore_is_Null()
        {
            ValidateLaunch         canLaunch;
            IConfigurationStore    configurationStore = null;
            IVMData                hyperV             = new StubIVMData();
            ConfigurationException ex = Assert.Throws <ConfigurationErrorsException>(() => canLaunch = new ValidateLaunch(configurationStore, hyperV));

            Assert.Equal("Missing Configuration Store", ex.Message);
        }