Revision 99a11adc
b/tools/ganeti-listrunner | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007, 2010 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2010, 2011 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
203 | 203 |
return [] |
204 | 204 |
|
205 | 205 |
|
206 |
def SetupSshConnection(host, username, password, keys, logfile):
|
|
206 |
def SetupSshConnection(host, username, password, use_agent, logfile):
|
|
207 | 207 |
"""Setup the ssh connection used for all later steps. |
208 | 208 |
|
209 | 209 |
This function sets up the ssh connection that will be used both |
... | ... | |
219 | 219 |
print " - ERROR: host not reachable on 22/tcp" |
220 | 220 |
return False |
221 | 221 |
|
222 |
if use_agent: |
|
223 |
keys = GetAgentKeys() |
|
224 |
else: |
|
225 |
keys = [] |
|
222 | 226 |
all_kwargs = [{"pkey": k} for k in keys] |
223 | 227 |
all_desc = ["key %d" % d for d in range(len(keys))] |
224 | 228 |
if password is not None: |
... | ... | |
346 | 350 |
return True |
347 | 351 |
|
348 | 352 |
|
349 |
def HostWorker(logdir, username, password, keys, hostname,
|
|
353 |
def HostWorker(logdir, username, password, use_agent, hostname,
|
|
350 | 354 |
executable, command, filelist): |
351 | 355 |
"""Per-host worker. |
352 | 356 |
|
... | ... | |
357 | 361 |
@param logdir: the directory where the logfiles must be created |
358 | 362 |
@param username: SSH username |
359 | 363 |
@param password: SSH password |
360 |
@param keys: SSH keys
|
|
364 |
@param use_agent: whether we should instead use an agent
|
|
361 | 365 |
@param hostname: the hostname to connect to |
362 | 366 |
@param executable: the executable to upload, if not None |
363 | 367 |
@param command: the command to run |
... | ... | |
370 | 374 |
result = 0 # optimism, I know |
371 | 375 |
try: |
372 | 376 |
connection = SetupSshConnection(hostname, username, |
373 |
password, keys, logfile)
|
|
377 |
password, use_agent, logfile)
|
|
374 | 378 |
if connection is not False: |
375 | 379 |
if executable is not None: |
376 | 380 |
print " %s: uploading files" % hostname |
... | ... | |
412 | 416 |
sys.exit(result) |
413 | 417 |
|
414 | 418 |
|
415 |
def LaunchWorker(child_pids, logdir, username, password, keys, hostname,
|
|
419 |
def LaunchWorker(child_pids, logdir, username, password, use_agent, hostname,
|
|
416 | 420 |
executable, command, filelist): |
417 | 421 |
"""Launch the per-host worker. |
418 | 422 |
|
... | ... | |
426 | 430 |
# controller just record the pids |
427 | 431 |
child_pids[pid] = hostname |
428 | 432 |
else: |
429 |
HostWorker(logdir, username, password, keys, hostname,
|
|
433 |
HostWorker(logdir, username, password, use_agent, hostname,
|
|
430 | 434 |
executable, command, filelist) |
431 | 435 |
|
432 | 436 |
|
... | ... | |
489 | 493 |
print "ERROR: cannot create logfiles in dir %s, aborting" % logdir |
490 | 494 |
sys.exit(1) |
491 | 495 |
|
492 |
keys = [] |
|
493 | 496 |
if use_agent: |
494 |
keys = GetAgentKeys()
|
|
497 |
pass
|
|
495 | 498 |
elif password: |
496 | 499 |
try: |
497 | 500 |
fh = file(password) |
... | ... | |
523 | 526 |
hosts = hosts[batch_size:] |
524 | 527 |
child_pids = {} |
525 | 528 |
for hostname in batch: |
526 |
LaunchWorker(child_pids, logdir, username, password, keys, hostname,
|
|
529 |
LaunchWorker(child_pids, logdir, username, password, use_agent, hostname,
|
|
527 | 530 |
executable, command, filelist) |
528 | 531 |
|
529 | 532 |
while child_pids: |
... | ... | |
535 | 538 |
else: |
536 | 539 |
failures += 1 |
537 | 540 |
if hosts: |
538 |
LaunchWorker(child_pids, logdir, username, password, keys,
|
|
541 |
LaunchWorker(child_pids, logdir, username, password, use_agent,
|
|
539 | 542 |
hosts.pop(0), executable, command, filelist) |
540 | 543 |
|
541 | 544 |
|
Also available in: Unified diff