Brooklyn

brooklyn.util.internal.ssh
[Java] Interface SshTool


public interface SshTool

Defines the methods available on the various different implementations of SSH, and configuration options which are also generally available.

The config keys in this class can be supplied (or their string equivalents, where the flags/props take Map) to influence configuration, either for the tool/session itself or for individual commands.

To specify some of these properties on a global basis, use the variants of the keys here contained in ConfigKeys (which are generally {

value:
#BROOKLYN_CONFIG_KEY_PREFIX} prefixed to the names of keys here).


Field Summary
static java.lang.String BROOKLYN_CONFIG_KEY_PREFIX

Intermediate config keys for Brooklyn are defined where they are used, e.g. in SshMachineLocation // * and have this prefix pre-prended to the config keys in this class.

static ConfigKey PROP_ALLOCATE_PTY

static ConfigKey PROP_CONNECT_TIMEOUT

static ConfigKey PROP_DIRECT_HEADER

static ConfigKey PROP_ERR_STREAM

static ConfigKey PROP_HOST

static ConfigKey PROP_KEY_FILES

@deprecated since 0.4; use PROP_PRIVATE_KEY_FILE; if this contains more than one element then it will fail.

static ConfigKey PROP_LAST_ACCESS_DATE

static ConfigKey PROP_LAST_MODIFICATION_DATE

static ConfigKey PROP_LOCAL_TEMP_DIR

static ConfigKey PROP_OUT_STREAM

static ConfigKey PROP_PASSWORD

static ConfigKey PROP_PERMISSIONS

static ConfigKey PROP_PORT

static ConfigKey PROP_PRIVATE_KEY

@deprecated since 0.4; use PROP_PRIVATE_KEY_DATA instead

static ConfigKey PROP_PRIVATE_KEY_DATA

static ConfigKey PROP_PRIVATE_KEY_FILE

static ConfigKey PROP_PRIVATE_KEY_PASSPHRASE

static ConfigKey PROP_SCRIPT_DIR

static ConfigKey PROP_SCRIPT_HEADER

static ConfigKey PROP_SEPARATOR

static ConfigKey PROP_SESSION_TIMEOUT

static ConfigKey PROP_SSH_RETRY_DELAY

static ConfigKey PROP_SSH_TRIES

static ConfigKey PROP_SSH_TRIES_TIMEOUT

static ConfigKey PROP_STRICT_HOST_KEY_CHECKING

static ConfigKey PROP_TOOL_CLASS

static ConfigKey PROP_USER

 
Method Summary
void connect()

@throws SshException

void connect(int maxAttempts)

@param maxAttempts

int copyFromServer(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.io.File local)

Copies the file to the server at the given path.

int copyToServer(java.util.Map props, java.io.File localFile, java.lang.String pathAndFileOnRemoteServer)

Copies the file to the server at the given path.

int copyToServer(java.util.Map props, java.io.InputStream contents, java.lang.String pathAndFileOnRemoteServer)

Closes the given input stream before returning.

int copyToServer(java.util.Map props, byte[] contents, java.lang.String pathAndFileOnRemoteServer)

@see copyToServer(Map, File, String)

int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.io.InputStream input, long size)

@deprecated since 0.5; See copyToServer(Map, InputStream, String)

int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.lang.String contents)

@deprecated since 0.5; See copyToServer(Map, byte[], String)

int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, byte[] contents)

@deprecated since 0.5; See copyToServer(Map, byte[], String)

void disconnect()

int execCommands(java.util.Map properties, java.util.List commands, java.util.Map env)

Executes the set of commands using ssh exec.

int execCommands(java.util.Map properties, java.util.List commands)

@see execuCommands(Map, List, Map)

int execScript(java.util.Map props, java.util.List commands, java.util.Map env)

Executes the set of commands in a shell script.

int execScript(java.util.Map props, java.util.List commands)

@see execScript(Map, List, Map)

int execShell(java.util.Map props, java.util.List commands)

@deprecated since 0.4; use execScript(...)

int execShell(java.util.Map props, java.util.List commands, java.util.Map env)

@deprecated since 0.4; execScript(...)

boolean isConnected()

int transferFileFrom(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.lang.String pathAndFileOnLocalServer)

@deprecated since 0.5; See copyFromServer(Map, InputStream, String)

int transferFileTo(java.util.Map props, java.io.InputStream input, java.lang.String pathAndFileOnRemoteServer)

@deprecated since 0.5; See copyToServer(Map, InputStream, String)

 

Field Detail

BROOKLYN_CONFIG_KEY_PREFIX

public static final java.lang.String BROOKLYN_CONFIG_KEY_PREFIX
Intermediate config keys for Brooklyn are defined where they are used, e.g. in SshMachineLocation // * and have this prefix pre-prended to the config keys in this class.


PROP_ALLOCATE_PTY

public static final ConfigKey PROP_ALLOCATE_PTY


PROP_CONNECT_TIMEOUT

public static final ConfigKey PROP_CONNECT_TIMEOUT


PROP_DIRECT_HEADER

public static final ConfigKey PROP_DIRECT_HEADER


PROP_ERR_STREAM

public static final ConfigKey PROP_ERR_STREAM


PROP_HOST

public static final ConfigKey PROP_HOST


PROP_KEY_FILES

public static final ConfigKey PROP_KEY_FILES
deprecated:
since 0.4; use PROP_PRIVATE_KEY_FILE; if this contains more than one element then it will fail.


PROP_LAST_ACCESS_DATE

public static final ConfigKey PROP_LAST_ACCESS_DATE


PROP_LAST_MODIFICATION_DATE

public static final ConfigKey PROP_LAST_MODIFICATION_DATE


PROP_LOCAL_TEMP_DIR

public static final ConfigKey PROP_LOCAL_TEMP_DIR


PROP_OUT_STREAM

public static final ConfigKey PROP_OUT_STREAM


PROP_PASSWORD

public static final ConfigKey PROP_PASSWORD


PROP_PERMISSIONS

public static final ConfigKey PROP_PERMISSIONS


PROP_PORT

public static final ConfigKey PROP_PORT


PROP_PRIVATE_KEY

@Deprecated
public static final ConfigKey PROP_PRIVATE_KEY
deprecated:
since 0.4; use PROP_PRIVATE_KEY_DATA instead


PROP_PRIVATE_KEY_DATA

public static final ConfigKey PROP_PRIVATE_KEY_DATA


PROP_PRIVATE_KEY_FILE

public static final ConfigKey PROP_PRIVATE_KEY_FILE


PROP_PRIVATE_KEY_PASSPHRASE

public static final ConfigKey PROP_PRIVATE_KEY_PASSPHRASE


PROP_SCRIPT_DIR

public static final ConfigKey PROP_SCRIPT_DIR


PROP_SCRIPT_HEADER

public static final ConfigKey PROP_SCRIPT_HEADER


PROP_SEPARATOR

public static final ConfigKey PROP_SEPARATOR


PROP_SESSION_TIMEOUT

public static final ConfigKey PROP_SESSION_TIMEOUT


PROP_SSH_RETRY_DELAY

public static final ConfigKey PROP_SSH_RETRY_DELAY


PROP_SSH_TRIES

public static final ConfigKey PROP_SSH_TRIES


PROP_SSH_TRIES_TIMEOUT

public static final ConfigKey PROP_SSH_TRIES_TIMEOUT


PROP_STRICT_HOST_KEY_CHECKING

public static final ConfigKey PROP_STRICT_HOST_KEY_CHECKING


PROP_TOOL_CLASS

public static final ConfigKey PROP_TOOL_CLASS


PROP_USER

public static final ConfigKey PROP_USER


 
Method Detail

connect

public void connect()
throws:
SshException


connect

public void connect(int maxAttempts)
throws:
SshException
Parameters:
maxAttempts


copyFromServer

public int copyFromServer(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.io.File local)
Copies the file to the server at the given path. If path is null, empty, '.', '..', or ends with '/' then file name is used.

Optional properties are:

Returns:
exit code (not supported by all SshTool implementations, sometimes just returning 0)


copyToServer

public int copyToServer(java.util.Map props, java.io.File localFile, java.lang.String pathAndFileOnRemoteServer)
Copies the file to the server at the given path. If path is null, empty, '.', '..', or ends with '/' then file name is used.

The file will not preserve the permission of last _access_ date. Optional properties are:

Returns:
exit code (not supported by all SshTool implementations, sometimes just returning 0)


copyToServer

public int copyToServer(java.util.Map props, java.io.InputStream contents, java.lang.String pathAndFileOnRemoteServer)
Closes the given input stream before returning. Consider using KnownSizeInputStream for efficiency when the size of the stream is known.
See Also:
copyToServer(java.util.Map, java.io.File, java.lang.String)


copyToServer

public int copyToServer(java.util.Map props, byte[] contents, java.lang.String pathAndFileOnRemoteServer)
See Also:
copyToServer(java.util.Map, java.io.File, java.lang.String)


createFile

public int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.io.InputStream input, long size)
deprecated:
since 0.5; See copyToServer(Map, InputStream, String)


createFile

public int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.lang.String contents)
deprecated:
since 0.5; See copyToServer(Map, byte[], String)


createFile

public int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, byte[] contents)
deprecated:
since 0.5; See copyToServer(Map, byte[], String)


disconnect

public void disconnect()


execCommands

public int execCommands(java.util.Map properties, java.util.List commands, java.util.Map env)
Executes the set of commands using ssh exec. This is generally more efficient than shell, but is not suitable if you need env values which are only set on a fully-fledged shell. Optional properties are:
throws:
SshException If failed to connect
Returns:
exit status of commands


execCommands

public int execCommands(java.util.Map properties, java.util.List commands)
See Also:
execuCommands(java.util.Map, java.util.List, java.util.Map)


execScript

public int execScript(java.util.Map props, java.util.List commands, java.util.Map env)
Executes the set of commands in a shell script. Blocks until completion.

Optional properties are:

throws:
SshException If failed to connect
Returns:
exit status of script


execScript

public int execScript(java.util.Map props, java.util.List commands)
See Also:
execScript(java.util.Map, java.util.List, java.util.Map)


execShell

public int execShell(java.util.Map props, java.util.List commands)
deprecated:
since 0.4; use execScript(...)


execShell

public int execShell(java.util.Map props, java.util.List commands, java.util.Map env)
deprecated:
since 0.4; execScript(...)


isConnected

public boolean isConnected()


transferFileFrom

public int transferFileFrom(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.lang.String pathAndFileOnLocalServer)
deprecated:
since 0.5; See copyFromServer(Map, InputStream, String)


transferFileTo

public int transferFileTo(java.util.Map props, java.io.InputStream input, java.lang.String pathAndFileOnRemoteServer)
deprecated:
since 0.5; See copyToServer(Map, InputStream, String)


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.