Nebula: add VM connection timeout

This commit is contained in:
wpetit 2019-03-15 12:18:39 +01:00
parent 78c8a9e74e
commit ec523ddfb4

View File

@ -149,6 +149,7 @@ def runInNewVM(Map args, Closure body) {
def vmTemplate = args.get('vmTemplate', '')
def terminateOnExit = args.get('terminateOnExit', true)
def shell = args.get("shell", "/bin/sh")
def connectionTimeout = args.get('connectionTimeout', 10)
// On récupère les identifiants de connexion SSH pour la VM
withCredentials([
@ -160,13 +161,15 @@ def runInNewVM(Map args, Closure body) {
def sshArgs = "-i '${VM_SSH_KEY}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
// On attend que la connexion SSH soit disponible
println "En attente de l'accès SSH sur la machine ${host}..."
while(true) {
def status = sh script: "nc -zv ${host} 22", returnStatus: true
if (status == 0) {
break;
println "En attente de l'accès SSH sur la machine ${host}..."
timeout(connectionTimeout) {
while(true) {
def status = sh script: "nc -zv ${host} 22", returnStatus: true
if (status == 0) {
break;
}
sleep(5)
}
sleep(5)
}
def remoteShell = { script ->