Skip to content

Commit

Permalink
fix: harmonize logs when using --wait and --follow
Browse files Browse the repository at this point in the history
  • Loading branch information
paullaffitte authored and lcaflc committed Nov 19, 2024
1 parent edae9da commit 81df66a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
5 changes: 1 addition & 4 deletions src/pvecontrol/actions/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ def action_nodeevacuate(proxmox, args):
logging.debug("Migration UPID: %s"%upid)
proxmox.refresh()
task = proxmox.find_task(upid)
if args.follow or args.wait:
print_task(proxmox, upid, args.follow, args.wait)
else:
print_taskstatus(task)
print_task(proxmox, upid, args.follow, args.wait)
else:
print("Dry run, skipping migration")
2 changes: 1 addition & 1 deletion src/pvecontrol/actions/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def action_tasklist(proxmox, args):
print_tableoutput(tasks, sortby='starttime')

def action_taskget(proxmox, args):
print_task(proxmox, args.upid, args.follow, args.wait)
print_task(proxmox, args.upid, args.follow, args.wait, show_logs = True)
4 changes: 1 addition & 3 deletions src/pvecontrol/actions/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def action_vmmigrate(proxmox, args):
# Suivre la task cree
proxmox.refresh()
task = proxmox.find_task(upid)
if args.follow or args.wait:
print_task(proxmox, upid, args.follow, args.wait)
print_taskstatus(task)
print_task(proxmox, upid, args.follow, args.wait)
else:
print("Dry run, skipping migration")

Expand Down
16 changes: 9 additions & 7 deletions src/pvecontrol/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ def print_taskstatus(task):
output = [ filter_keys(task.__dict__, ['upid', 'exitstatus', 'node', 'runningstatus', 'type', 'user', 'starttime']) ]
print_tableoutput(output)

def print_task(proxmox, upid, follow = False, wait = False):
def print_task(proxmox, upid, follow = False, wait = False, show_logs = False):
task = proxmox.find_task(upid)
logging.debug("Task: %s", task)
print_taskstatus(task)

if task.running() and (follow or wait):
print_taskstatus(task)

log = task.log(limit=0)
logging.debug("Task Log: %s", log)
print_log_output = True
if task.running() and follow:
print_log_output = False
lastline = 0
print("log output, follow mode")
while task.running():
Expand All @@ -54,13 +55,14 @@ def print_task(proxmox, upid, follow = False, wait = False):
time.sleep(1)

if task.running() and wait:
print_log_output = False
while task.running():
task.refresh()
print(".", end="")
sys.stdout.flush()
time.sleep(1)
print("")
if print_log_output:

if (show_logs and not follow) or not (task.running() or follow or wait):
print_tableoutput([{"log output": task.decode_log()}])
print_taskstatus(task)

print_taskstatus(task)

0 comments on commit 81df66a

Please sign in to comment.