Ejemplo n.º 1
0
        private async Task <SwarmInformation> GetSwarmInformationAsync(IDockerClients clients)
        {
            var ping = await clients.SystemClient.PingAsync();

            var diskUsage = await clients.SystemClient.GetDiskUsageAsync();

            var version = await clients.SystemClient.GetSystemVersionAsync();

            var containers = await clients.ContainerClient.GetContainersAsync();

            var tasks = await clients.TaskClient.GetTasksAsync();

            var nodes = await clients.NodeClient.GetNodesAsync();

            var swarmServices = await clients.ServiceClient.GetServicesAsync();

            var swarm = new SwarmInformation
            {
                DiskUsage       = diskUsage,
                LocalContainers = containers,
                Ping            = ping,
                SwarmNodes      = nodes,
                SwarmServices   = swarmServices,
                SwarmTasks      = tasks,
                SystemVersion   = version
            };

            return(swarm);
        }
Ejemplo n.º 2
0
        private async Task ProcessTarget(Target target, SwarmInformation swarm)
        {
            using (this._logger.BeginScope("{@target}", target))
            {
                try
                {
                    var    text        = Guid.NewGuid().ToString();
                    string oldTemplate = null;

                    if (!string.IsNullOrWhiteSpace(target.TemplateSource))
                    {
                        this._logger.LogTrace("Template source set, rendering template");
                        text = await this._razorRunner.Render(target.TemplateSource, swarm);

                        oldTemplate = this._previousTemplates.GetOrAdd(target, string.Empty);
                        this._logger.LogTrace("Resulting text: {text}", text);

                        if (oldTemplate != text)
                        {
                            this._logger.LogInformation("Rendered content changed, {@newContent}", text);

                            if (!string.IsNullOrWhiteSpace(target.Destination))
                            {
                                this._logger.LogInformation("Updating destination");
                                await File.WriteAllTextAsync(target.Destination, text);
                            }
                            else
                            {
                                this._logger.LogTrace("Destination file target blank, not writing");
                            }
                            this._previousTemplates[target] = text;
                        }
                        else
                        {
                            this._logger.LogInformation("Rendered content did not change");
                        }
                    }

                    if (oldTemplate != text &&
                        target.ExecuteOnChange != null &&
                        target.ExecuteOnChange.Length > 0)
                    {
                        this._logger.LogTrace("Execute on change has options, executing options.");
                        foreach (var execute in target.ExecuteOnChange)
                        {
                            this.Execute(execute);
                        }
                    }
                }
                catch (Exception exception)
                {
                    this._logger.LogError(exception, "Unable to process target");
                }
            }
        }