Handle regex in a more consistent way

This commit is contained in:
Joshua Boniface 2019-03-12 23:52:59 -04:00
parent 19445205d7
commit df394c5c39
1 changed files with 12 additions and 7 deletions

View File

@ -515,12 +515,7 @@ def get_list(zk_conn, node, limit, raw):
vm_vcpu = {}
vm_nets = {}
# If we're limited, remove other nodes' VMs
for vm in full_vm_list:
# Check we don't match the limit
name = zkhandler.readdata(zk_conn, '/domains/{}'.format(vm))
vm_node[vm] = zkhandler.readdata(zk_conn, '/domains/{}/node'.format(vm))
# Set our limit to a sensible regex
if limit != None:
try:
# Implcitly assume fuzzy limits
@ -528,7 +523,17 @@ def get_list(zk_conn, node, limit, raw):
limit = '.*' + limit
if re.match('.*\$', limit) == None:
limit = limit + '.*'
except Exception as e:
return False, 'Regex Error: {}'.format(e)
# If we're limited, remove other nodes' VMs
for vm in full_vm_list:
# Check we don't match the limit
name = zkhandler.readdata(zk_conn, '/domains/{}'.format(vm))
vm_node[vm] = zkhandler.readdata(zk_conn, '/domains/{}/node'.format(vm))
# Handle limiting
if limit != None:
try:
if re.match(limit, vm) != None:
if node == None:
vm_list.append(vm)