Support raw VM listing

This commit is contained in:
Joshua Boniface 2019-03-12 21:30:01 -04:00
parent 081d855a03
commit c4a97f04a7
2 changed files with 11 additions and 3 deletions

View File

@ -580,7 +580,11 @@ def vm_info(domain, long_output):
'-n', '--node', 'node', default=None, '-n', '--node', 'node', default=None,
help='Limit list to this node.' help='Limit list to this node.'
) )
def vm_list(node, limit): @click.option(
'-r', '--raw', 'raw', is_flag=True, default=False,
help='Display the raw list of VM names.'
)
def vm_list(node, limit, raw):
""" """
List all virtual machines in the cluster; optionally only match names matching regex LIMIT. List all virtual machines in the cluster; optionally only match names matching regex LIMIT.
@ -588,7 +592,7 @@ def vm_list(node, limit):
""" """
zk_conn = pvc_common.startZKConnection(zk_host) zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_vm.get_list(zk_conn, node, limit) retcode, retmsg = pvc_vm.get_list(zk_conn, node, limit, raw)
cleanup(retcode, retmsg, zk_conn) cleanup(retcode, retmsg, zk_conn)
############################################################################### ###############################################################################

View File

@ -496,7 +496,7 @@ def get_info(zk_conn, domain, long_output):
return True, '' return True, ''
def get_list(zk_conn, node, limit): def get_list(zk_conn, node, limit, raw):
if node != None: if node != None:
# Verify node is valid # Verify node is valid
common.verifyNode(zk_conn, node) common.verifyNode(zk_conn, node)
@ -552,6 +552,10 @@ def get_list(zk_conn, node, limit):
if vm_node[vm] == node: if vm_node[vm] == node:
vm_list.append(vm) vm_list.append(vm)
if raw:
click.echo('\n'.join(vm_list))
return True, ''
# Gather information for printing # Gather information for printing
for vm in vm_list: for vm in vm_list:
vm_state[vm] = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(vm)) vm_state[vm] = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(vm))