ssh
This method execute a command via a SSH connection
on a external system.
Warning
Be aware that this kind of process is heavy. In consequence avoid usage of high frequency request.
For more information see example Execute remote command (SSH).
Usage :
Creates the runner to the given host via the builder
Executes the runner (each request create a new connection to avoid session problems)
Checks the execution status
Deploy certificate
Warning
OnSphere doesn’t support openssh key, use ssh-keygen -t rsa -m PEM
to generate a compatible key
The certificate must be registered as an osp-script module resource and must be at the root of the folder /certs.
Example
{
"resources": [
{
"source": "root/ssh/",
"destination": "/certs"
}
]
}
- ssh.certCmdBuilder(host: string, port: number, username: string, filename: string)
Give an helper to build ssh command execution on server host using port :guilabel`port` authenticated with private key
- Arguments:
host – Ip address or hostname of the server.
port – Port to use for ssh connection
username – Username for authentication on server that is going to execute the script.
filename –
Private key filename for authentication.
Warning
Password protected private key not supported.
- Returns:
Return object
SshCommandBuilder()
.
- ssh.plainTextCmdBuilder(host: string, port: number, username: string, password: string)
Give an helper to build ssh command execution on server host using port :guilabel`port` authenticated with plaintext username/password.
- Arguments:
host – Ip address or hostname of the server.
port – Port to use for ssh connection
username – Username for authentication on server that is going to execute the script.
password
- Returns:
Return object
SshCommandBuilder()
.
- class ssh.CmdExecutionResult()
Result of an ssh remote command execution.
- CmdExecutionResult.getExceptionCode()
Get exit code given by the command
- Returns:
Number that represent exit code of remotely executed command.
- CmdExecutionResult.getStdErr()
Get error result of the command.
- Returns:
Return the error message given by command remotely executed.
- CmdExecutionResult.getStdIn()
DEPRECATED. Get result of the command executed.
- Returns:
String that is returned by the command.
- CmdExecutionResult.getStdOut()
Get result of the command executed (stdout).
- Returns:
String that is returned by the command.
- CmdExecutionResult.isSuccess()
Read success result of the command execution on remote host.
- class ssh.SshCommandBuilder()
Builder to help ssh remote command execution construction.
- SshCommandBuilder.build()
Build the runner that is ready to execute ssh command.
- Returns:
Return an
SshCommandRunner()
ready to execute command built.
- SshCommandBuilder.disableStdErr()
Disable the stdErr input collection, this can be used in case of large commands output (to save memory). Default: false.
- SshCommandBuilder.disableStdIn()
Disable the stdIn input collection, this can be used in case of large commands output (to save memory). Default true
- SshCommandBuilder.enableStrictHostKeyChecking()
Enable host checking for ssh connection. If set to true a change of SSH key on server will raise an error. Beware if you are running with this properties set, a change of SSH key will require a restart of the module.
Default value is false.
- SshCommandBuilder.setConnectionTimeout(timeoutSeconds: number)
The time allowed to establish the SSH connection. Default: 10s
- Arguments:
timeoutSeconds – Time in [s] before ssh session establishment fail.
- SshCommandBuilder.setMaxCommandTime(maxCommandTimeSec: number)
The time allowed for the command execution, after this time the SSH connection is dropped. Default: 10s
- Arguments:
maxCommandTimeSec – Time in [s] allowed for command execution. After that, ssh session will be killed.