Skip to content

Commit 9692e29

Browse files
Support for custom SSH port for KVM hosts using the configuration 'kvm.host.discovery.ssh.port'
- Use the custom SSH port for KVM host discovery to connect to the Host during Add Host command - and any other operations on host using SSH
1 parent ce42ce5 commit 9692e29

6 files changed

Lines changed: 10 additions & 6 deletions

File tree

engine/components-api/src/main/java/com/cloud/agent/AgentManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public interface AgentManager {
5454
"This timeout overrides the wait global config. This holds a comma separated key value pairs containing timeout (in seconds) for specific commands. " +
5555
"For example: DhcpEntryCommand=600, SavePasswordCommand=300, VmDataCommand=300", false);
5656

57+
ConfigKey<Integer> KVMHostDiscoverySshPort = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Integer.class,
58+
"kvm.host.discovery.ssh.port", "22", "SSH port used for KVM host discovery and any other operations on host (using SSH)", true);
59+
5760
enum TapAgentsAction {
5861
Add, Del, Contains,
5962
}

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ public ConfigKey<?>[] getConfigKeys() {
19771977
return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize,
19781978
DirectAgentPoolSize, DirectAgentThreadCap, EnableKVMAutoEnableDisable, ReadyCommandWait,
19791979
GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, RemoteAgentMaxConcurrentNewConnections,
1980-
RemoteAgentNewConnectionsMonitorInterval };
1980+
RemoteAgentNewConnectionsMonitorInterval, KVMHostDiscoverySshPort };
19811981
}
19821982

19831983
protected class SetHostParamsListener implements Listener {

plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.backup;
1818

19+
import com.cloud.agent.AgentManager;
1920
import com.cloud.dc.dao.ClusterDao;
2021
import com.cloud.host.HostVO;
2122
import com.cloud.host.Status;
@@ -230,7 +231,7 @@ private String executeBackupCommand(HostVO host, String username, String passwor
230231
Pattern saveTimePattern = Pattern.compile(nstRegex);
231232

232233
try {
233-
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), 22,
234+
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), AgentManager.KVMHostDiscoverySshPort.value(),
234235
username, null, password, command, 120000, 120000, 3600000);
235236
if (!response.first()) {
236237
LOG.error(String.format("Backup Script failed on HYPERVISOR %s due to: %s", host, response.second()));
@@ -251,7 +252,7 @@ private String executeBackupCommand(HostVO host, String username, String passwor
251252
private boolean executeRestoreCommand(HostVO host, String username, String password, String command) {
252253

253254
try {
254-
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), 22,
255+
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), AgentManager.KVMHostDiscoverySshPort.value(),
255256
username, null, password, command, 120000, 120000, 3600000);
256257

257258
if (!response.first()) {

server/src/main/java/com/cloud/hypervisor/kvm/discoverer/LibvirtServerDiscoverer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private void setupAgentSecurity(final Connection sshConnection, final String age
272272
}
273273
}
274274

275-
sshConnection = new Connection(agentIp, 22);
275+
sshConnection = new Connection(agentIp, AgentManager.KVMHostDiscoverySshPort.value());
276276

277277
sshConnection.connect(null, 60000, 60000);
278278

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2949,7 +2949,7 @@ protected Ternary<String, String, String> getHostCredentials(HostVO host) {
29492949
*/
29502950
protected void connectAndRestartAgentOnHost(HostVO host, String username, String password, String privateKey) {
29512951
final com.trilead.ssh2.Connection connection = SSHCmdHelper.acquireAuthorizedConnection(
2952-
host.getPrivateIpAddress(), 22, username, password, privateKey);
2952+
host.getPrivateIpAddress(), AgentManager.KVMHostDiscoverySshPort.value(), username, password, privateKey);
29532953
if (connection == null) {
29542954
throw new CloudRuntimeException(String.format("SSH to agent is enabled, but failed to connect to %s via IP address [%s].", host, host.getPrivateIpAddress()));
29552955
}

utils/src/main/java/com/cloud/utils/ssh/SSHCmdHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static com.trilead.ssh2.Connection acquireAuthorizedConnection(String ip,
7777
}
7878

7979
public static com.trilead.ssh2.Connection acquireAuthorizedConnection(String ip, int port, String username, String password) {
80-
return acquireAuthorizedConnection(ip, 22, username, password, null);
80+
return acquireAuthorizedConnection(ip, port, username, password, null);
8181
}
8282

8383
public static boolean acquireAuthorizedConnectionWithPublicKey(final com.trilead.ssh2.Connection sshConnection, final String username, final String privateKey) {

0 commit comments

Comments
 (0)