Search in sources :

Example 1 with SshConnection

use of org.platformlayer.ops.ssh.SshConnection in project platformlayer by platformlayer.

the class CloudContextRegistry method getSshConnection.

private SshConnection getSshConnection(String host, String user, KeyPair sshKeyPair) throws OpsException {
    OpsSystem opsSystem = OpsContext.get().getOpsSystem();
    ISshContext sshContext = opsSystem.getSshContext();
    SshConnection sshConnection = sshContext.getSshConnection(user);
    try {
        sshConnection.setHost(InetAddress.getByName(host));
    } catch (UnknownHostException e) {
        throw new OpsException("Error resolving address: " + host, e);
    }
    sshConnection.setKeyPair(sshKeyPair);
    // TODO: Verify the server key once we've learned it
    IServerKeyVerifier serverKeyVerifier = new AcceptAllLearningServerKeyVerifier();
    sshConnection.setServerKeyVerifier(serverKeyVerifier);
    return sshConnection;
}
Also used : SshConnection(org.platformlayer.ops.ssh.SshConnection) AcceptAllLearningServerKeyVerifier(org.platformlayer.ops.ssh.AcceptAllLearningServerKeyVerifier) UnknownHostException(java.net.UnknownHostException) IServerKeyVerifier(org.platformlayer.ops.ssh.IServerKeyVerifier) ISshContext(org.platformlayer.ops.ssh.ISshContext)

Example 2 with SshConnection

use of org.platformlayer.ops.ssh.SshConnection in project platformlayer by platformlayer.

the class MachineBase method getTarget.

@Override
public OpsTarget getTarget(String user, KeyPair sshKeyPair) throws OpsException {
    OpsSystem opsSystem = OpsContext.get().getOpsSystem();
    ISshContext sshContext = opsSystem.getSshContext();
    SshConnection sshConnection = sshContext.getSshConnection(user);
    String address = getNetworkPoint().getBestAddress(NetworkPoint.forMe());
    try {
        sshConnection.setHost(InetAddress.getByName(address));
    } catch (UnknownHostException e) {
        throw new OpsException("Error resolving address: " + address, e);
    }
    sshConnection.setKeyPair(sshKeyPair);
    File tempDirBase = new File("/tmp/");
    // TODO: Verify the server key once we've learned it
    IServerKeyVerifier serverKeyVerifier = new AcceptAllLearningServerKeyVerifier();
    sshConnection.setServerKeyVerifier(serverKeyVerifier);
    return new SshOpsTarget(tempDirBase, this, sshConnection);
}
Also used : SshConnection(org.platformlayer.ops.ssh.SshConnection) AcceptAllLearningServerKeyVerifier(org.platformlayer.ops.ssh.AcceptAllLearningServerKeyVerifier) UnknownHostException(java.net.UnknownHostException) IServerKeyVerifier(org.platformlayer.ops.ssh.IServerKeyVerifier) File(java.io.File) ISshContext(org.platformlayer.ops.ssh.ISshContext)

Example 3 with SshConnection

use of org.platformlayer.ops.ssh.SshConnection in project platformlayer by platformlayer.

the class SshOpsTarget method executeCommandUnchecked.

@Override
protected ProcessExecution executeCommandUnchecked(Command command) throws ProcessExecutionException {
    try {
        String commandString = command.buildCommandString();
        TimeSpan timeout = command.getTimeout();
        if (command.getKeyPair() != null) {
            SshConnection agentConnection = sshConnection.buildAgentConnection(command.getKeyPair());
            try {
                return agentConnection.sshExecute(commandString, timeout);
            } finally {
                agentConnection.close();
            }
        } else {
            return sshConnection.sshExecute(commandString, timeout);
        }
    } catch (IOException e) {
        throw new ProcessExecutionException("Error during command execution", e);
    } catch (InterruptedException e) {
        ExceptionUtils.handleInterrupted(e);
        throw new ProcessExecutionException("Error during command execution", e);
    } catch (SshException e) {
        throw new ProcessExecutionException("Error during command execution", e);
    }
}
Also used : TimeSpan(com.fathomdb.TimeSpan) SshConnection(org.platformlayer.ops.ssh.SshConnection) ProcessExecutionException(org.platformlayer.ops.process.ProcessExecutionException) IOException(java.io.IOException) SshException(org.platformlayer.ops.ssh.SshException)

Aggregations

SshConnection (org.platformlayer.ops.ssh.SshConnection)3 UnknownHostException (java.net.UnknownHostException)2 AcceptAllLearningServerKeyVerifier (org.platformlayer.ops.ssh.AcceptAllLearningServerKeyVerifier)2 IServerKeyVerifier (org.platformlayer.ops.ssh.IServerKeyVerifier)2 ISshContext (org.platformlayer.ops.ssh.ISshContext)2 TimeSpan (com.fathomdb.TimeSpan)1 File (java.io.File)1 IOException (java.io.IOException)1 ProcessExecutionException (org.platformlayer.ops.process.ProcessExecutionException)1 SshException (org.platformlayer.ops.ssh.SshException)1