Add restart command support
This commit is contained in:
parent
bc52c80aec
commit
ae28cc932e
53
pvc.py
53
pvc.py
|
@ -467,6 +467,56 @@ def start_vm(dom_name, dom_uuid):
|
||||||
pvcf.stopZKConnection(zk)
|
pvcf.stopZKConnection(zk)
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# pvc vm restart
|
||||||
|
###############################################################################
|
||||||
|
@click.command(name='restart', short_help='Restart virtual machine.')
|
||||||
|
@click.option(
|
||||||
|
'-n', '--name', 'dom_name',
|
||||||
|
cls=pvcf.MutuallyExclusiveOption,
|
||||||
|
mutually_exclusive=[{ 'function': 'dom_uuid', 'argument': '--uuid' }],
|
||||||
|
help='Search for this human-readable name.'
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
'-u', '--uuid', 'dom_uuid',
|
||||||
|
cls=pvcf.MutuallyExclusiveOption,
|
||||||
|
mutually_exclusive=[{ 'function': 'dom_name', 'argument': '--name' }],
|
||||||
|
help='Search for this UUID.'
|
||||||
|
)
|
||||||
|
def start_vm(dom_name, dom_uuid):
|
||||||
|
"""
|
||||||
|
Restart a virtual machine on its configured hypervisor.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Ensure at least one search method is set
|
||||||
|
if dom_name == None and dom_uuid == None:
|
||||||
|
click.echo("ERROR: You must specify either a `--name` or `--uuid` value.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Open a Zookeeper connection
|
||||||
|
zk = pvcf.startZKConnection(zk_host)
|
||||||
|
|
||||||
|
# If the --name value was passed, get the UUID
|
||||||
|
if dom_name != None:
|
||||||
|
dom_uuid = pvcf.searchClusterByName(zk, dom_name)
|
||||||
|
|
||||||
|
# Verify we got a result or abort
|
||||||
|
if not pvcf.validateUUID(dom_uuid):
|
||||||
|
if dom_name != None:
|
||||||
|
message_name = dom_name
|
||||||
|
else:
|
||||||
|
message_name = dom_uuid
|
||||||
|
click.echo('ERROR: Could not find VM "{}" in the cluster!'.format(message_name))
|
||||||
|
return
|
||||||
|
|
||||||
|
# Set the VM to start
|
||||||
|
click.echo('Restarting VM "{}".'.format(dom_uuid))
|
||||||
|
zk.set('/domains/%s/state' % dom_uuid, 'restart'.encode('ascii'))
|
||||||
|
|
||||||
|
# Close the Zookeeper connection
|
||||||
|
pvcf.stopZKConnection(zk)
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# pvc vm shutdown
|
# pvc vm shutdown
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -951,6 +1001,8 @@ def _vm_list(hypervisor):
|
||||||
vm_state_colour = ansiiprint.green()
|
vm_state_colour = ansiiprint.green()
|
||||||
elif vm_state[vm] == 'stop':
|
elif vm_state[vm] == 'stop':
|
||||||
vm_state_colour = ansiiprint.red()
|
vm_state_colour = ansiiprint.red()
|
||||||
|
elif vm_state[vm] == 'restart':
|
||||||
|
vm_state_colour = ansiiprint.yellow()
|
||||||
else:
|
else:
|
||||||
vm_state_colour = ansiiprint.blue()
|
vm_state_colour = ansiiprint.blue()
|
||||||
|
|
||||||
|
@ -1047,6 +1099,7 @@ node.add_command(node_list)
|
||||||
vm.add_command(define_vm)
|
vm.add_command(define_vm)
|
||||||
vm.add_command(undefine_vm)
|
vm.add_command(undefine_vm)
|
||||||
vm.add_command(start_vm)
|
vm.add_command(start_vm)
|
||||||
|
vm.add_command(restart_vm)
|
||||||
vm.add_command(shutdown_vm)
|
vm.add_command(shutdown_vm)
|
||||||
vm.add_command(stop_vm)
|
vm.add_command(stop_vm)
|
||||||
vm.add_command(move_vm)
|
vm.add_command(move_vm)
|
||||||
|
|
Loading…
Reference in New Issue