|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ace.moab.api.connect.SSHConnection
public class SSHConnection
Provides a connection to an instance of Moab through an SSH connection. This class also provides some methods to get more information about the Moab Connection specific to SSH connections.
IMoabConnection
Constructor Summary | |
---|---|
SSHConnection(java.lang.String hostname,
int port)
This constructor sets up the host and port information necessary to create an SSH connection. |
Method Summary | |
---|---|
boolean |
connectWithPassword(java.lang.String username,
java.lang.String password)
Initiates a connection to the host machine on the port number previously specified. |
boolean |
connectWithPublicKey(java.lang.String username,
java.lang.String publicKeyFilePath,
java.lang.String keyPassphrase)
Initiates a connection to the host machine on the port number previously specified. |
void |
disconnect()
Disconnects the ssh connection if it is active. |
MoabInputStream |
executeCommand(java.lang.String command,
boolean isMoabCommand)
Same as connect(command,
isMoabCommand, null) . |
MoabInputStream |
executeCommand(java.lang.String command,
boolean isMoabCommand,
org.apache.log4j.Level log4jLevel)
Runs a command on the remote machine and returns back a reference to the intputStream which will output the results of that command. |
ConnectionType |
getConnectionType()
Returns the connection type of SSH. |
java.lang.String |
getHostname()
Gets the hostname specified at creation time. |
boolean |
isConnected()
Returns true if this connection has been established and
authenticated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SSHConnection(java.lang.String hostname, int port)
hostname
- The name of the host machine that the connection will be made
with.port
- The port number of the host machine that the connection will
be made with.Method Detail |
---|
public boolean connectWithPassword(java.lang.String username, java.lang.String password) throws java.io.IOException, AuthenticationException
If the authentication phase is complete, true
will be
returned. If the server does not accept the request (or if further
authentication steps are needed), false
is returned and one
can retry either by using this or any other authentication method
Note: if this method fails, then please double-check that it is actually offered by the server
Often, password authentication is disabled, but users are not aware of it. Many servers only offer "publickey" and "keyboard-interactive". However, even though "keyboard-interactive" *feels* like password authentication (e.g., when using the putty or openssh clients) it is *not* the same mechanism.
username
- The username used to connect to the host machine.password
- The password used to connect to the host machine.
java.io.IOException
AuthenticationException
- If the authentication failed, an AuthenticationException is
thrown.public boolean connectWithPublicKey(java.lang.String username, java.lang.String publicKeyFilePath, java.lang.String keyPassphrase) throws java.io.IOException, com.moab.api.connect.exception.InitialConnectException
If the authentication phase is complete, true
will be
returned. If the server does not accept the request (or if further
authentication steps are needed), false
is returned and one
can retry either by using this or any other authentication method.
username
- The user used to connect to Moab.publicKeyFilePath
- The complete path of the public key. (i.e.
/home/tmp/.ssh/id_rsa)keyPassphrase
- The passphrase used to unlock the key file.
java.io.IOException
com.moab.api.connect.exception.InitialConnectException
public void disconnect()
public java.lang.String getHostname()
public boolean isConnected()
true
if this connection has been established and
authenticated. If true
, users can attempt to execute
commands on the host.
public ConnectionType getConnectionType()
getConnectionType
in interface IMoabConnection
ConnectionType
public MoabInputStream executeCommand(java.lang.String command, boolean isMoabCommand) throws MoabCommunicationException
connect(command,
isMoabCommand, null)
.
executeCommand
in interface IMoabConnection
command
- the command to be run on the machine where Moab is runningisMoabCommand
- whether the command is a Moab command.
executeCommand(String, boolean, Level)
method.
MoabCommunicationException
- If the command is invalid or the connection has issues, a
MoabCommunciationException is thrown.public MoabInputStream executeCommand(java.lang.String command, boolean isMoabCommand, org.apache.log4j.Level log4jLevel) throws MoabCommunicationException
Runs a command on the remote machine and returns back a reference to the intputStream which will output the results of that command. This can be a moab command, or any other command that can be run on the remote machine
executeCommand
in interface IMoabConnection
command
- the command to be run on the local machineisMoabCommand
- whether the command is a Moab command. (i.e. 'showq')log4jLevel
- (can be null) the log4j level at which this Moab command and
it's output should be written to the log file. This allows
users the ability to prevent the logs from becoming
unnecessarily cluttered by frequently called Moab commands.
MoabCommunicationException
- If the command is invalid or the connection has issues, a
MoabCommunciationException is thrown.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |