Add wait flag to flush command

This commit is contained in:
Joshua Boniface 2018-07-17 01:48:15 -04:00
parent 4561c1fdb1
commit eef9bb6b1d
1 changed files with 12 additions and 1 deletions

13
pvc.py
View File

@ -383,10 +383,14 @@ def node():
# pvc node flush # pvc node flush
############################################################################### ###############################################################################
@click.command(name='flush', short_help='Take a node out of service') @click.command(name='flush', short_help='Take a node out of service')
@click.option(
'-w', '--wait', 'wait', is_flag=True, default=False,
help='Wait for migrations to complete before returning.'
)
@click.argument( @click.argument(
'node', default=myhostname 'node', default=myhostname
) )
def flush_host(node): def flush_host(node, wait):
""" """
Take NODE out of active service and migrate away all VMs. If unspecified, defaults to this host. Take NODE out of active service and migrate away all VMs. If unspecified, defaults to this host.
""" """
@ -404,6 +408,13 @@ def flush_host(node):
transaction.set_data('/nodes/{}/domainstate'.format(node), 'flush'.encode('ascii')) transaction.set_data('/nodes/{}/domainstate'.format(node), 'flush'.encode('ascii'))
results = transaction.commit() results = transaction.commit()
if wait == True:
while True:
sleep(1)
node_state = zk_conn.get('/nodes/{}/state'.format(node_name))[0].decode('ascii')
if node_state == "flushed":
break
# Close the Zookeeper connection # Close the Zookeeper connection
stopZKConnection(zk_conn) stopZKConnection(zk_conn)