Beginning to configure SshClient for docker instance
This commit is contained in:
@@ -28,11 +28,11 @@ namespace LeafWeb.Core.Tests.Remote
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Define in machine.config
|
||||
/// </summary>
|
||||
/// <example>host=[url]; username=[un]; password=[pw]</example>
|
||||
private readonly string _piscalConnectionString =
|
||||
/// <summary>
|
||||
/// Define in machine.config
|
||||
/// </summary>
|
||||
/// <example>host=[url]; port=22; username=[un]; password=[pw]</example>
|
||||
private readonly string _piscalConnectionString =
|
||||
ConfigurationManager.ConnectionStrings["PiscalServer"].ConnectionString;
|
||||
|
||||
private PiscalSshClient GetTestClient()
|
||||
|
||||
@@ -16,4 +16,7 @@
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<connectionStrings>
|
||||
<add name="PiscalServer" connectionString="host=192.168.1.4; port=2222; username=launcher; password=launcher" />
|
||||
</connectionStrings>
|
||||
</configuration>
|
||||
@@ -1,3 +1,4 @@
|
||||
//#define DOCKER_PISCAL
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
@@ -13,9 +14,15 @@ namespace LeafWeb.Core.Remote
|
||||
{
|
||||
public class PiscalSshClient : IPiscalClient
|
||||
{
|
||||
private const string BaseDirectory = "./LeafWeb";
|
||||
private const string RemoteScriptPath = BaseDirectory + "/piscal_manager.sh";
|
||||
#if DOCKER_PISCAL
|
||||
private const string RunDirectory = ".";
|
||||
private const string PiscalManagerScriptPath = "/srv/piscal_manager.sh";
|
||||
#else
|
||||
private const string RunDirectory = "./LeafWeb";
|
||||
private const string PiscalManagerScriptPath = RunDirectory + "/piscal_manager.sh";
|
||||
#endif
|
||||
private readonly string _host;
|
||||
private readonly int _port;
|
||||
private readonly PasswordConnectionInfo _connectionInfo;
|
||||
|
||||
private const string StatusComplete = "complete";
|
||||
@@ -34,9 +41,10 @@ namespace LeafWeb.Core.Remote
|
||||
var conn = new DbConnectionStringBuilder {ConnectionString = connectionString};
|
||||
|
||||
_host = conn["host"] as string;
|
||||
_port = int.Parse(conn.ContainsKey("port") ? conn["port"] as string : "22"); // default 22
|
||||
var username = conn["username"] as string;
|
||||
var password = conn["password"] as string;
|
||||
_connectionInfo = new PasswordConnectionInfo(_host, username, password);
|
||||
_connectionInfo = new PasswordConnectionInfo(_host, _port, username, password);
|
||||
|
||||
_connectRetryPolicy = Policy
|
||||
.Handle<SshConnectionException>()
|
||||
@@ -88,15 +96,15 @@ namespace LeafWeb.Core.Remote
|
||||
using (var sshClient = GetSshClient())
|
||||
{
|
||||
Connect(leafInput, sshClient);
|
||||
sshClient.RunCommand($"mkdir {BaseDirectory}/{leafInput.PiscalDirectoryName}");
|
||||
sshClient.RunCommand($"mkdir {BaseDirectory}/{leafInput.PiscalDirectoryName}/input");
|
||||
sshClient.RunCommand($"mkdir {RunDirectory}/{leafInput.PiscalDirectoryName}");
|
||||
sshClient.RunCommand($"mkdir {RunDirectory}/{leafInput.PiscalDirectoryName}/input");
|
||||
Disconnect(leafInput, sshClient);
|
||||
}
|
||||
// copy files
|
||||
using (var scp = GetScpClient())
|
||||
foreach (var file in leafInput.InputFiles)
|
||||
{
|
||||
var inputPath = $"{BaseDirectory}/{leafInput.PiscalDirectoryName}/input/{file.Filename}";
|
||||
var inputPath = $"{RunDirectory}/{leafInput.PiscalDirectoryName}/input/{file.Filename}";
|
||||
using (var stream = new MemoryStream(file.Contents))
|
||||
{
|
||||
_logger.Debug("Copying " + inputPath);
|
||||
@@ -120,7 +128,7 @@ namespace LeafWeb.Core.Remote
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
Connect(leafInput, ssh);
|
||||
var commandText = $"{RemoteScriptPath} -d {leafInput.PiscalDirectoryName} -p {leafInput.PhotosyntheticType} -s";
|
||||
var commandText = $"{PiscalManagerScriptPath} -d {leafInput.PiscalDirectoryName} -p {leafInput.PhotosyntheticType} -s";
|
||||
|
||||
if (leafInput.SuppressStorageCopy)
|
||||
commandText += " -t";
|
||||
@@ -166,7 +174,7 @@ namespace LeafWeb.Core.Remote
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
Connect(leafInput, ssh);
|
||||
var commandText = $"{RemoteScriptPath} -d {leafInput.PiscalDirectoryName}";
|
||||
var commandText = $"{PiscalManagerScriptPath} -d {leafInput.PiscalDirectoryName}";
|
||||
var command = ssh.CreateCommand(commandText);
|
||||
command.Execute();
|
||||
Disconnect(leafInput, ssh);
|
||||
@@ -227,7 +235,7 @@ namespace LeafWeb.Core.Remote
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
Connect(leafInput, ssh);
|
||||
var commandText = $"{RemoteScriptPath} -d {leafInput.PiscalDirectoryName} -k";
|
||||
var commandText = $"{PiscalManagerScriptPath} -d {leafInput.PiscalDirectoryName} -k";
|
||||
var command = ssh.CreateCommand(commandText);
|
||||
command.Execute();
|
||||
Disconnect(leafInput, ssh);
|
||||
@@ -242,7 +250,7 @@ namespace LeafWeb.Core.Remote
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
Connect(leafInput, ssh);
|
||||
var commandText = $"{RemoteScriptPath} -d {leafInput.PiscalDirectoryName} -c";
|
||||
var commandText = $"{PiscalManagerScriptPath} -d {leafInput.PiscalDirectoryName} -c";
|
||||
var command = ssh.CreateCommand(commandText);
|
||||
command.Execute();
|
||||
Disconnect(leafInput, ssh);
|
||||
|
||||
Reference in New Issue
Block a user