Skip to content

Commit

Permalink
feat(vm): vmmigrate add --wait flag
Browse files Browse the repository at this point in the history
  • Loading branch information
paullaffitte authored and lcaflc committed Nov 19, 2024
1 parent 011db78 commit 8b8f1f1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/pvecontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def _parser():
parser_vmmigrate.add_argument('--target', action='store', required=True, help="Destination Proxmox VE node")
parser_vmmigrate.add_argument('--online', action='store_true', help="Online migrate the VM, default True", default=True)
parser_vmmigrate.add_argument('-f', '--follow', action='store_true', help="Follow task log output")
parser_vmmigrate.add_argument('-w', '--wait', action='store_true', help="Wait task end")
parser_vmmigrate.add_argument('--dry-run', action='store_true', help="Dry run, do not execute migration")
parser_vmmigrate.set_defaults(func=vm.action_vmmigrate)

Expand Down
12 changes: 2 additions & 10 deletions src/pvecontrol/actions/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,9 @@ def action_vmmigrate(proxmox, args):
# Suivre la task cree
proxmox.refresh()
task = proxmox.find_task(upid)
if args.follow:
print_task(proxmox, upid, args.follow)
else:
print_taskstatus(task)
# wait for task completion
while task.running():
logging.debug("Task status: %s", task.runningstatus)
task.refresh()
time.sleep(1)
if args.follow or args.wait:
print_task(proxmox, upid, args.follow, args.wait)
print_taskstatus(task)

else:
print("Dry run, skipping migration")

Expand Down
3 changes: 2 additions & 1 deletion src/pvecontrol/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def print_task(proxmox, upid, follow = False, wait = False):
if line['n'] > lastline:
lastline = line['n']
time.sleep(1)
print_taskstatus(task)

if task.running() and wait:
print_log_output = False
while task.running():
task.refresh()
print(".", end="")
Expand All @@ -63,3 +63,4 @@ def print_task(proxmox, upid, follow = False, wait = False):
print("")
if print_log_output:
print_tableoutput([{"log output": task.decode_log()}])
print_taskstatus(task)

0 comments on commit 8b8f1f1

Please sign in to comment.