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