@Override public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { meta = (SSHMeta) smi; data = (SSHData) sdi; if ( data.conn != null ) { data.conn.close(); if ( log.isDebug() ) { logDebug( BaseMessages.getString( PKG, "SSH.Log.ConnectionClosed" ) ); } } super.dispose( smi, sdi ); } }
private void closeFTPConnections() { // Close FTP connection if necessary if ( ftpclient != null && ftpclient.connected() ) { try { ftpclient.quit(); ftpclient = null; } catch ( Exception e ) { // Ignore close errors } } // Close SecureFTP connection if necessary if ( sftpclient != null ) { try { sftpclient.disconnect(); sftpclient = null; } catch ( Exception e ) { // Ignore close errors } } // Close SSH connection if necessary if ( conn != null ) { try { conn.close(); conn = null; } catch ( Exception e ) { // Ignore close errors } } }
public static void releaseSshConnection(com.trilead.ssh2.Connection sshConnection) { if (sshConnection != null) { sshConnection.close(); } }
if ( conn != null ) { try { conn.close(); } catch ( Exception ignored ) {
if ( conn != null ) { try { conn.close(); } catch ( Exception e ) { /* Ignore */
public Boolean checkHeartbeat(final String hostuuid) { final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password.peek())) { throw new CloudRuntimeException("Unable to authenticate"); } final String shcmd = "/opt/cloud/bin/check_heartbeat.sh " + hostuuid + " " + Integer.toString(_heartbeatInterval * 2); if (!SSHCmdHelper.sshExecuteCmd(sshConnection, shcmd)) { s_logger.debug("Heart beat is gone so dead."); return false; } s_logger.debug("Heart beat is still going"); return true; } catch (final Exception e) { s_logger.debug("health check failed due to catch exception " + e.toString()); return null; } finally { sshConnection.close(); } }
} finally { if (sshConnection != null) { sshConnection.close();
} finally { if (sshConnection != null) { sshConnection.close();
public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, String localFile, String fileMode, int connectTimeoutInMs, int kexTimeoutInMs) throws Exception { com.trilead.ssh2.Connection conn = null; com.trilead.ssh2.SCPClient scpClient = null; try { conn = new com.trilead.ssh2.Connection(host, port); conn.connect(null, connectTimeoutInMs, kexTimeoutInMs); if (pemKeyFile == null) { if (!conn.authenticateWithPassword(user, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } else { if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } scpClient = conn.createSCPClient(); if (fileMode != null) scpClient.put(localFile, remoteTargetDirectory, fileMode); else scpClient.put(localFile, remoteTargetDirectory); } finally { if (conn != null) conn.close(); } }
public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, byte[] data, String remoteFileName, String fileMode, int connectTimeoutInMs, int kexTimeoutInMs) throws Exception { com.trilead.ssh2.Connection conn = null; com.trilead.ssh2.SCPClient scpClient = null; try { conn = new com.trilead.ssh2.Connection(host, port); conn.connect(null, connectTimeoutInMs, kexTimeoutInMs); if (pemKeyFile == null) { if (!conn.authenticateWithPassword(user, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } else { if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } scpClient = conn.createSCPClient(); if (fileMode != null) scpClient.put(data, remoteFileName, remoteTargetDirectory, fileMode); else scpClient.put(data, remoteFileName, remoteTargetDirectory); } finally { if (conn != null) conn.close(); } }
public boolean doPingTest(final Connection conn, final String computingHostIp) { final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password.peek())) { throw new CloudRuntimeException("Unable to authenticate"); } final String cmd = "ping -c 2 " + computingHostIp; if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) { throw new CloudRuntimeException("Cannot ping host " + computingHostIp + " from host " + _host.getIp()); } return true; } catch (final Exception e) { s_logger.warn("Catch exception " + e.toString(), e); return false; } finally { sshConnection.close(); } }
@Override public boolean setupServer(final Connection conn,final Host host) { final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password.peek())) { throw new CloudRuntimeException("Unable to authenticate"); } final String cmd = "rm -f /opt/xensource/sm/hostvmstats.py " + "/opt/xensource/bin/copy_vhd_to_secondarystorage.sh " + "/opt/xensource/bin/copy_vhd_from_secondarystorage.sh " + "/opt/xensource/bin/create_privatetemplate_from_snapshot.sh " + "/opt/xensource/bin/vhd-util " + "/opt/cloud/bin/copy_vhd_to_secondarystorage.sh " + "/opt/cloud/bin/copy_vhd_from_secondarystorage.sh " + "/opt/cloud/bin/create_privatetemplate_from_snapshot.sh " + "/opt/cloud/bin/vhd-util"; SSHCmdHelper.sshExecuteCmd(sshConnection, cmd); } catch (final Exception e) { s_logger.debug("Catch exception " + e.toString(), e); } finally { sshConnection.close(); } return super.setupServer(conn, host); }
return false; } finally { sshConnection.close();
protected PreparePxeServerAnswer execute(PreparePxeServerCommand cmd) { com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { s_logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } String script = String.format("python /usr/bin/prepare_tftp_bootfile.py restore %1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s", _tftpDir, cmd.getMac(), _storageServer, _share, _dir, cmd.getTemplate(), _cifsUserName, _cifsPassword, cmd.getIp(), cmd.getNetMask(), cmd.getGateWay()); if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) { return new PreparePxeServerAnswer(cmd, "prepare PING at " + _ip + " failed, command:" + script); } s_logger.debug("Prepare Ping PXE server successfully"); return new PreparePxeServerAnswer(cmd); } catch (Exception e) { s_logger.debug("Prepare PING pxe server failed", e); return new PreparePxeServerAnswer(cmd, e.getMessage()); } finally { if (sshConnection != null) { sshConnection.close(); } } }
protected Answer execute(PrepareCreateTemplateCommand cmd) { com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { s_logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } String script = String.format("python /usr/bin/prepare_tftp_bootfile.py backup %1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s", _tftpDir, cmd.getMac(), _storageServer, _share, _dir, cmd.getTemplate(), _cifsUserName, _cifsPassword, cmd.getIp(), cmd.getNetMask(), cmd.getGateWay()); if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) { return new Answer(cmd, false, "prepare for creating template failed, command:" + script); } s_logger.debug("Prepare for creating template successfully"); return new Answer(cmd, true, "Success"); } catch (Exception e) { s_logger.debug("Prepare for creating baremetal template failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { sshConnection.close(); } } }
} finally { if (sshConnection != null) { sshConnection.close();
throw new CloudRuntimeException("Unable to create iso folder", e); } finally { sshConnection.close();
} finally { if (sshConnection != null) { sshConnection.close();
} finally { if (sshConnection != null) { sshConnection.close();