Add wait support to VM CLI commands

References #72
This commit is contained in:
Joshua Boniface 2020-02-19 09:57:31 -05:00
parent 99f579e41a
commit 78780039de
2 changed files with 37 additions and 15 deletions

View File

@ -173,16 +173,17 @@ def vm_remove(config, vm, delete_disks=False):
return retstatus, response.json()['message'] 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 Modify the current state of VM
API endpoint: POST /vm/{vm}/state API endpoint: POST /vm/{vm}/state
API arguments: state={state} API arguments: state={state}, wait={wait}
API schema: {"message":"{data}"} API schema: {"message":"{data}"}
""" """
params={ params={
'state': target_state, 'state': target_state,
'wait': str(wait).lower()
} }
response = call_api(config, 'post', '/vm/{vm}/state'.format(vm=vm), params=params) 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'] 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} Modify the current node of VM via {action}
API endpoint: POST /vm/{vm}/node 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}"} API schema: {"message":"{data}"}
""" """
params={ params={
'node': target_node, 'node': target_node,
'action': action, '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) response = call_api(config, 'post', '/vm/{vm}/node'.format(vm=vm), params=params)

View File

@ -729,12 +729,16 @@ def vm_start(domain):
@click.argument( @click.argument(
'domain' '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. 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) cleanup(retcode, retmsg)
############################################################################### ###############################################################################
@ -744,12 +748,16 @@ def vm_restart(domain):
@click.argument( @click.argument(
'domain' '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. 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) cleanup(retcode, retmsg)
############################################################################### ###############################################################################
@ -795,12 +803,16 @@ def vm_disable(domain):
'-t', '--target', 'target_node', default=None, '-t', '--target', 'target_node', default=None,
help='Target node to migrate to; autodetect if unspecified.' 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. 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) cleanup(retcode, retmsg)
############################################################################### ###############################################################################
@ -818,12 +830,16 @@ def vm_move(domain, target_node):
'-f', '--force', 'force_migrate', is_flag=True, default=False, '-f', '--force', 'force_migrate', is_flag=True, default=False,
help='Force migrate an already migrated VM; does not replace an existing previous node value.' 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. 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) cleanup(retcode, retmsg)
############################################################################### ###############################################################################
@ -833,12 +849,16 @@ def vm_migrate(domain, target_node, force_migrate):
@click.argument( @click.argument(
'domain' '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. 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) cleanup(retcode, retmsg)
############################################################################### ###############################################################################