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_vcpu = {}
vm_nets = {} vm_nets = {}
# If we're limited, remove other nodes' VMs # Set our limit to a sensible regex
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))
if limit != None: if limit != None:
try: try:
# Implcitly assume fuzzy limits # Implcitly assume fuzzy limits
@ -528,7 +523,17 @@ def get_list(zk_conn, node, limit, raw):
limit = '.*' + limit limit = '.*' + limit
if re.match('.*\$', limit) == None: if re.match('.*\$', limit) == None:
limit = limit + '.*' 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 re.match(limit, vm) != None:
if node == None: if node == None:
vm_list.append(vm) vm_list.append(vm)