SSH

Availability table

Controller availability

Module

Available

module.scripts

Supported feature

module.keycloak

Supported feature

ssh controller

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.

Usage :

  1. Creates the runner to the given host via the builder

  2. Executes the runner (each request create a new connection to avoid session problems)

  3. 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

Example

{
    "resources": [
        {
            "source": "root/ssh/",
            "destination": "certs"
        }
    ]
}

The certificate must be registered as an osp-script module resource and must be at the root of the folder /certs.

ssh.certCmdBuilder(host: string, port: number, username: string, filename: string)

Give an helper to build ssh command execution on server host using port 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 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().

CmdExecutionResult

class ssh.CmdExecutionResult()

Result of an ssh remote command execution.

CmdExecutionResult.returnCode

The return code of the executed command on the remote server.

The type of the field is number.

CmdExecutionResult.stdOut

The standard output of the executed command on the remote server.

The type of the field is string.

CmdExecutionResult.stdErr

The error output of the executed command on the remote server.

The type of the field is string.

CmdExecutionResult.exceptionCode

The exception code return during the execution of the command.

  • 0 : NO_EXCEPTION

  • -1 : FAIL_TO_CONNECT

  • -2 : FAIL_TO_EXECUTE_CMD

  • -3 : MAX_COMMAND_EXECUTION_TIME_REACHED

The type of the field is number.

CmdExecutionResult.getExceptionCode()

Get exit code given by the command

Deprecated since version 2.1.0: Use CmdExecutionResult.exceptionCode instead.

Returns:

Number that represent exit code of remotely executed command.

CmdExecutionResult.getStdErr()

Get error result of the command.

Deprecated since version 2.1.0: Use CmdExecutionResult.stdErr instead.

Returns:

Return the error message given by command remotely executed.

CmdExecutionResult.getStdIn()

Get result of the command executed.

Deprecated since version 1.4.0: Use CmdExecutionResult.stdOut instead.

Returns:

String that is returned by the command.

CmdExecutionResult.getStdOut()

Get result of the command executed (stdout).

Deprecated since version 2.1.0: Use CmdExecutionResult.stdOut instead.

Returns:

String that is returned by the command.

CmdExecutionResult.isSuccess()

Read success result of the command execution on remote host.

Deprecated since version 2.1.0: Use CmdExecutionResult.returnCode instead.

SshCommandBuilder

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.

SshCommandRunner

class ssh.SshCommandRunner()

Runner for ssh remote command execution.

SshCommandRunner.run(arguments: object[])

Execute command build.

Arguments:
  • arguments – List of arguments string that will be passed to ssh commands.