Class LinuxSshProxy
Uses a SSH/SCP connection to provide access to Linux machines to access
files, run commands, etc.
note
IMPORTANT: We use this class to manage Ubuntu Linux machines. This
will likely work for Debian and other Debian based distros but other distros
like Alpine and Red Hat may have problems or may not work at all.
Inheritance
LinuxSshProxy
Assembly: Neon.SSH.dll
Syntax
public class LinuxSshProxy
Constructors
LinuxSshProxy(string, IPAddress, SshCredentials, int, TextWriter)
Declaration
public LinuxSshProxy(string name, IPAddress address, SshCredentials credentials, int port = 22, TextWriter logWriter = null)
Parameters
Type |
Name |
Description |
string |
name |
The display name for the remote machine.
|
IPAddress |
address |
The private cluster IP address for the remote machine.
|
SshCredentials |
credentials |
The credentials to be used for establishing SSH connections.
|
int |
port |
Optionally overrides the standard SSH port (22).
|
TextWriter |
logWriter |
The optional TextWriter where operation logs will be written.
|
Exceptions
Fields
SshProxyInitPath
Path to the file whose existence indicates that the proxy has already
configured things like disabling SUDO password prompts.
Declaration
public const string SshProxyInitPath = "/etc/neon-sshproxy-init"
Field Value
credentials
Declaration
protected SshCredentials credentials
Field Value
logWriter
Declaration
protected TextWriter logWriter
Field Value
Properties
Address
Declaration
public IPAddress Address { get; set; }
Property Value
ConnectTimeout
Declaration
public TimeSpan ConnectTimeout { get; set; }
Property Value
DefaultRunOptions
Declaration
public RunOptions DefaultRunOptions { get; set; }
Property Value
DownloadFolderPath
Declaration
public string DownloadFolderPath { get; }
Property Value
FileTimeout
Declaration
public TimeSpan FileTimeout { get; set; }
Property Value
HomeFolderPath
Declaration
public string HomeFolderPath { get; }
Property Value
IsConfiguring
Declaration
public bool IsConfiguring { get; set; }
Property Value
IsFaulted
Declaration
public bool IsFaulted { get; set; }
Property Value
IsInvolved
Declaration
public bool IsInvolved { get; set; }
Property Value
IsReady
Declaration
public bool IsReady { get; set; }
Property Value
KernelRelease
Declaration
public string KernelRelease { get; }
Property Value
KernelVersion
Declaration
public Version KernelVersion { get; }
Property Value
Name
Declaration
public string Name { get; }
Property Value
OsName
Declaration
public string OsName { get; }
Property Value
OsVersion
Declaration
public Version OsVersion { get; }
Property Value
RemotePath
Declaration
public string RemotePath { get; set; }
Property Value
RetryCount
Declaration
public int RetryCount { get; set; }
Property Value
SshPort
Declaration
public int SshPort { get; set; }
Property Value
Status
Declaration
public string Status { get; set; }
Property Value
UploadFolderPath
Declaration
public string UploadFolderPath { get; }
Property Value
Username
Returns the username used to log into the remote node.
Declaration
public string Username { get; }
Property Value
Methods
Clean(bool, bool)
Cleans a node by removing unnecessary package manager metadata, cached DHCP information, journald
logs... and then fills unreferenced file system blocks with zeros so the disk image will or
trims the file system (when possible) so the image will compress better.
Declaration
public void Clean(bool trim = false, bool zero = false)
Parameters
Type |
Name |
Description |
bool |
trim |
Optionally trims the file system.
|
bool |
zero |
Optionally zeros unreferenced file system blocks.
|
Clone()
Returns a clone of the SSH proxy. This can be useful for situations where you
need to be able to perform multiple SSH/SCP operations against the same
machine in parallel.
note
This does not clone any attached log writer.
Declaration
public LinuxSshProxy Clone()
Returns
CloneScpClient()
Declaration
public ScpClient CloneScpClient()
Returns
Type |
Description |
ScpClient |
|
CloneSshClient()
Declaration
public SshClient CloneSshClient()
Returns
Type |
Description |
SshClient |
|
CloneTo(LinuxSshProxy)
Used by derived classes to copy the base class state to a new
instance as well as configure the new connection's SSH and SCP
clients.
Declaration
protected void CloneTo(LinuxSshProxy target)
Parameters
Connect(TimeSpan)
Declaration
public void Connect(TimeSpan timeout = default)
Parameters
CreateShell()
Declaration
public ShellStream CreateShell()
Returns
Type |
Description |
ShellStream |
|
CreateSudoShell()
Declaration
public ShellStream CreateSudoShell()
Returns
Type |
Description |
ShellStream |
|
DeleteDirectory(string)
Declaration
public void DeleteDirectory(string path)
Parameters
Type |
Name |
Description |
string |
path |
|
DeleteFile(string)
Declaration
public void DeleteFile(string path)
Parameters
Type |
Name |
Description |
string |
path |
|
DirectoryExists(string)
Declaration
public bool DirectoryExists(string path)
Parameters
Type |
Name |
Description |
string |
path |
|
Returns
DisableSudoPrompt(string)
Declaration
public void DisableSudoPrompt(string password)
Parameters
Type |
Name |
Description |
string |
password |
|
Disconnect()
Declaration
Dispose()
Releases all associated resources (e.g. any open remote machine connections).
Declaration
Dispose(bool)
Releases all associated resources (e.g. any open remote machine connections).
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type |
Name |
Description |
bool |
disposing |
Pass true if we're disposing, false if we're finalizing.
|
Download(string, Stream)
Declaration
public void Download(string source, Stream output)
Parameters
Download(string, string)
Declaration
public void Download(string source, string target)
Parameters
DownloadBytes(string)
Declaration
public byte[] DownloadBytes(string source)
Parameters
Type |
Name |
Description |
string |
source |
|
Returns
DownloadText(string)
Declaration
public string DownloadText(string source)
Parameters
Type |
Name |
Description |
string |
source |
|
Returns
Fault(string)
Declaration
public void Fault(string message = null)
Parameters
Type |
Name |
Description |
string |
message |
|
FileExists(string)
Declaration
public bool FileExists(string path)
Parameters
Type |
Name |
Description |
string |
path |
|
Returns
~LinuxSshProxy()
Declaration
protected ~LinuxSshProxy()
GetAuthenticationMethod(SshCredentials)
Extracts the authentication method from SSH credentials.
Declaration
protected AuthenticationMethod GetAuthenticationMethod(SshCredentials credentials)
Parameters
Returns
Type |
Description |
AuthenticationMethod |
The AuthenticationMethod.
|
GetNeonInitStatus()
Declaration
public bool GetNeonInitStatus()
Returns
GetNetworkInterface(IPAddress)
Declaration
public string GetNetworkInterface(IPAddress address)
Parameters
Returns
GetTimeUtc()
Declaration
public DateTime GetTimeUtc()
Returns
KubeCtlApply(StringBuilder, RunOptions)
Declaration
public CommandResponse KubeCtlApply(StringBuilder sbYaml, RunOptions runOptions = RunOptions.Defaults)
Parameters
Returns
KubectlApply(string, RunOptions)
Declaration
public CommandResponse KubectlApply(string yaml, RunOptions runOptions = RunOptions.Defaults)
Parameters
Returns
ListDisks(bool)
Declaration
public Dictionary<string, LinuxDiskInfo> ListDisks(bool fixedDisksOnly = true)
Parameters
Type |
Name |
Description |
bool |
fixedDisksOnly |
|
Returns
ListPartitionedDisks()
Declaration
public List<string> ListPartitionedDisks()
Returns
ListUnpartitionedDisks()
Declaration
public List<string> ListUnpartitionedDisks()
Returns
Log(string)
Declaration
public virtual void Log(string text)
Parameters
Type |
Name |
Description |
string |
text |
|
LogException(Exception)
Declaration
public void LogException(Exception e)
Parameters
LogException(string, Exception)
Declaration
public void LogException(string message, Exception e)
Parameters
LogFlush()
Declaration
public virtual void LogFlush()
LogLine(string)
Declaration
public virtual void LogLine(string text)
Parameters
Type |
Name |
Description |
string |
text |
|
PatchLinux()
Patches Linux on the node applying all outstanding security patches but without
upgrading the Linux distribution.
Declaration
Returns
Type |
Description |
bool |
true when a reboot is required.
|
Reboot(bool)
Declaration
public void Reboot(bool wait = true)
Parameters
Type |
Name |
Description |
bool |
wait |
|
RemoveFile(string)
Declaration
public void RemoveFile(string target)
Parameters
Type |
Name |
Description |
string |
target |
|
RunCommand(CommandBundle, RunOptions)
Declaration
public CommandResponse RunCommand(CommandBundle bundle, RunOptions runOptions = RunOptions.Defaults)
Parameters
Returns
RunCommand(string, RunOptions, params object[])
Declaration
public CommandResponse RunCommand(string command, RunOptions runOptions, params object[] args)
Parameters
Returns
RunCommand(string, params object[])
Declaration
public CommandResponse RunCommand(string command, params object[] args)
Parameters
Returns
SetNeonInitStatus(bool, bool)
Declaration
public void SetNeonInitStatus(bool initialized, bool keepNetworkSettings = false)
Parameters
Type |
Name |
Description |
bool |
initialized |
|
bool |
keepNetworkSettings |
|
SetPassword(string, string)
Declaration
public void SetPassword(string username, string password)
Parameters
Type |
Name |
Description |
string |
username |
The username.
|
string |
password |
The new password.
|
Shutdown()
Declaration
SudoCommand(CommandBundle, RunOptions)
Declaration
public CommandResponse SudoCommand(CommandBundle bundle, RunOptions runOptions = RunOptions.Defaults)
Parameters
Returns
SudoCommand(string, RunOptions, params object[])
Declaration
public CommandResponse SudoCommand(string command, RunOptions runOptions, params object[] args)
Parameters
Returns
SudoCommand(string, params object[])
Declaration
public CommandResponse SudoCommand(string command, params object[] args)
Parameters
Returns
SudoCommandAsUser(string, string, RunOptions, params object[])
Declaration
public CommandResponse SudoCommandAsUser(string user, string command, RunOptions runOptions, params object[] args)
Parameters
Returns
SudoCommandAsUser(string, string, params object[])
Declaration
public CommandResponse SudoCommandAsUser(string user, string command, params object[] args)
Parameters
Returns
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type |
Description |
string |
A string that represents the current object.
|
Overrides
UpdateCredentials(SshCredentials)
Declaration
public void UpdateCredentials(SshCredentials newCredentials)
Parameters
UpdateRootCertificates()
Checks for and installs any new root certificates.
Declaration
public void UpdateRootCertificates()
UpgradeLinuxDistribution()
Upgrades the Linux distribution on the node.
Declaration
public bool UpgradeLinuxDistribution()
Returns
Type |
Description |
bool |
true when a reboot is required.
|
Upload(string, Stream, string, string, bool)
Declaration
public void Upload(string target, Stream input, string permissions = null, string owner = null, bool userPermissions = false)
Parameters
UploadBytes(string, byte[])
Declaration
public void UploadBytes(string target, byte[] bytes)
Parameters
UploadText(string, Stream, int, Encoding, Encoding, string, string)
Declaration
public void UploadText(string target, Stream textStream, int tabStop = 0, Encoding inputEncoding = null, Encoding outputEncoding = null, string permissions = null, string owner = null)
Parameters
UploadText(string, string, int, Encoding, string, string)
Declaration
public void UploadText(string target, string text, int tabStop = 0, Encoding outputEncoding = null, string permissions = null, string owner = null)
Parameters
UploadText(string, StringBuilder, int, Encoding, string, string)
Declaration
public void UploadText(string target, StringBuilder text, int tabStop = 0, Encoding outputEncoding = null, string permissions = null, string owner = null)
Parameters
WaitForBoot(TimeSpan?)
Declaration
public void WaitForBoot(TimeSpan? timeout = null)
Parameters