Connect with address (not host)
This commit is contained in:
parent
c0acf60521
commit
55cab19e33
1 changed files with 15 additions and 4 deletions
|
@ -4,6 +4,7 @@ import threading
|
||||||
import queue
|
import queue
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import socket
|
||||||
import random
|
import random
|
||||||
import yaml
|
import yaml
|
||||||
import paramiko
|
import paramiko
|
||||||
|
@ -58,8 +59,9 @@ class Task:
|
||||||
class WorkingThread(threading.Thread):
|
class WorkingThread(threading.Thread):
|
||||||
""" A thread actually getting work done on a given machine """
|
""" A thread actually getting work done on a given machine """
|
||||||
|
|
||||||
def __init__(self, host, workqueue, failures):
|
def __init__(self, host, addr, workqueue, failures):
|
||||||
self.host = host
|
self.host = host
|
||||||
|
self.addr = addr
|
||||||
self.client = None
|
self.client = None
|
||||||
self.workqueue = workqueue
|
self.workqueue = workqueue
|
||||||
self.failures = failures
|
self.failures = failures
|
||||||
|
@ -70,18 +72,24 @@ class WorkingThread(threading.Thread):
|
||||||
self.client.load_system_host_keys()
|
self.client.load_system_host_keys()
|
||||||
for n_try in range(3):
|
for n_try in range(3):
|
||||||
try:
|
try:
|
||||||
self.client.connect(self.host, username=CONFIG["username"])
|
self.client.connect(self.addr, username=CONFIG["username"])
|
||||||
break
|
break
|
||||||
except Exception as exn:
|
except Exception as exn:
|
||||||
delay = 3 + random.random() * 4
|
delay = 3 + random.random() * 4
|
||||||
print(
|
print(
|
||||||
(
|
(
|
||||||
"[{}] Failed to connect. Retry in {} seconds."
|
"[{}] Failed to connect. Retry in {:.02f} seconds."
|
||||||
+ "Exception:\n{}"
|
+ "Exception:\n{}"
|
||||||
).format(self.host, delay, exn),
|
).format(self.host, delay, exn),
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
"[{}] Failed to connect, stopping thread.".format(self.host),
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
@ -121,7 +129,10 @@ class HostsFile:
|
||||||
"Host {} has no {}".format(entry["host"], field)
|
"Host {} has no {}".format(entry["host"], field)
|
||||||
)
|
)
|
||||||
raise Exception("Host has no {}".format(field))
|
raise Exception("Host has no {}".format(field))
|
||||||
self.hosts[entry["host"]] = {"cores": entry["cores"]}
|
self.hosts[entry["host"]] = {
|
||||||
|
"cores": entry["cores"],
|
||||||
|
"ip": socket.gethostbyname(entry["host"]),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class TasksFile:
|
class TasksFile:
|
||||||
|
|
Loading…
Reference in a new issue