46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using ZA.CoreService.ESBCertificateManager.Models;
|
|
|
|
namespace ZA.CoreService.ESBCertificateManager.Services;
|
|
|
|
/// <summary>
|
|
/// Schlanke Fassade: nur Container-Neustart über MfApi.
|
|
/// </summary>
|
|
public sealed class SonicManagementClient : IDisposable
|
|
{
|
|
private readonly SonicConnection _connection;
|
|
private readonly SonicMfApiExecutor _mfApi;
|
|
|
|
public SonicManagementClient(
|
|
SonicConnection connection)
|
|
{
|
|
_connection = connection;
|
|
_mfApi = new SonicMfApiExecutor(connection);
|
|
}
|
|
|
|
public async Task<(bool Success, string Status, string? Detail)> RestartContainerAsync(
|
|
string containerName,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
(bool ok, string? output, string? error) =
|
|
await _mfApi.RestartAsync(containerName, cancellationToken);
|
|
|
|
if (ok)
|
|
{
|
|
await Task.Delay(
|
|
TimeSpan.FromSeconds(Math.Clamp(_connection.PostRestartDelaySeconds, 0, 120)),
|
|
cancellationToken);
|
|
|
|
return (true, $"Container '{containerName}' neugestartet (MfApi)",
|
|
$"Domain={_connection.DomainName}; URL={_connection.ConnectionUrl}\n{output}");
|
|
}
|
|
|
|
return (false, "Neustart fehlgeschlagen (MfApi)",
|
|
$"Container '{containerName}', Domain '{_connection.DomainName}', URL {_connection.ConnectionUrl}\n" +
|
|
$"Fehler: {error}\n\n{output}");
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|