diff --git a/client-cli/cli_lib/vm.py b/client-cli/cli_lib/vm.py index cdf6eb0a..16a18a26 100644 --- a/client-cli/cli_lib/vm.py +++ b/client-cli/cli_lib/vm.py @@ -173,16 +173,17 @@ def vm_remove(config, vm, delete_disks=False): return retstatus, response.json()['message'] -def vm_state(config, vm, target_state): +def vm_state(config, vm, target_state, wait=False): """ Modify the current state of VM API endpoint: POST /vm/{vm}/state - API arguments: state={state} + API arguments: state={state}, wait={wait} API schema: {"message":"{data}"} """ params={ 'state': target_state, + 'wait': str(wait).lower() } response = call_api(config, 'post', '/vm/{vm}/state'.format(vm=vm), params=params) @@ -193,18 +194,19 @@ def vm_state(config, vm, target_state): return retstatus, response.json()['message'] -def vm_node(config, vm, target_node, action, force=False): +def vm_node(config, vm, target_node, action, force=False, wait=False): """ Modify the current node of VM via {action} API endpoint: POST /vm/{vm}/node - API arguments: node={target_node}, action={action}, force={force} + API arguments: node={target_node}, action={action}, force={force}, wait={wait} API schema: {"message":"{data}"} """ params={ 'node': target_node, 'action': action, - 'force': force + 'force': str(force).lower(), + 'wait': str(wait).lower() } response = call_api(config, 'post', '/vm/{vm}/node'.format(vm=vm), params=params) diff --git a/client-cli/pvc.py b/client-cli/pvc.py index 5398ccfa..39f068e6 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -729,12 +729,16 @@ def vm_start(domain): @click.argument( 'domain' ) -def vm_restart(domain): +@click.option( + '-w', '--wait', 'wait', is_flag=True, default=False, + help='Wait for restart to complete before returning.' +) +def vm_restart(domain, wait): """ Restart running virtual machine DOMAIN. DOMAIN may be a UUID or name. """ - retcode, retmsg = pvc_vm.vm_state(config, domain, 'restart') + retcode, retmsg = pvc_vm.vm_state(config, domain, 'restart', wait=wait) cleanup(retcode, retmsg) ############################################################################### @@ -744,12 +748,16 @@ def vm_restart(domain): @click.argument( 'domain' ) -def vm_shutdown(domain): +@click.option( + '-w', '--wait', 'wait', is_flag=True, default=False, + help='Wait for shutdown to complete before returning.' +) +def vm_shutdown(domain, wait): """ Gracefully shut down virtual machine DOMAIN. DOMAIN may be a UUID or name. """ - retcode, retmsg = pvc_vm.vm_state(config, domain, 'shutdown') + retcode, retmsg = pvc_vm.vm_state(config, domain, 'shutdown', wait=wait) cleanup(retcode, retmsg) ############################################################################### @@ -795,12 +803,16 @@ def vm_disable(domain): '-t', '--target', 'target_node', default=None, help='Target node to migrate to; autodetect if unspecified.' ) -def vm_move(domain, target_node): +@click.option( + '-w', '--wait', 'wait', is_flag=True, default=False, + help='Wait for migration to complete before returning.' +) +def vm_move(domain, target_node, wait): """ Permanently move virtual machine DOMAIN, via live migration if running and possible, to another node. DOMAIN may be a UUID or name. """ - retcode, retmsg = pvc_vm.vm_node(config, domain, target_node, 'move', force=False) + retcode, retmsg = pvc_vm.vm_node(config, domain, target_node, 'move', force=False, wait=wait) cleanup(retcode, retmsg) ############################################################################### @@ -818,12 +830,16 @@ def vm_move(domain, target_node): '-f', '--force', 'force_migrate', is_flag=True, default=False, help='Force migrate an already migrated VM; does not replace an existing previous node value.' ) -def vm_migrate(domain, target_node, force_migrate): +@click.option( + '-w', '--wait', 'wait', is_flag=True, default=False, + help='Wait for migration to complete before returning.' +) +def vm_migrate(domain, target_node, force_migrate, wait): """ Temporarily migrate running virtual machine DOMAIN, via live migration if possible, to another node. DOMAIN may be a UUID or name. If DOMAIN is not running, it will be started on the target node. """ - retcode, retmsg = pvc_vm.vm_node(config, domain, target_node, 'migrate', force=force_migrate) + retcode, retmsg = pvc_vm.vm_node(config, domain, target_node, 'migrate', force=force_migrate, wait=wait) cleanup(retcode, retmsg) ############################################################################### @@ -833,12 +849,16 @@ def vm_migrate(domain, target_node, force_migrate): @click.argument( 'domain' ) -def vm_unmigrate(domain): +@click.option( + '-w', '--wait', 'wait', is_flag=True, default=False, + help='Wait for migration to complete before returning.' +) +def vm_unmigrate(domain, wait): """ Restore previously migrated virtual machine DOMAIN, via live migration if possible, to its original node. DOMAIN may be a UUID or name. If DOMAIN is not running, it will be started on the target node. """ - retcode, retmsg = pvc_vm.vm_node(config, domain, None, 'unmigrate', force=False) + retcode, retmsg = pvc_vm.vm_node(config, domain, None, 'unmigrate', force=False, wait=wait) cleanup(retcode, retmsg) ###############################################################################