Revision 19b9ba9a scripts/gnt-debug
b/scripts/gnt-debug | ||
---|---|---|
39 | 39 |
from ganeti import errors |
40 | 40 |
|
41 | 41 |
|
42 |
#: Default fields for L{ListLocks} |
|
43 |
_LIST_LOCKS_DEF_FIELDS = [ |
|
44 |
"name", |
|
45 |
"mode", |
|
46 |
"owner", |
|
47 |
] |
|
48 |
|
|
49 |
|
|
42 | 50 |
def Delay(opts, args): |
43 | 51 |
"""Sleeps for a while |
44 | 52 |
|
... | ... | |
398 | 406 |
return 0 |
399 | 407 |
|
400 | 408 |
|
409 |
def ListLocks(opts, args): # pylint: disable-msg=W0613 |
|
410 |
"""List all locks. |
|
411 |
|
|
412 |
@param opts: the command line options selected by the user |
|
413 |
@type args: list |
|
414 |
@param args: should be an empty list |
|
415 |
@rtype: int |
|
416 |
@return: the desired exit code |
|
417 |
|
|
418 |
""" |
|
419 |
selected_fields = ParseFields(opts.output, _LIST_LOCKS_DEF_FIELDS) |
|
420 |
|
|
421 |
if not opts.no_headers: |
|
422 |
headers = { |
|
423 |
"name": "Name", |
|
424 |
"mode": "Mode", |
|
425 |
"owner": "Owner", |
|
426 |
} |
|
427 |
else: |
|
428 |
headers = None |
|
429 |
|
|
430 |
while True: |
|
431 |
# Not reusing client as interval might be too long |
|
432 |
output = GetClient().QueryLocks(selected_fields, False) |
|
433 |
|
|
434 |
# change raw values to nicer strings |
|
435 |
for row in output: |
|
436 |
for idx, field in enumerate(selected_fields): |
|
437 |
val = row[idx] |
|
438 |
|
|
439 |
if field in ("mode", "owner") and val is None: |
|
440 |
val = "-" |
|
441 |
elif field == "owner": |
|
442 |
val = utils.CommaJoin(val) |
|
443 |
|
|
444 |
row[idx] = str(val) |
|
445 |
|
|
446 |
data = GenerateTable(separator=opts.separator, headers=headers, |
|
447 |
fields=selected_fields, data=output) |
|
448 |
for line in data: |
|
449 |
ToStdout(line) |
|
450 |
|
|
451 |
if not opts.interval: |
|
452 |
break |
|
453 |
|
|
454 |
ToStdout("") |
|
455 |
time.sleep(opts.interval) |
|
456 |
|
|
457 |
return 0 |
|
458 |
|
|
459 |
|
|
401 | 460 |
commands = { |
402 | 461 |
'delay': ( |
403 | 462 |
Delay, [ArgUnknown(min=1, max=1)], |
... | ... | |
454 | 513 |
"{opts...} <instance>", "Executes a TestAllocator OpCode"), |
455 | 514 |
"test-jobqueue": ( |
456 | 515 |
TestJobqueue, ARGS_NONE, [], |
457 |
"", "Test a few aspects of the job queue") |
|
516 |
"", "Test a few aspects of the job queue"), |
|
517 |
"locks": ( |
|
518 |
ListLocks, ARGS_NONE, [NOHDR_OPT, SEP_OPT, FIELDS_OPT, INTERVAL_OPT], |
|
519 |
"[--interval N]", "Show a list of locks in the master daemon"), |
|
458 | 520 |
} |
459 | 521 |
|
460 | 522 |
|
Also available in: Unified diff