Example #1
0
        public IEnumerable <ConfigurationResult> ApplyRunList(IEnumerable <ConfigItem> runlist)
        {
            var returnData = new List <ConfigurationResult>();

            foreach (var item in runlist)
            {
                _console.Information("========================================================================");
                _console.Information(" Name: {name}", item.Name);
                _console.Information(" Resource: {resource}", item.Resource);
                _console.Information("========================================================================");
                var currentResult = new ConfigurationResult
                {
                    Name        = item.Name,
                    Resource    = item.Resource,
                    State       = ResourceState.NotConfigured,
                    RanResource = false
                };

                foreach (var dyn in item.Dynamics)
                {
                    dyn(_dataStore, item);
                }

                returnData.Add(currentResult);

                var driver = _pluginManager.GetResource(item.Resource);
                driver.GetData(item);
                var testResult = driver.Test();

                _console.Information("Current Status: {state}", testResult);

                currentResult.State = testResult;

                if (testResult == ResourceState.NeedReboot)
                {
                    currentResult.State = ResourceState.NeedReboot;
                    return(returnData);
                }

                if (testResult == ResourceState.NotConfigured)
                {
                    _console.Information("Running Apply to update configuration...");
                    var result = driver.Apply();
                    currentResult.RanResource = true;

                    if (result == ResourceState.NeedReboot)
                    {
                        _console.Information("Reboot Required");
                        currentResult.State = ResourceState.NeedReboot;
                        return(returnData);
                    }

                    _console.Information("Finished Apply changes...Rechecking...");
                    var secondTest = driver.Test();

                    if (secondTest != ResourceState.Configured)
                    {
                        _console.Error("Configuration Check failed...exiting...");
                        currentResult.State = ResourceState.NotConfigured;
                        return(returnData);
                    }

                    _console.Information("Configuration Verified.");
                }
            }

            return(returnData);
        }